rbd: add wrapper for rbd_pool_init() function

Added PoolInit function implementing rbd_pool_init which sets the
application tag to rbd.

Signed-off-by: Mudit Agarwal <muagarwa@redhat.com>
This commit is contained in:
Mudit Agarwal 2020-07-04 09:06:07 +05:30 committed by John Mulligan
parent 0ffebd1f25
commit 0cd2b21224
2 changed files with 47 additions and 0 deletions

View File

@ -84,3 +84,18 @@ func RemovePoolMetadata(ioctx *rados.IOContext, key string) error {
ret := C.rbd_pool_metadata_remove(cephIoctx(ioctx), cKey)
return getError(ret)
}
// PoolInit initializes a pool for use by rbd.
// This function does not create new pools, rather it prepares the pool
// to host rbd images.
//
// Implements:
// int rbd_pool_init(rados_ioctx_t io, bool force)
func PoolInit(ioctx *rados.IOContext, force bool) error {
if ioctx == nil {
return ErrNoIOContext
}
ret := C.rbd_pool_init(cephIoctx(ioctx), C.bool(force))
return getError(ret)
}

View File

@ -99,3 +99,35 @@ func TestPoolMetadata(t *testing.T) {
assert.Error(t, err)
})
}
func TestPoolInit(t *testing.T) {
conn := radosConnect(t)
poolName := GetUUID()
err := conn.MakePool(poolName)
assert.NoError(t, err)
ioctx, err := conn.OpenIOContext(poolName)
assert.NoError(t, err)
assert.NotNil(t, ioctx)
defer func() {
ioctx.Destroy()
conn.DeletePool(poolName)
conn.Shutdown()
}()
t.Run("NullIOContext", func(t *testing.T) {
err := PoolInit(nil, true)
assert.Error(t, err)
})
t.Run("PoolInitWithForce", func(t *testing.T) {
err := PoolInit(ioctx, true)
assert.NoError(t, err)
})
t.Run("PoolInitWithoutForce", func(t *testing.T) {
err := PoolInit(ioctx, false)
assert.NoError(t, err)
})
}