mirror of https://github.com/ceph/go-ceph
rbd: hide ioctx.Pointer incantations in a function
A previous change improved our use of pointers such that go vet no longer had an issue with these lines but if we ever need to change the interaction between rbd and rados like that again we can now rely on a single call site `cephIoctx` that will return our ceph/c type given the public Go-language level type from the rados pkg. Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
parent
1abd1423c1
commit
fa3bce7234
|
@ -95,7 +95,6 @@ const (
|
||||||
// int (*cb)(uint64_t, size_t, int, void *),
|
// int (*cb)(uint64_t, size_t, int, void *),
|
||||||
// void *arg);
|
// void *arg);
|
||||||
func (image *Image) DiffIterate(config DiffIterateConfig) error {
|
func (image *Image) DiffIterate(config DiffIterateConfig) error {
|
||||||
|
|
||||||
if err := image.validate(imageIsOpen); err != nil {
|
if err := image.validate(imageIsOpen); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
45
rbd/rbd.go
45
rbd/rbd.go
|
@ -113,6 +113,11 @@ func split(buf []byte) (values []string) {
|
||||||
return values
|
return values
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cephIoctx returns a ceph rados_ioctx_t given a go-ceph rados IOContext.
|
||||||
|
func cephIoctx(radosIoctx *rados.IOContext) C.rados_ioctx_t {
|
||||||
|
return C.rados_ioctx_t(radosIoctx.Pointer())
|
||||||
|
}
|
||||||
|
|
||||||
// test if a bit is set in the given value
|
// test if a bit is set in the given value
|
||||||
func hasBit(value, bit uint32) bool {
|
func hasBit(value, bit uint32) bool {
|
||||||
return (value & bit) == bit
|
return (value & bit) == bit
|
||||||
|
@ -193,7 +198,7 @@ func Create(ioctx *rados.IOContext, name string, size uint64, order int,
|
||||||
|
|
||||||
defer C.free(unsafe.Pointer(c_name))
|
defer C.free(unsafe.Pointer(c_name))
|
||||||
|
|
||||||
ret = C.rbd_create(C.rados_ioctx_t(ioctx.Pointer()),
|
ret = C.rbd_create(cephIoctx(ioctx),
|
||||||
c_name, C.uint64_t(size), &c_order)
|
c_name, C.uint64_t(size), &c_order)
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("Wrong number of argument")
|
return nil, errors.New("Wrong number of argument")
|
||||||
|
@ -223,7 +228,7 @@ func Create2(ioctx *rados.IOContext, name string, size uint64, features uint64,
|
||||||
|
|
||||||
defer C.free(unsafe.Pointer(c_name))
|
defer C.free(unsafe.Pointer(c_name))
|
||||||
|
|
||||||
ret = C.rbd_create2(C.rados_ioctx_t(ioctx.Pointer()), c_name,
|
ret = C.rbd_create2(cephIoctx(ioctx), c_name,
|
||||||
C.uint64_t(size), C.uint64_t(features), &c_order)
|
C.uint64_t(size), C.uint64_t(features), &c_order)
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return nil, RBDError(ret)
|
return nil, RBDError(ret)
|
||||||
|
@ -251,7 +256,7 @@ func Create3(ioctx *rados.IOContext, name string, size uint64, features uint64,
|
||||||
|
|
||||||
defer C.free(unsafe.Pointer(c_name))
|
defer C.free(unsafe.Pointer(c_name))
|
||||||
|
|
||||||
ret = C.rbd_create3(C.rados_ioctx_t(ioctx.Pointer()), c_name,
|
ret = C.rbd_create3(cephIoctx(ioctx), c_name,
|
||||||
C.uint64_t(size), C.uint64_t(features), &c_order,
|
C.uint64_t(size), C.uint64_t(features), &c_order,
|
||||||
C.uint64_t(stripe_unit), C.uint64_t(stripe_count))
|
C.uint64_t(stripe_unit), C.uint64_t(stripe_count))
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
|
@ -284,9 +289,9 @@ func (image *Image) Clone(snapname string, c_ioctx *rados.IOContext, c_name stri
|
||||||
defer C.free(unsafe.Pointer(c_p_snapname))
|
defer C.free(unsafe.Pointer(c_p_snapname))
|
||||||
defer C.free(unsafe.Pointer(c_c_name))
|
defer C.free(unsafe.Pointer(c_c_name))
|
||||||
|
|
||||||
ret := C.rbd_clone(C.rados_ioctx_t(image.ioctx.Pointer()),
|
ret := C.rbd_clone(cephIoctx(image.ioctx),
|
||||||
c_p_name, c_p_snapname,
|
c_p_name, c_p_snapname,
|
||||||
C.rados_ioctx_t(c_ioctx.Pointer()),
|
cephIoctx(c_ioctx),
|
||||||
c_c_name, C.uint64_t(features), &c_order)
|
c_c_name, C.uint64_t(features), &c_order)
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return nil, RBDError(ret)
|
return nil, RBDError(ret)
|
||||||
|
@ -319,7 +324,7 @@ func (image *Image) Trash(delay time.Duration) error {
|
||||||
c_name := C.CString(image.name)
|
c_name := C.CString(image.name)
|
||||||
defer C.free(unsafe.Pointer(c_name))
|
defer C.free(unsafe.Pointer(c_name))
|
||||||
|
|
||||||
return getError(C.rbd_trash_move(C.rados_ioctx_t(image.ioctx.Pointer()), c_name,
|
return getError(C.rbd_trash_move(cephIoctx(image.ioctx), c_name,
|
||||||
C.uint64_t(delay.Seconds())))
|
C.uint64_t(delay.Seconds())))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,7 +343,7 @@ func (image *Image) Rename(destname string) error {
|
||||||
defer C.free(unsafe.Pointer(c_srcname))
|
defer C.free(unsafe.Pointer(c_srcname))
|
||||||
defer C.free(unsafe.Pointer(c_destname))
|
defer C.free(unsafe.Pointer(c_destname))
|
||||||
|
|
||||||
err := RBDError(C.rbd_rename(C.rados_ioctx_t(image.ioctx.Pointer()),
|
err := RBDError(C.rbd_rename(cephIoctx(image.ioctx),
|
||||||
c_srcname, c_destname))
|
c_srcname, c_destname))
|
||||||
if err == 0 {
|
if err == 0 {
|
||||||
image.name = destname
|
image.name = destname
|
||||||
|
@ -544,7 +549,7 @@ func (image *Image) Copy(ioctx *rados.IOContext, destname string) error {
|
||||||
defer C.free(unsafe.Pointer(c_destname))
|
defer C.free(unsafe.Pointer(c_destname))
|
||||||
|
|
||||||
return getError(C.rbd_copy(image.image,
|
return getError(C.rbd_copy(image.image,
|
||||||
C.rados_ioctx_t(ioctx.Pointer()), c_destname))
|
cephIoctx(ioctx), c_destname))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy one rbd image to another, using an image handle.
|
// Copy one rbd image to another, using an image handle.
|
||||||
|
@ -968,14 +973,14 @@ func GetTrashList(ioctx *rados.IOContext) ([]TrashInfo, error) {
|
||||||
var num_entries C.size_t
|
var num_entries C.size_t
|
||||||
|
|
||||||
// Call rbd_trash_list with nil pointer to get number of trash entries.
|
// Call rbd_trash_list with nil pointer to get number of trash entries.
|
||||||
if C.rbd_trash_list(C.rados_ioctx_t(ioctx.Pointer()), nil, &num_entries); num_entries == 0 {
|
if C.rbd_trash_list(cephIoctx(ioctx), nil, &num_entries); num_entries == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
c_entries := make([]C.rbd_trash_image_info_t, num_entries)
|
c_entries := make([]C.rbd_trash_image_info_t, num_entries)
|
||||||
trashList := make([]TrashInfo, num_entries)
|
trashList := make([]TrashInfo, num_entries)
|
||||||
|
|
||||||
if ret := C.rbd_trash_list(C.rados_ioctx_t(ioctx.Pointer()), &c_entries[0], &num_entries); ret < 0 {
|
if ret := C.rbd_trash_list(cephIoctx(ioctx), &c_entries[0], &num_entries); ret < 0 {
|
||||||
return nil, RBDError(ret)
|
return nil, RBDError(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -999,7 +1004,7 @@ func TrashRemove(ioctx *rados.IOContext, id string, force bool) error {
|
||||||
c_id := C.CString(id)
|
c_id := C.CString(id)
|
||||||
defer C.free(unsafe.Pointer(c_id))
|
defer C.free(unsafe.Pointer(c_id))
|
||||||
|
|
||||||
return getError(C.rbd_trash_remove(C.rados_ioctx_t(ioctx.Pointer()), c_id, C.bool(force)))
|
return getError(C.rbd_trash_remove(cephIoctx(ioctx), c_id, C.bool(force)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// TrashRestore restores the trashed RBD with the specified id back to the pool from whence it
|
// TrashRestore restores the trashed RBD with the specified id back to the pool from whence it
|
||||||
|
@ -1010,7 +1015,7 @@ func TrashRestore(ioctx *rados.IOContext, id, name string) error {
|
||||||
defer C.free(unsafe.Pointer(c_id))
|
defer C.free(unsafe.Pointer(c_id))
|
||||||
defer C.free(unsafe.Pointer(c_name))
|
defer C.free(unsafe.Pointer(c_name))
|
||||||
|
|
||||||
return getError(C.rbd_trash_restore(C.rados_ioctx_t(ioctx.Pointer()), c_id, c_name))
|
return getError(C.rbd_trash_restore(cephIoctx(ioctx), c_id, c_name))
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenImage will open an existing rbd image by name and snapshot name,
|
// OpenImage will open an existing rbd image by name and snapshot name,
|
||||||
|
@ -1032,7 +1037,7 @@ func OpenImage(ioctx *rados.IOContext, name, snapName string) (*Image, error) {
|
||||||
|
|
||||||
var cImage C.rbd_image_t
|
var cImage C.rbd_image_t
|
||||||
ret := C.rbd_open(
|
ret := C.rbd_open(
|
||||||
C.rados_ioctx_t(ioctx.Pointer()),
|
cephIoctx(ioctx),
|
||||||
cName,
|
cName,
|
||||||
&cImage,
|
&cImage,
|
||||||
cSnapName)
|
cSnapName)
|
||||||
|
@ -1068,7 +1073,7 @@ func OpenImageReadOnly(ioctx *rados.IOContext, name, snapName string) (*Image, e
|
||||||
|
|
||||||
var cImage C.rbd_image_t
|
var cImage C.rbd_image_t
|
||||||
ret := C.rbd_open_read_only(
|
ret := C.rbd_open_read_only(
|
||||||
C.rados_ioctx_t(ioctx.Pointer()),
|
cephIoctx(ioctx),
|
||||||
cName,
|
cName,
|
||||||
&cImage,
|
&cImage,
|
||||||
cSnapName)
|
cSnapName)
|
||||||
|
@ -1105,7 +1110,7 @@ func OpenImageById(ioctx *rados.IOContext, id, snapName string) (*Image, error)
|
||||||
|
|
||||||
var cImage C.rbd_image_t
|
var cImage C.rbd_image_t
|
||||||
ret := C.rbd_open_by_id(
|
ret := C.rbd_open_by_id(
|
||||||
C.rados_ioctx_t(ioctx.Pointer()),
|
cephIoctx(ioctx),
|
||||||
cid,
|
cid,
|
||||||
&cImage,
|
&cImage,
|
||||||
cSnapName)
|
cSnapName)
|
||||||
|
@ -1142,7 +1147,7 @@ func OpenImageByIdReadOnly(ioctx *rados.IOContext, id, snapName string) (*Image,
|
||||||
|
|
||||||
var cImage C.rbd_image_t
|
var cImage C.rbd_image_t
|
||||||
ret := C.rbd_open_by_id_read_only(
|
ret := C.rbd_open_by_id_read_only(
|
||||||
C.rados_ioctx_t(ioctx.Pointer()),
|
cephIoctx(ioctx),
|
||||||
cid,
|
cid,
|
||||||
&cImage,
|
&cImage,
|
||||||
cSnapName)
|
cSnapName)
|
||||||
|
@ -1171,7 +1176,7 @@ func CreateImage(ioctx *rados.IOContext, name string, size uint64, rio *RbdImage
|
||||||
c_name := C.CString(name)
|
c_name := C.CString(name)
|
||||||
defer C.free(unsafe.Pointer(c_name))
|
defer C.free(unsafe.Pointer(c_name))
|
||||||
|
|
||||||
ret := C.rbd_create4(C.rados_ioctx_t(ioctx.Pointer()), c_name,
|
ret := C.rbd_create4(cephIoctx(ioctx), c_name,
|
||||||
C.uint64_t(size), C.rbd_image_options_t(rio.options))
|
C.uint64_t(size), C.rbd_image_options_t(rio.options))
|
||||||
return getError(ret)
|
return getError(ret)
|
||||||
}
|
}
|
||||||
|
@ -1183,7 +1188,7 @@ func CreateImage(ioctx *rados.IOContext, name string, size uint64, rio *RbdImage
|
||||||
func RemoveImage(ioctx *rados.IOContext, name string) error {
|
func RemoveImage(ioctx *rados.IOContext, name string) error {
|
||||||
c_name := C.CString(name)
|
c_name := C.CString(name)
|
||||||
defer C.free(unsafe.Pointer(c_name))
|
defer C.free(unsafe.Pointer(c_name))
|
||||||
return getError(C.rbd_remove(C.rados_ioctx_t(ioctx.Pointer()), c_name))
|
return getError(C.rbd_remove(cephIoctx(ioctx), c_name))
|
||||||
}
|
}
|
||||||
|
|
||||||
// CloneImage creates a clone of the image from the named snapshot in the
|
// CloneImage creates a clone of the image from the named snapshot in the
|
||||||
|
@ -1208,10 +1213,10 @@ func CloneImage(ioctx *rados.IOContext, parentName, snapName string,
|
||||||
defer C.free(unsafe.Pointer(cCloneName))
|
defer C.free(unsafe.Pointer(cCloneName))
|
||||||
|
|
||||||
ret := C.rbd_clone3(
|
ret := C.rbd_clone3(
|
||||||
C.rados_ioctx_t(ioctx.Pointer()),
|
cephIoctx(ioctx),
|
||||||
cParentName,
|
cParentName,
|
||||||
cParentSnapName,
|
cParentSnapName,
|
||||||
C.rados_ioctx_t(destctx.Pointer()),
|
cephIoctx(destctx),
|
||||||
cCloneName,
|
cCloneName,
|
||||||
C.rbd_image_options_t(rio.options))
|
C.rbd_image_options_t(rio.options))
|
||||||
return getError(ret)
|
return getError(ret)
|
||||||
|
|
|
@ -23,7 +23,7 @@ func GetImageNames(ioctx *rados.IOContext) (names []string, err error) {
|
||||||
buf := make([]byte, 4096)
|
buf := make([]byte, 4096)
|
||||||
for {
|
for {
|
||||||
size := C.size_t(len(buf))
|
size := C.size_t(len(buf))
|
||||||
ret := C.rbd_list(C.rados_ioctx_t(ioctx.Pointer()),
|
ret := C.rbd_list(cephIoctx(ioctx),
|
||||||
(*C.char)(unsafe.Pointer(&buf[0])), &size)
|
(*C.char)(unsafe.Pointer(&buf[0])), &size)
|
||||||
if ret == -C.ERANGE {
|
if ret == -C.ERANGE {
|
||||||
buf = make([]byte, size)
|
buf = make([]byte, size)
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
// GetImageNames returns the list of current RBD images.
|
// GetImageNames returns the list of current RBD images.
|
||||||
func GetImageNames(ioctx *rados.IOContext) ([]string, error) {
|
func GetImageNames(ioctx *rados.IOContext) ([]string, error) {
|
||||||
size := C.size_t(0)
|
size := C.size_t(0)
|
||||||
ret := C.rbd_list2(C.rados_ioctx_t(ioctx.Pointer()), nil, &size)
|
ret := C.rbd_list2(cephIoctx(ioctx), nil, &size)
|
||||||
if ret < 0 && ret != -C.ERANGE {
|
if ret < 0 && ret != -C.ERANGE {
|
||||||
return nil, RBDError(ret)
|
return nil, RBDError(ret)
|
||||||
} else if ret > 0 {
|
} else if ret > 0 {
|
||||||
|
@ -31,7 +31,7 @@ func GetImageNames(ioctx *rados.IOContext) ([]string, error) {
|
||||||
|
|
||||||
// expected: ret == -ERANGE, size contains number of image names
|
// expected: ret == -ERANGE, size contains number of image names
|
||||||
images := make([]C.rbd_image_spec_t, size)
|
images := make([]C.rbd_image_spec_t, size)
|
||||||
ret = C.rbd_list2(C.rados_ioctx_t(ioctx.Pointer()), (*C.rbd_image_spec_t)(unsafe.Pointer(&images[0])), &size)
|
ret = C.rbd_list2(cephIoctx(ioctx), (*C.rbd_image_spec_t)(unsafe.Pointer(&images[0])), &size)
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return nil, RBDError(ret)
|
return nil, RBDError(ret)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue