rbd: add GetImageMirrorMode() to get the mirroing mode of a RBD image

Signed-off-by: Mudit Agarwal <muagarwa@redhat.com>
This commit is contained in:
Mudit Agarwal 2021-01-25 14:21:02 +05:30 committed by mergify[bot]
parent 6ff40f828f
commit 3032c539a0
2 changed files with 21 additions and 0 deletions

View File

@ -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)
}

View File

@ -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)