From 92fc7ac0bf20a96a39e1df29bd604270d0f93ce4 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Tue, 17 Dec 2019 09:58:45 +0100 Subject: [PATCH] rbd: replace deprecated rbd_get_parent_info() with rbd_get_parent() Signed-off-by: Niels de Vos --- rbd/rbd.go | 23 -------------- rbd/snapshot_mimic.go | 45 ++++++++++++++++++++++++++++ rbd/snapshot_nautilus.go | 65 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 23 deletions(-) create mode 100644 rbd/snapshot_mimic.go create mode 100644 rbd/snapshot_nautilus.go diff --git a/rbd/rbd.go b/rbd/rbd.go index cab39d8..0cab37c 100644 --- a/rbd/rbd.go +++ b/rbd/rbd.go @@ -1015,29 +1015,6 @@ func (image *Image) GetSnapshot(snapname string) *Snapshot { } } -// int rbd_get_parent_info(rbd_image_t image, -// char *parent_pool_name, size_t ppool_namelen, char *parent_name, -// size_t pnamelen, char *parent_snap_name, size_t psnap_namelen) -func (image *Image) GetParentInfo(p_pool, p_name, p_snapname []byte) error { - if err := image.validate(imageIsOpen); err != nil { - return err - } - - ret := C.rbd_get_parent_info( - image.image, - (*C.char)(unsafe.Pointer(&p_pool[0])), - (C.size_t)(len(p_pool)), - (*C.char)(unsafe.Pointer(&p_name[0])), - (C.size_t)(len(p_name)), - (*C.char)(unsafe.Pointer(&p_snapname[0])), - (C.size_t)(len(p_snapname))) - if ret == 0 { - return nil - } else { - return RBDError(ret) - } -} - // int rbd_metadata_get(rbd_image_t image, const char *key, char *value, size_t *vallen) func (image *Image) GetMetadata(key string) (string, error) { if err := image.validate(imageIsOpen); err != nil { diff --git a/rbd/snapshot_mimic.go b/rbd/snapshot_mimic.go new file mode 100644 index 0000000..0923f4b --- /dev/null +++ b/rbd/snapshot_mimic.go @@ -0,0 +1,45 @@ +// +build luminous mimic +// +build !nautilus +// +// Ceph Nautilus introduced rbd_get_parent() and deprecated rbd_get_parent_info(). +// Ceph Nautilus introduced rbd_list_children3() and deprecated rbd_list_children(). + +package rbd + +// #cgo LDFLAGS: -lrbd +// #include +// #include +import "C" + +import ( + "bytes" + "unsafe" +) + +// GetParentInfo looks for the parent of the image and stores the pool, name +// and snapshot-name in the byte-arrays that are passed as arguments. +// +// Implements: +// int rbd_get_parent_info(rbd_image_t image, char *parent_pool_name, +// size_t ppool_namelen, char *parent_name, +// size_t pnamelen, char *parent_snap_name, +// size_t psnap_namelen) +func (image *Image) GetParentInfo(p_pool, p_name, p_snapname []byte) error { + if err := image.validate(imageIsOpen); err != nil { + return err + } + + ret := C.rbd_get_parent_info( + image.image, + (*C.char)(unsafe.Pointer(&p_pool[0])), + (C.size_t)(len(p_pool)), + (*C.char)(unsafe.Pointer(&p_name[0])), + (C.size_t)(len(p_name)), + (*C.char)(unsafe.Pointer(&p_snapname[0])), + (C.size_t)(len(p_snapname))) + if ret == 0 { + return nil + } else { + return RBDError(ret) + } +} diff --git a/rbd/snapshot_nautilus.go b/rbd/snapshot_nautilus.go new file mode 100644 index 0000000..731da83 --- /dev/null +++ b/rbd/snapshot_nautilus.go @@ -0,0 +1,65 @@ +// +build !luminous,!mimic +// +// Ceph Nautilus introduced rbd_get_parent() and deprecated rbd_get_parent_info(). +// Ceph Nautilus introduced rbd_list_children3() and deprecated rbd_list_children(). + +package rbd + +// #cgo LDFLAGS: -lrbd +// #include +// #include +import "C" + +import ( + "fmt" + "unsafe" +) + +// GetParentInfo looks for the parent of the image and stores the pool, name +// and snapshot-name in the byte-arrays that are passed as arguments. +// +// Implements: +// int rbd_get_parent(rbd_image_t image, +// rbd_linked_image_spec_t *parent_image, +// rbd_snap_spec_t *parent_snap) +func (image *Image) GetParentInfo(pool, name, snapname []byte) error { + if err := image.validate(imageIsOpen); err != nil { + return err + } + + parentImage := C.rbd_linked_image_spec_t{} + parentSnap := C.rbd_snap_spec_t{} + ret := C.rbd_get_parent(image.image, &parentImage, &parentSnap) + if ret != 0 { + return RBDError(ret) + } + + defer C.rbd_linked_image_spec_cleanup(&parentImage) + defer C.rbd_snap_spec_cleanup(&parentSnap) + + strlen := int(C.strlen(parentImage.pool_name)) + if len(pool) < strlen { + return RBDError(C.ERANGE) + } + if copy(pool, C.GoString(parentImage.pool_name)) != strlen { + return RBDError(C.ERANGE) + } + + strlen = int(C.strlen(parentImage.image_name)) + if len(name) < strlen { + return RBDError(C.ERANGE) + } + if copy(name, C.GoString(parentImage.image_name)) != strlen { + return RBDError(C.ERANGE) + } + + strlen = int(C.strlen(parentSnap.name)) + if len(snapname) < strlen { + return RBDError(C.ERANGE) + } + if copy(snapname, C.GoString(parentSnap.name)) != strlen { + return RBDError(C.ERANGE) + } + + return nil +}