mirror of https://github.com/ceph/go-ceph
rbd: add GetMirrorUUID function
* 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 <rajasing@redhat.com>
This commit is contained in:
parent
24eeb9512c
commit
5c49aab11e
|
@ -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
|
// SetMirrorMode is used to enable or disable pool level mirroring with either
|
||||||
// an automatic or per-image behavior.
|
// an automatic or per-image behavior.
|
||||||
//
|
//
|
||||||
|
|
|
@ -17,6 +17,51 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"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) {
|
func TestGetMirrorMode(t *testing.T) {
|
||||||
conn := radosConnect(t)
|
conn := radosConnect(t)
|
||||||
poolName := GetUUID()
|
poolName := GetUUID()
|
||||||
|
|
Loading…
Reference in New Issue