From 5b45db6803a289684e914509315f3e1aff3fee17 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Wed, 17 Jun 2020 16:17:17 +0200 Subject: [PATCH] rbd: add Image.GetCreateTimestamp() Signed-off-by: Niels de Vos --- rbd/rbd.go | 4 ++++ rbd/rbd_nautilus.go | 22 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/rbd/rbd.go b/rbd/rbd.go index 76cc5be..767ba07 100644 --- a/rbd/rbd.go +++ b/rbd/rbd.go @@ -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 diff --git a/rbd/rbd_nautilus.go b/rbd/rbd_nautilus.go index cf479a0..050db3a 100644 --- a/rbd/rbd_nautilus.go +++ b/rbd/rbd_nautilus.go @@ -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 +}