continue after -ERANGE in retval of rbd_list_children. fix out of range on zero children

This commit is contained in:
Ryan Roemmich 2016-04-05 09:47:47 -06:00
parent 29d1ad9394
commit 777d9c72ab
2 changed files with 23 additions and 1 deletions

View File

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

View File

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