Repository: ceph/go-ceph (go)

Issue:
Missing rbd API components: function rbd_mirror_uuid_get
The rbd API implements function(s) below but go-ceph does not:
* rbd_mirror_uuid_get

This issue has been filed to track implementing this missing
functionality in the appropriate package within go-ceph.
Please refer to the Ceph C API for details about the function(s)
in question.

NOTE: This issue was generated by a script.
If the content looks wrong or the wording seems a bit odd
please excuse the script and blame @phlogistonjohn



Pull request description:
rbd : add missing API component
Fixes #488 

Add function rbd_mirror_uuid_get that is missing from go-ceph.

Signed-off-by: RAJAT SINGH <rajasing@redhat.com>


<!--
Thank you for opening a pull request. Please provide:

- A clear summary of your changes

- Descriptive and succinct commit messages with the format:
  """
  [topic]: [short description]

  [Longer description]

  Signed-off-by: [Your Name] <[your email]>
  """

  Topic will generally be the go ceph package dir you are working in.

- Ensure checklist items listed below are accounted for
-->

## Checklist
- [ ] Added tests for features and functional changes
- [ ] Public functions and types are documented
- [ ] Standard formatting is applied to Go code


Patch:
diff --git a/rbd/mirror.go b/rbd/mirror.go
index c5a9b0d..84f2f47 100644
--- a/rbd/mirror.go
+++ b/rbd/mirror.go
@@ -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.
 //


Test patch:
diff --git a/rbd/mirror_test.go b/rbd/mirror_test.go
index 5362be5..ad52901 100644
--- a/rbd/mirror_test.go
+++ b/rbd/mirror_test.go
@@ -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()