rbd: add Image.GetCreateTimestamp()

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2020-06-17 16:17:17 +02:00 committed by John Mulligan
parent c4714165a6
commit 5b45db6803
2 changed files with 25 additions and 1 deletions

View File

@ -18,6 +18,7 @@ import (
"unsafe"
"github.com/ceph/go-ceph/internal/retry"
ts "github.com/ceph/go-ceph/internal/timespec"
"github.com/ceph/go-ceph/rados"
)
@ -45,6 +46,9 @@ const (
NoSnapshot = ""
)
// Timespec is a public type for the internal C 'struct timespec'
type Timespec ts.Timespec
// ImageInfo represents the status information for an image.
type ImageInfo struct {
Size uint64

View File

@ -1,6 +1,7 @@
// +build !luminous,!mimic
//
// Ceph Nautilus is the first release that includes rbd_list2().
// Ceph Nautilus is the first release that includes rbd_list2() and
// rbd_get_create_timestamp().
package rbd
@ -14,6 +15,7 @@ import (
"unsafe"
"github.com/ceph/go-ceph/internal/retry"
ts "github.com/ceph/go-ceph/internal/timespec"
"github.com/ceph/go-ceph/rados"
)
@ -45,3 +47,21 @@ func GetImageNames(ioctx *rados.IOContext) ([]string, error) {
}
return names, nil
}
// GetCreateTimestamp returns the time the rbd image was created.
//
// Implements:
// int rbd_get_create_timestamp(rbd_image_t image, struct timespec *timestamp);
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
}