2020-01-07 13:30:27 +00:00
|
|
|
// +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 <rbd/librbd.h>
|
|
|
|
// #include <errno.h>
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
2020-06-17 09:37:06 +00:00
|
|
|
|
|
|
|
"github.com/ceph/go-ceph/internal/retry"
|
2020-01-07 13:30:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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 {
|
2020-08-11 14:42:21 +00:00
|
|
|
return rbdError(ret)
|
2020-01-07 13:30:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2020-08-11 14:42:21 +00:00
|
|
|
return rbdError(C.ERANGE)
|
2020-01-07 13:30:27 +00:00
|
|
|
}
|
|
|
|
if copy(pool, C.GoString(parentImage.pool_name)) != strlen {
|
2020-08-11 14:42:21 +00:00
|
|
|
return rbdError(C.ERANGE)
|
2020-01-07 13:30:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
strlen = int(C.strlen(parentImage.image_name))
|
|
|
|
if len(name) < strlen {
|
2020-08-11 14:42:21 +00:00
|
|
|
return rbdError(C.ERANGE)
|
2020-01-07 13:30:27 +00:00
|
|
|
}
|
|
|
|
if copy(name, C.GoString(parentImage.image_name)) != strlen {
|
2020-08-11 14:42:21 +00:00
|
|
|
return rbdError(C.ERANGE)
|
2020-01-07 13:30:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
strlen = int(C.strlen(parentSnap.name))
|
|
|
|
if len(snapname) < strlen {
|
2020-08-11 14:42:21 +00:00
|
|
|
return rbdError(C.ERANGE)
|
2020-01-07 13:30:27 +00:00
|
|
|
}
|
|
|
|
if copy(snapname, C.GoString(parentSnap.name)) != strlen {
|
2020-08-11 14:42:21 +00:00
|
|
|
return rbdError(C.ERANGE)
|
2020-01-07 13:30:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListChildren returns arrays with the pools and names of the images that are
|
|
|
|
// children of the given image. The index of the pools and images arrays can be
|
|
|
|
// used to link the two items together.
|
|
|
|
//
|
|
|
|
// Implements:
|
|
|
|
// int rbd_list_children3(rbd_image_t image, rbd_linked_image_spec_t *images,
|
|
|
|
// size_t *max_images);
|
|
|
|
func (image *Image) ListChildren() (pools []string, images []string, err error) {
|
|
|
|
if err := image.validate(imageIsOpen); err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
2020-06-17 09:37:06 +00:00
|
|
|
var (
|
|
|
|
csize C.size_t
|
|
|
|
children []C.rbd_linked_image_spec_t
|
|
|
|
)
|
|
|
|
retry.WithSizes(16, 4096, func(size int) retry.Hint {
|
|
|
|
csize = C.size_t(size)
|
|
|
|
children = make([]C.rbd_linked_image_spec_t, csize)
|
|
|
|
ret := C.rbd_list_children3(
|
|
|
|
image.image,
|
|
|
|
(*C.rbd_linked_image_spec_t)(unsafe.Pointer(&children[0])),
|
|
|
|
&csize)
|
|
|
|
err = getErrorIfNegative(ret)
|
|
|
|
return retry.Size(int(csize)).If(err == errRange)
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
2020-01-07 13:30:27 +00:00
|
|
|
}
|
2020-06-17 09:37:06 +00:00
|
|
|
defer C.rbd_linked_image_spec_list_cleanup((*C.rbd_linked_image_spec_t)(unsafe.Pointer(&children[0])), csize)
|
2020-01-07 13:30:27 +00:00
|
|
|
|
2020-06-17 09:37:06 +00:00
|
|
|
pools = make([]string, csize)
|
|
|
|
images = make([]string, csize)
|
|
|
|
for i, child := range children[:csize] {
|
2020-01-07 13:30:27 +00:00
|
|
|
pools[i] = C.GoString(child.pool_name)
|
|
|
|
images[i] = C.GoString(child.image_name)
|
|
|
|
}
|
|
|
|
return pools, images, nil
|
|
|
|
}
|