2020-01-28 09:42:33 +00:00
|
|
|
// +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"
|
|
|
|
|
2020-04-16 20:58:36 +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) (names []string, err error) {
|
2020-04-16 20:58:36 +00:00
|
|
|
var (
|
|
|
|
buf []byte
|
|
|
|
csize C.size_t
|
|
|
|
)
|
|
|
|
// from 4KiB to 32KiB
|
|
|
|
retry.WithSizes(4096, 1<<15, func(size int) retry.Hint {
|
|
|
|
csize = C.size_t(size)
|
|
|
|
buf = make([]byte, csize)
|
2020-03-09 23:10:23 +00:00
|
|
|
ret := C.rbd_list(cephIoctx(ioctx),
|
2020-04-16 20:58:36 +00:00
|
|
|
(*C.char)(unsafe.Pointer(&buf[0])), &csize)
|
|
|
|
err = getErrorIfNegative(ret)
|
|
|
|
return retry.Size(int(csize)).If(err == errRange)
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
tmp := bytes.Split(buf[:csize-1], []byte{0})
|
|
|
|
for _, s := range tmp {
|
|
|
|
if len(s) > 0 {
|
|
|
|
name := C.GoString((*C.char)(unsafe.Pointer(&s[0])))
|
|
|
|
names = append(names, name)
|
2020-01-28 09:42:33 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-16 20:58:36 +00:00
|
|
|
return names, nil
|
2020-01-28 09:42:33 +00:00
|
|
|
}
|