mirror of
https://github.com/ceph/go-ceph
synced 2024-12-19 21:02:12 +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>
44 lines
924 B
Go
44 lines
924 B
Go
// +build luminous mimic
|
|
// +build !nautilus
|
|
//
|
|
// Ceph Nautilus includes rbd_list2() and marked rbd_list() deprecated.
|
|
|
|
package rbd
|
|
|
|
// #cgo LDFLAGS: -lrbd
|
|
// #include <rados/librados.h>
|
|
// #include <rbd/librbd.h>
|
|
// #include <errno.h>
|
|
import "C"
|
|
|
|
import (
|
|
"bytes"
|
|
"unsafe"
|
|
|
|
"github.com/ceph/go-ceph/rados"
|
|
)
|
|
|
|
// GetImageNames returns the list of current RBD images.
|
|
func GetImageNames(ioctx *rados.IOContext) (names []string, err error) {
|
|
buf := make([]byte, 4096)
|
|
for {
|
|
size := C.size_t(len(buf))
|
|
ret := C.rbd_list(cephIoctx(ioctx),
|
|
(*C.char)(unsafe.Pointer(&buf[0])), &size)
|
|
if ret == -C.ERANGE {
|
|
buf = make([]byte, size)
|
|
continue
|
|
} else if ret < 0 {
|
|
return nil, RBDError(ret)
|
|
}
|
|
tmp := bytes.Split(buf[:size-1], []byte{0})
|
|
for _, s := range tmp {
|
|
if len(s) > 0 {
|
|
name := C.GoString((*C.char)(unsafe.Pointer(&s[0])))
|
|
names = append(names, name)
|
|
}
|
|
}
|
|
return names, nil
|
|
}
|
|
}
|