2020-01-28 09:42:33 +00:00
|
|
|
// +build !luminous,!mimic
|
|
|
|
//
|
|
|
|
// Ceph Nautilus is the first release that includes rbd_list2().
|
|
|
|
|
|
|
|
package rbd
|
|
|
|
|
|
|
|
// #cgo LDFLAGS: -lrbd
|
|
|
|
// #include <rados/librados.h>
|
|
|
|
// #include <rbd/librbd.h>
|
|
|
|
// #include <errno.h>
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
|
2020-04-10 17:35:49 +00:00
|
|
|
"github.com/ceph/go-ceph/internal/retry"
|
2020-01-28 09:42:33 +00:00
|
|
|
"github.com/ceph/go-ceph/rados"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetImageNames returns the list of current RBD images.
|
|
|
|
func GetImageNames(ioctx *rados.IOContext) ([]string, error) {
|
2020-04-10 17:35:49 +00:00
|
|
|
var (
|
|
|
|
err error
|
|
|
|
images []C.rbd_image_spec_t
|
|
|
|
size C.size_t
|
|
|
|
)
|
|
|
|
retry.WithSizes(32, 4096, func(s int) retry.Hint {
|
|
|
|
size = C.size_t(s)
|
|
|
|
images = make([]C.rbd_image_spec_t, size)
|
|
|
|
ret := C.rbd_list2(
|
|
|
|
cephIoctx(ioctx),
|
|
|
|
(*C.rbd_image_spec_t)(unsafe.Pointer(&images[0])),
|
|
|
|
&size)
|
|
|
|
err = getErrorIfNegative(ret)
|
|
|
|
return retry.Size(int(size)).If(err == errRange)
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2020-01-28 09:42:33 +00:00
|
|
|
}
|
|
|
|
defer C.rbd_image_spec_list_cleanup((*C.rbd_image_spec_t)(unsafe.Pointer(&images[0])), size)
|
|
|
|
|
|
|
|
names := make([]string, size)
|
2020-04-10 17:35:49 +00:00
|
|
|
for i, image := range images[:size] {
|
2020-01-28 09:42:33 +00:00
|
|
|
names[i] = C.GoString(image.name)
|
|
|
|
}
|
|
|
|
return names, nil
|
|
|
|
}
|