// int rbd_create(rados_ioctx_t io, const char *name, uint64_t size, int *order); // int rbd_create2(rados_ioctx_t io, const char *name, uint64_t size, // uint64_t features, int *order); // int rbd_create3(rados_ioctx_t io, const char *name, uint64_t size, // uint64_t features, int *order, // uint64_t stripe_unit, uint64_t stripe_count); func Create(ioctx *rados.IOContext, name string, size uint64, args ...uint64) (image *Image, err error) { var ret C.int var c_order C.int var c_name *C.char = C.CString(name) defer C.free(unsafe.Pointer(c_name)) switch len(args) { case 2: ret = C.rbd_create3(C.rados_ioctx_t(ioctx.Pointer()), c_name, C.uint64_t(size), C.uint64_t(args[0]), &c_order, C.uint64_t(args[1]), C.uint64_t(args[2])) case 1: ret = C.rbd_create2(C.rados_ioctx_t(ioctx.Pointer()), c_name, C.uint64_t(size), C.uint64_t(args[0]), &c_order) case 0: ret = C.rbd_create(C.rados_ioctx_t(ioctx.Pointer()), c_name, C.uint64_t(size), &c_order) default: return nil, errors.New("Wrong number of argument") } if ret < 0 { return nil, RBDError(int(ret)) } return &Image{ ioctx: ioctx, name: name, }, nil }
// CreateImage creates a rbd image for the pool. Given a name and size in // bytes, it will return any error if there was a problem creating the // image. func (p *Pool) CreateImage(name string, size uint64) error { str := C.CString(name) defer C.free(unsafe.Pointer(str)) order := C.int(0) if i := C.rbd_create(p.ioctx, str, C.uint64_t(size), &order); i < 0 { return strerror(i) } return nil }