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 <muagarwa@redhat.com>
This commit is contained in:
Mudit Agarwal 2020-06-06 06:53:41 +05:30 committed by John Mulligan
parent d999f78e2e
commit a2c1c2bb34
2 changed files with 34 additions and 1 deletions

View File

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

View File

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