mirror of
https://github.com/ceph/go-ceph
synced 2024-12-23 14:45:42 +00:00
fa3bce7234
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>
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
// +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 (
|
|
"fmt"
|
|
"unsafe"
|
|
|
|
"github.com/ceph/go-ceph/rados"
|
|
)
|
|
|
|
// GetImageNames returns the list of current RBD images.
|
|
func GetImageNames(ioctx *rados.IOContext) ([]string, error) {
|
|
size := C.size_t(0)
|
|
ret := C.rbd_list2(cephIoctx(ioctx), nil, &size)
|
|
if ret < 0 && ret != -C.ERANGE {
|
|
return nil, RBDError(ret)
|
|
} else if ret > 0 {
|
|
return nil, fmt.Errorf("rbd_list2() returned %d names, expected 0", ret)
|
|
} else if ret == 0 && size == 0 {
|
|
return nil, nil
|
|
}
|
|
|
|
// expected: ret == -ERANGE, size contains number of image names
|
|
images := make([]C.rbd_image_spec_t, size)
|
|
ret = C.rbd_list2(cephIoctx(ioctx), (*C.rbd_image_spec_t)(unsafe.Pointer(&images[0])), &size)
|
|
if ret < 0 {
|
|
return nil, RBDError(ret)
|
|
}
|
|
defer C.rbd_image_spec_list_cleanup((*C.rbd_image_spec_t)(unsafe.Pointer(&images[0])), size)
|
|
|
|
names := make([]string, size)
|
|
for i, image := range images {
|
|
names[i] = C.GoString(image.name)
|
|
}
|
|
return names, nil
|
|
}
|