From a2c1c2bb345f3dc676c4ee53c61742d78f28b719 Mon Sep 17 00:00:00 2001 From: Mudit Agarwal Date: Sat, 6 Jun 2020 06:53:41 +0530 Subject: [PATCH] rbd: add wrapper for rbd_pool_metadata_remove() Add wrapper for rbd_pool_metadata_remove() function which removes pool metadata associated with a given key. Signed-off-by: Mudit Agarwal --- rbd/pool_nautilus.go | 14 +++++++++++++- rbd/pool_nautilus_test.go | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/rbd/pool_nautilus.go b/rbd/pool_nautilus.go index b86c6a2..22610ed 100644 --- a/rbd/pool_nautilus.go +++ b/rbd/pool_nautilus.go @@ -1,7 +1,7 @@ // +build !luminous,!mimic // // Ceph Nautilus is the first release that includes rbd_pool_metadata_get(), -// rbd_pool_metadata_set(). +// rbd_pool_metadata_set() and rbd_pool_metadata_remove(). package rbd @@ -60,3 +60,15 @@ func SetPoolMetadata(ioctx *rados.IOContext, key, value string) error { ret := C.rbd_pool_metadata_set(cephIoctx(ioctx), cKey, cValue) return getError(ret) } + +// RemovePoolMetadata removes the pool metadata value for a given pool metadata key. +// +// Implements: +// int rbd_pool_metadata_remove(rados_ioctx_t io_ctx, const char *key) +func RemovePoolMetadata(ioctx *rados.IOContext, key string) error { + cKey := C.CString(key) + defer C.free(unsafe.Pointer(cKey)) + + ret := C.rbd_pool_metadata_remove(cephIoctx(ioctx), cKey) + return getError(ret) +} diff --git a/rbd/pool_nautilus_test.go b/rbd/pool_nautilus_test.go index ac212a2..5042d71 100644 --- a/rbd/pool_nautilus_test.go +++ b/rbd/pool_nautilus_test.go @@ -59,4 +59,25 @@ func TestPoolMetadata(t *testing.T) { assert.NoError(t, err) assert.Equal(t, keyLen, len(myVal)) }) + + t.Run("removeNonExistingKey", func(t *testing.T) { + err := RemovePoolMetadata(ioctx, "someKey") + assert.Error(t, err) + }) + + t.Run("removeExistingKey", func(t *testing.T) { + var ( + myKey = "myKey" + myVal = "myVal" + ) + assert.NoError(t, SetPoolMetadata(ioctx, myKey, myVal)) + _, err := GetPoolMetadata(ioctx, myKey) + assert.NoError(t, err) + + // Remove the key. + err = RemovePoolMetadata(ioctx, myKey) + assert.NoError(t, err) + _, err = GetPoolMetadata(ioctx, myKey) + assert.Error(t, err) + }) }