mirror of https://github.com/ceph/go-ceph
rbd: additional error checking in GetPoolMetadata, SetPoolMetadata and RemovePoolMetadata
added a check to validate ioctx in all the three *PoolMetadata functions Signed-off-by: Mudit Agarwal <muagarwa@redhat.com>
This commit is contained in:
parent
624230cdbd
commit
7be8bbfe81
|
@ -23,6 +23,10 @@ import (
|
||||||
// Implements:
|
// Implements:
|
||||||
// int rbd_pool_metadata_get(rados_ioctx_t io_ctx, const char *key, char *value, size_t *val_len);
|
// int rbd_pool_metadata_get(rados_ioctx_t io_ctx, const char *key, char *value, size_t *val_len);
|
||||||
func GetPoolMetadata(ioctx *rados.IOContext, key string) (string, error) {
|
func GetPoolMetadata(ioctx *rados.IOContext, key string) (string, error) {
|
||||||
|
if ioctx == nil {
|
||||||
|
return "", ErrNoIOContext
|
||||||
|
}
|
||||||
|
|
||||||
cKey := C.CString(key)
|
cKey := C.CString(key)
|
||||||
defer C.free(unsafe.Pointer(cKey))
|
defer C.free(unsafe.Pointer(cKey))
|
||||||
|
|
||||||
|
@ -52,6 +56,10 @@ func GetPoolMetadata(ioctx *rados.IOContext, key string) (string, error) {
|
||||||
// Implements:
|
// Implements:
|
||||||
// int rbd_pool_metadata_set(rados_ioctx_t io_ctx, const char *key, const char *value);
|
// int rbd_pool_metadata_set(rados_ioctx_t io_ctx, const char *key, const char *value);
|
||||||
func SetPoolMetadata(ioctx *rados.IOContext, key, value string) error {
|
func SetPoolMetadata(ioctx *rados.IOContext, key, value string) error {
|
||||||
|
if ioctx == nil {
|
||||||
|
return ErrNoIOContext
|
||||||
|
}
|
||||||
|
|
||||||
cKey := C.CString(key)
|
cKey := C.CString(key)
|
||||||
defer C.free(unsafe.Pointer(cKey))
|
defer C.free(unsafe.Pointer(cKey))
|
||||||
cValue := C.CString(value)
|
cValue := C.CString(value)
|
||||||
|
@ -66,6 +74,10 @@ func SetPoolMetadata(ioctx *rados.IOContext, key, value string) error {
|
||||||
// Implements:
|
// Implements:
|
||||||
// int rbd_pool_metadata_remove(rados_ioctx_t io_ctx, const char *key)
|
// int rbd_pool_metadata_remove(rados_ioctx_t io_ctx, const char *key)
|
||||||
func RemovePoolMetadata(ioctx *rados.IOContext, key string) error {
|
func RemovePoolMetadata(ioctx *rados.IOContext, key string) error {
|
||||||
|
if ioctx == nil {
|
||||||
|
return ErrNoIOContext
|
||||||
|
}
|
||||||
|
|
||||||
cKey := C.CString(key)
|
cKey := C.CString(key)
|
||||||
defer C.free(unsafe.Pointer(cKey))
|
defer C.free(unsafe.Pointer(cKey))
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,24 @@ func TestPoolMetadata(t *testing.T) {
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("NullKey", func(t *testing.T) {
|
||||||
|
_, err := GetPoolMetadata(ioctx, "")
|
||||||
|
assert.Error(t, err)
|
||||||
|
err = SetPoolMetadata(ioctx, "", "")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
err = RemovePoolMetadata(ioctx, "")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("NullIOContext", func(t *testing.T) {
|
||||||
|
_, err := GetPoolMetadata(nil, "someKey")
|
||||||
|
assert.Error(t, err)
|
||||||
|
err = SetPoolMetadata(nil, "someKey", "someValue")
|
||||||
|
assert.Error(t, err)
|
||||||
|
err = RemovePoolMetadata(nil, "someKey")
|
||||||
|
assert.Error(t, err)
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("SetGetValues", func(t *testing.T) {
|
t.Run("SetGetValues", func(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
key1 = "key1"
|
key1 = "key1"
|
||||||
|
|
Loading…
Reference in New Issue