rbd: add SetSnapshot (re)implementing rbd_snap_set

Signed-off-by: oct28.yjkim <oct28.yjkim@gmail.com>
This commit is contained in:
oct28-yjkim 2021-05-10 14:34:52 +09:00 committed by mergify[bot]
parent 97eefba287
commit 8e4b8349aa
3 changed files with 21 additions and 4 deletions

View File

@ -916,6 +916,22 @@ func (image *Image) GetId() (string, error) {
}
// SetSnapshot updates the rbd image (not the Snapshot) such that the snapshot
// is the source of readable data.
//
// Implements:
// int rbd_snap_set(rbd_image_t image, const char *snapname);
func (image *Image) SetSnapshot(snapname string) error {
if err := image.validate(imageIsOpen); err != nil {
return err
}
c_snapname := C.CString(snapname)
defer C.free(unsafe.Pointer(c_snapname))
return getError(C.rbd_snap_set(image.image, c_snapname))
}
// GetTrashList returns a slice of TrashInfo structs, containing information about all RBD images
// currently residing in the trash.
func GetTrashList(ioctx *rados.IOContext) ([]TrashInfo, error) {

View File

@ -149,6 +149,7 @@ func (snapshot *Snapshot) IsProtected() (bool, error) {
// Set updates the rbd image (not the Snapshot) such that the snapshot
// is the source of readable data.
// This method is deprecated. Refer the SetSnapshot method of the Image type instead.
//
// Implements:
// int rbd_snap_set(rbd_image_t image, const char *snapname);
@ -157,10 +158,7 @@ func (snapshot *Snapshot) Set() error {
return err
}
c_snapname := C.CString(snapshot.name)
defer C.free(unsafe.Pointer(c_snapname))
return getError(C.rbd_snap_set(snapshot.image.image, c_snapname))
return snapshot.image.SetSnapshot(snapshot.name)
}
// GetSnapTimestamp returns the timestamp of a snapshot for an image.

View File

@ -94,6 +94,9 @@ func TestErrorSnapshotNoName(t *testing.T) {
_, err = snapshot.IsProtected()
assert.Equal(t, err, ErrSnapshotNoName)
err = img.SetSnapshot(snapshot.name)
assert.Equal(t, err, ErrImageNotOpen)
err = snapshot.Set()
assert.Equal(t, err, ErrSnapshotNoName)