rbd: rename Create4 to CreateImage

In the future, CreateImage should be the canonical way one creates an
rbd image. Like the underlying ceph apis CreateImage does not return an
Image, only an error code. Open image handles should be acquired through
the OpenImage functions.

Because Create4 was fairly recently added to library there should not be
consumers in the wild. Thus we don't retain the current version for
backwards compatibility.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
John Mulligan 2020-01-24 08:56:46 -05:00 committed by John Mulligan
parent 13028061e7
commit 635ca3cdb2
2 changed files with 26 additions and 33 deletions

View File

@ -334,32 +334,6 @@ func Create3(ioctx *rados.IOContext, name string, size uint64, features uint64,
}, nil
}
// Create4 creates a new rbd image using provided image options.
//
// Implements:
// 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
}
// Clone a new rbd image from a snapshot.
//
// Implements:
@ -1359,3 +1333,22 @@ func OpenImageReadOnly(ioctx *rados.IOContext, name, snapName string) (*Image, e
image: cImage,
}, nil
}
// CreateImage creates a new rbd image using provided image options.
//
// Implements:
// int rbd_create4(rados_ioctx_t io, const char *name, uint64_t size,
// rbd_image_options_t opts);
func CreateImage(ioctx *rados.IOContext, name string, size uint64, rio *RbdImageOptions) error {
if rio == nil {
return 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))
return GetError(ret)
}

View File

@ -160,25 +160,25 @@ func TestCreateImageWithOptions(t *testing.T) {
// nil options, causes a panic if not handled correctly
name := GetUUID()
image, err := Create4(ioctx, name, 1<<22, nil)
err = CreateImage(ioctx, name, 1<<22, nil)
assert.Error(t, err)
options := NewRbdImageOptions()
// empty/default options
name = GetUUID()
image, err = Create4(ioctx, name, 1<<22, options)
err = CreateImage(ioctx, name, 1<<22, options)
assert.NoError(t, err)
err = image.Remove()
err = GetImage(ioctx, name).Remove()
assert.NoError(t, err)
// create image with RbdImageOptionOrder
err = options.SetUint64(RbdImageOptionOrder, 22)
assert.NoError(t, err)
name = GetUUID()
image, err = Create4(ioctx, name, 1<<22, options)
err = CreateImage(ioctx, name, 1<<22, options)
assert.NoError(t, err)
err = image.Remove()
err = GetImage(ioctx, name).Remove()
assert.NoError(t, err)
options.Clear()
@ -189,9 +189,9 @@ func TestCreateImageWithOptions(t *testing.T) {
err = options.SetString(RbdImageOptionDataPool, datapool)
assert.NoError(t, err)
name = GetUUID()
image, err = Create4(ioctx, name, 1<<22, options)
err = CreateImage(ioctx, name, 1<<22, options)
assert.NoError(t, err)
err = image.Remove()
err = GetImage(ioctx, name).Remove()
assert.NoError(t, err)
conn.DeletePool(datapool)