From 3032c539a01e67785c890aec05f04464254dfc0d Mon Sep 17 00:00:00 2001 From: Mudit Agarwal Date: Mon, 25 Jan 2021 14:21:02 +0530 Subject: [PATCH] rbd: add GetImageMirrorMode() to get the mirroing mode of a RBD image Signed-off-by: Mudit Agarwal --- rbd/mirror.go | 14 ++++++++++++++ rbd/mirror_test.go | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/rbd/mirror.go b/rbd/mirror.go index 5955af6..1087494 100644 --- a/rbd/mirror.go +++ b/rbd/mirror.go @@ -219,3 +219,17 @@ func (image *Image) GetMirrorImageInfo() (*MirrorImageInfo, error) { C.rbd_mirror_image_get_info_cleanup(&cInfo) return &mii, nil } + +// GetImageMirrorMode fetches the mirroring approach for an RBD image. +// +// Implements: +// int rbd_mirror_image_get_mode(rbd_image_t image, rbd_mirror_image_mode_t *mode); +func (image *Image) GetImageMirrorMode() (ImageMirrorMode, error) { + var mode C.rbd_mirror_image_mode_t + if err := image.validate(imageIsOpen); err != nil { + return ImageMirrorMode(mode), err + } + + ret := C.rbd_mirror_image_get_mode(image.image, &mode) + return ImageMirrorMode(mode), getError(ret) +} diff --git a/rbd/mirror_test.go b/rbd/mirror_test.go index 2f49175..a8eb8e0 100644 --- a/rbd/mirror_test.go +++ b/rbd/mirror_test.go @@ -91,6 +91,11 @@ func TestMirroring(t *testing.T) { err = img.MirrorEnable(ImageMirrorModeSnapshot) assert.NoError(t, err) + + mode, err := img.GetImageMirrorMode() + assert.NoError(t, err) + assert.Equal(t, mode, ImageMirrorModeSnapshot) + err = img.MirrorDisable(false) assert.NoError(t, err) }) @@ -103,6 +108,8 @@ func TestMirroring(t *testing.T) { assert.Error(t, err) err = img.MirrorDisable(false) assert.Error(t, err) + _, err = img.GetImageMirrorMode() + assert.Error(t, err) }) t.Run("promoteDemote", func(t *testing.T) { img, err := OpenImage(ioctx, name1, NoSnapshot)