2020-01-28 09:42:33 +00:00
|
|
|
//
|
2020-06-17 14:17:17 +00:00
|
|
|
// Ceph Nautilus is the first release that includes rbd_list2() and
|
|
|
|
// rbd_get_create_timestamp().
|
2020-01-28 09:42:33 +00:00
|
|
|
|
|
|
|
package rbd
|
|
|
|
|
|
|
|
// #cgo LDFLAGS: -lrbd
|
|
|
|
// #include <rados/librados.h>
|
|
|
|
// #include <rbd/librbd.h>
|
|
|
|
// #include <errno.h>
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
|
2020-06-17 14:17:17 +00:00
|
|
|
ts "github.com/ceph/go-ceph/internal/timespec"
|
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) {
|
2022-06-14 15:09:17 +00:00
|
|
|
var images []C.rbd_image_spec_t
|
2022-06-02 16:57:35 +00:00
|
|
|
size := C.size_t(4096)
|
2022-06-14 15:09:17 +00:00
|
|
|
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
|
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
|
|
|
|
}
|
2020-06-17 14:17:17 +00:00
|
|
|
|
|
|
|
// GetCreateTimestamp returns the time the rbd image was created.
|
|
|
|
//
|
|
|
|
// Implements:
|
2023-02-09 17:23:11 +00:00
|
|
|
//
|
|
|
|
// int rbd_get_create_timestamp(rbd_image_t image, struct timespec *timestamp);
|
2020-06-17 14:17:17 +00:00
|
|
|
func (image *Image) GetCreateTimestamp() (Timespec, error) {
|
|
|
|
if err := image.validate(imageIsOpen); err != nil {
|
|
|
|
return Timespec{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var cts C.struct_timespec
|
|
|
|
|
|
|
|
if ret := C.rbd_get_create_timestamp(image.image, &cts); ret < 0 {
|
|
|
|
return Timespec{}, getError(ret)
|
|
|
|
}
|
|
|
|
|
|
|
|
return Timespec(ts.CStructToTimespec(ts.CTimespecPtr(&cts))), nil
|
|
|
|
}
|
2020-06-17 14:26:58 +00:00
|
|
|
|
|
|
|
// GetAccessTimestamp returns the time the rbd image was last accessed.
|
|
|
|
//
|
|
|
|
// Implements:
|
2023-02-09 17:23:11 +00:00
|
|
|
//
|
|
|
|
// int rbd_get_access_timestamp(rbd_image_t image, struct timespec *timestamp);
|
2020-06-17 14:26:58 +00:00
|
|
|
func (image *Image) GetAccessTimestamp() (Timespec, error) {
|
|
|
|
if err := image.validate(imageIsOpen); err != nil {
|
|
|
|
return Timespec{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var cts C.struct_timespec
|
|
|
|
|
|
|
|
if ret := C.rbd_get_access_timestamp(image.image, &cts); ret < 0 {
|
|
|
|
return Timespec{}, getError(ret)
|
|
|
|
}
|
|
|
|
|
|
|
|
return Timespec(ts.CStructToTimespec(ts.CTimespecPtr(&cts))), nil
|
|
|
|
}
|
2020-06-17 14:34:51 +00:00
|
|
|
|
|
|
|
// GetModifyTimestamp returns the time the rbd image was last modified.
|
|
|
|
//
|
|
|
|
// Implements:
|
2023-02-09 17:23:11 +00:00
|
|
|
//
|
|
|
|
// int rbd_get_modify_timestamp(rbd_image_t image, struct timespec *timestamp);
|
2020-06-17 14:34:51 +00:00
|
|
|
func (image *Image) GetModifyTimestamp() (Timespec, error) {
|
|
|
|
if err := image.validate(imageIsOpen); err != nil {
|
|
|
|
return Timespec{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var cts C.struct_timespec
|
|
|
|
|
|
|
|
if ret := C.rbd_get_modify_timestamp(image.image, &cts); ret < 0 {
|
|
|
|
return Timespec{}, getError(ret)
|
|
|
|
}
|
|
|
|
|
|
|
|
return Timespec(ts.CStructToTimespec(ts.CTimespecPtr(&cts))), nil
|
|
|
|
}
|
2020-08-20 18:40:49 +00:00
|
|
|
|
|
|
|
// Sparsify makes an image sparse by deallocating runs of zeros.
|
|
|
|
// The sparseSize value will be used to find runs of zeros and must be
|
|
|
|
// a power of two no less than 4096 and no larger than the image size.
|
|
|
|
//
|
|
|
|
// Implements:
|
2023-02-09 17:23:11 +00:00
|
|
|
//
|
|
|
|
// int rbd_sparsify(rbd_image_t image, size_t sparse_size);
|
2020-08-20 18:40:49 +00:00
|
|
|
func (image *Image) Sparsify(sparseSize uint) error {
|
|
|
|
if err := image.validate(imageIsOpen); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return getError(C.rbd_sparsify(image.image, C.size_t(sparseSize)))
|
|
|
|
}
|