From 777d9c72abe9bfa08dc1c845fcfd2882b3716300 Mon Sep 17 00:00:00 2001 From: Ryan Roemmich Date: Tue, 5 Apr 2016 09:47:47 -0600 Subject: [PATCH] continue after -ERANGE in retval of rbd_list_children. fix out of range on zero children --- rbd/rbd.go | 5 ++++- rbd/rbd_test.go | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/rbd/rbd.go b/rbd/rbd.go index 3e9b57a..86e8056 100644 --- a/rbd/rbd.go +++ b/rbd/rbd.go @@ -461,7 +461,10 @@ func (image *Image) ListChildren() (pools []string, images []string, err error) ret := C.rbd_list_children(image.image, nil, &c_pools_len, nil, &c_images_len) - if ret < 0 { + if ret == 0 { + return nil, nil, nil + } + if ret < 0 && ret != -C.ERANGE { return nil, nil, RBDError(int(ret)) } diff --git a/rbd/rbd_test.go b/rbd/rbd_test.go index d4c098f..ce67b28 100644 --- a/rbd/rbd_test.go +++ b/rbd/rbd_test.go @@ -188,6 +188,17 @@ func TestParentInfo(t *testing.T) { err = snapshot.Protect() assert.NoError(t, err) + // create an image context with the parent+snapshot + snapImg := rbd.GetImage(ioctx, "parent") + err = snapImg.Open("mysnap") + assert.NoError(t, err) + + // ensure no children prior to clone + pools, images, err := snapImg.ListChildren() + assert.NoError(t, err) + assert.Equal(t, len(pools), 0, "pools equal") + assert.Equal(t, len(images), 0, "children length equal") + imgNew, err := img.Clone("mysnap", ioctx, "child", 1, 22) assert.NoError(t, err) @@ -208,6 +219,11 @@ func TestParentInfo(t *testing.T) { assert.Equal(t, pName, "parent", "they should be equal") assert.Equal(t, pSnapname, "mysnap", "they should be equal") + pools, images, err = snapImg.ListChildren() + assert.NoError(t, err) + assert.Equal(t, len(pools), 1, "pools equal") + assert.Equal(t, len(images), 1, "children length equal") + err = imgNew.Close() assert.NoError(t, err) @@ -223,6 +239,9 @@ func TestParentInfo(t *testing.T) { err = img.Close() assert.NoError(t, err) + err = snapImg.Close() + assert.NoError(t, err) + err = img.Remove() assert.NoError(t, err)