mirror of
https://github.com/ceph/go-ceph
synced 2024-12-24 07:03:00 +00:00
rbd: add Create4() for more advanced RBD Image creation
This allows to set additional options while creating RBD images. Ceph-CSI will initially consume this to configure an optionally different pool for data. Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
c06593eef7
commit
b86563db7e
23
rbd/rbd.go
23
rbd/rbd.go
@ -261,6 +261,29 @@ func Create3(ioctx *rados.IOContext, name string, size uint64, features uint64,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// int rbd_create4(rados_ioctx_t io, const char *name, uint64_t size,
|
||||
// rbd_image_options_t opts);
|
||||
func Create4(ioctx *rados.IOContext, name string, size uint64, rio *RbdImageOptions) (image *Image, err error) {
|
||||
if rio == nil {
|
||||
return nil, RBDError(C.EINVAL)
|
||||
}
|
||||
|
||||
c_name := C.CString(name)
|
||||
defer C.free(unsafe.Pointer(c_name))
|
||||
|
||||
ret := C.rbd_create4(C.rados_ioctx_t(ioctx.Pointer()), c_name,
|
||||
C.uint64_t(size), C.rbd_image_options_t(rio.options))
|
||||
|
||||
if ret < 0 {
|
||||
return nil, RBDError(ret)
|
||||
}
|
||||
|
||||
return &Image{
|
||||
ioctx: ioctx,
|
||||
name: name,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// int rbd_clone(rados_ioctx_t p_ioctx, const char *p_name,
|
||||
// const char *p_snapname, rados_ioctx_t c_ioctx,
|
||||
// const char *c_name, uint64_t features, int *c_order);
|
||||
|
@ -114,6 +114,62 @@ func TestImageCreate3(t *testing.T) {
|
||||
conn.Shutdown()
|
||||
}
|
||||
|
||||
func TestCreateImageWithOptions(t *testing.T) {
|
||||
conn, _ := rados.NewConn()
|
||||
conn.ReadDefaultConfigFile()
|
||||
conn.Connect()
|
||||
|
||||
poolname := GetUUID()
|
||||
err := conn.MakePool(poolname)
|
||||
assert.NoError(t, err)
|
||||
|
||||
ioctx, err := conn.OpenIOContext(poolname)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// nil options, causes a panic if not handled correctly
|
||||
name := GetUUID()
|
||||
image, err := rbd.Create4(ioctx, name, 1<<22, nil)
|
||||
assert.Error(t, err)
|
||||
|
||||
options := rbd.NewRbdImageOptions()
|
||||
|
||||
// empty/default options
|
||||
name = GetUUID()
|
||||
image, err = rbd.Create4(ioctx, name, 1<<22, options)
|
||||
assert.NoError(t, err)
|
||||
err = image.Remove()
|
||||
assert.NoError(t, err)
|
||||
|
||||
// create image with RbdImageOptionOrder
|
||||
err = options.SetUint64(rbd.RbdImageOptionOrder, 22)
|
||||
assert.NoError(t, err)
|
||||
name = GetUUID()
|
||||
image, err = rbd.Create4(ioctx, name, 1<<22, options)
|
||||
assert.NoError(t, err)
|
||||
err = image.Remove()
|
||||
assert.NoError(t, err)
|
||||
options.Clear()
|
||||
|
||||
// create image with a different data pool
|
||||
datapool := GetUUID()
|
||||
err = conn.MakePool(datapool)
|
||||
assert.NoError(t, err)
|
||||
err = options.SetString(rbd.RbdImageOptionDataPool, datapool)
|
||||
assert.NoError(t, err)
|
||||
name = GetUUID()
|
||||
image, err = rbd.Create4(ioctx, name, 1<<22, options)
|
||||
assert.NoError(t, err)
|
||||
err = image.Remove()
|
||||
assert.NoError(t, err)
|
||||
conn.DeletePool(datapool)
|
||||
|
||||
// cleanup
|
||||
options.Destroy()
|
||||
ioctx.Destroy()
|
||||
conn.DeletePool(poolname)
|
||||
conn.Shutdown()
|
||||
}
|
||||
|
||||
func TestGetImageNames(t *testing.T) {
|
||||
conn, _ := rados.NewConn()
|
||||
conn.ReadDefaultConfigFile()
|
||||
|
Loading…
Reference in New Issue
Block a user