rbd: refactor GetImageNames to use a for loop instead of recursion
This is done because using a for loop is more idiomatic in Go code.
@@ -19,11 +19,23 @@ import (
// GetImageNames returns the list of current RBD images.
func GetImageNames(ioctx *rados.IOContext) ([]string, error) {
+ var images []C.rbd_image_spec_t
size := C.size_t(4096)
- images, err := getImageNames(ioctx, &size)
+ for {
+ 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)
if err != nil {
+ if err == errRange {
+ continue
+ }
return nil, err
}
+ break
+ }
defer C.rbd_image_spec_list_cleanup((*C.rbd_image_spec_t)(unsafe.Pointer(&images[0])), size)
names := make([]string, size)
@@ -33,22 +45,6 @@ func GetImageNames(ioctx *rados.IOContext) ([]string, error) {
return names, nil
}
-func getImageNames(ioctx *rados.IOContext, size *C.size_t) ([]C.rbd_image_spec_t, error) {
- 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)
- if err != nil {
- if err == errRange {
- return getImageNames(ioctx, size)
- }
- return nil, err
- }
- return images, nil
-}
-
// GetCreateTimestamp returns the time the rbd image was created.
//
// Implements:
