Skip to content

Commit

Permalink
rbd: add GetMirrorUUID function
Browse files Browse the repository at this point in the history
* Add GetMirrorUUID implementing rbd_mirror_uuid_get

This function is be used to get the mirroring uuid for the pool.
Basic tests included.

Signed-off-by: RAJAT SINGH <[email protected]>
  • Loading branch information
RAJAT SINGH authored and mergify[bot] committed Jun 8, 2021
1 parent 24eeb95 commit 5c49aab
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
28 changes: 28 additions & 0 deletions rbd/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,34 @@ func (imm ImageMirrorMode) String() string {
}
}

// GetMirrorUUID returns a string naming the mirroring uuid for the pool
// associated with the ioctx.
//
// Implements:
// int rbd_mirror_uuid_get(rados_ioctx_t io_ctx,
// char *uuid, size_t *max_len);
func GetMirrorUUID(ioctx *rados.IOContext) (string, error) {
var (
err error
buf []byte
cSize C.size_t
)
retry.WithSizes(1024, 1<<16, func(size int) retry.Hint {
cSize = C.size_t(size)
buf = make([]byte, cSize)
ret := C.rbd_mirror_uuid_get(
cephIoctx(ioctx),
(*C.char)(unsafe.Pointer(&buf[0])),
&cSize)
err = getErrorIfNegative(ret)
return retry.Size(int(cSize)).If(err == errRange)
})
if err != nil {
return "", err
}
return string(buf[:cSize]), nil
}

// SetMirrorMode is used to enable or disable pool level mirroring with either
// an automatic or per-image behavior.
//
Expand Down
45 changes: 45 additions & 0 deletions rbd/mirror_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,51 @@ import (
"github.com/stretchr/testify/require"
)

func TestGetMirrorUUID(t *testing.T) {
conn := radosConnect(t)
poolName := GetUUID()
err := conn.MakePool(poolName)
require.NoError(t, err)
defer func() {
assert.NoError(t, conn.DeletePool(poolName))
conn.Shutdown()
}()

ioctx, err := conn.OpenIOContext(poolName)
assert.NoError(t, err)
defer func() {
ioctx.Destroy()
}()

// verify that mirroring is not enabled on this new pool
m, err := GetMirrorMode(ioctx)
assert.NoError(t, err)
assert.Equal(t, m, MirrorModeDisabled)

// enable per-image mirroring for this pool
err = SetMirrorMode(ioctx, MirrorModeImage)
require.NoError(t, err)

name1 := GetUUID()
options := NewRbdImageOptions()
assert.NoError(t,
options.SetUint64(ImageOptionOrder, uint64(testImageOrder)))
err = CreateImage(ioctx, name1, testImageSize, options)
require.NoError(t, err)
t.Run("getUUID", func(t *testing.T) {
img, err := OpenImage(ioctx, name1, NoSnapshot)
assert.NoError(t, err)
defer func() {
assert.NoError(t, img.Close())
}()

err = img.MirrorEnable(ImageMirrorModeSnapshot)
assert.NoError(t, err)
miid, err := GetMirrorUUID(ioctx)
assert.NoError(t, err)
assert.NotEqual(t, miid, "")
})
}
func TestGetMirrorMode(t *testing.T) {
conn := radosConnect(t)
poolName := GetUUID()
Expand Down

0 comments on commit 5c49aab

Please sign in to comment.