]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
librbd: make list_children work if parent snap is head
authorMykola Golub <mgolub@suse.com>
Thu, 7 Feb 2019 10:03:08 +0000 (10:03 +0000)
committerMykola Golub <mgolub@suse.com>
Tue, 19 Feb 2019 08:43:09 +0000 (08:43 +0000)
(returning children for all the image snaps in this case)

Signed-off-by: Mykola Golub <mgolub@suse.com>
src/librbd/api/Image.cc

index 80fad287eafb4db9e7a805159a312db37c59af3d..94154e9579546d0a9ef3d215c6921812d72a6ddf 100644 (file)
@@ -233,11 +233,25 @@ int Image<I>::get_parent(I *ictx,
 template <typename I>
 int Image<I>::list_children(I *ictx,
                             std::vector<librbd::linked_image_spec_t> *images) {
+  images->clear();
+
   RWLock::RLocker l(ictx->snap_lock);
-  cls::rbd::ParentImageSpec parent_spec{ictx->md_ctx.get_id(),
-                                        ictx->md_ctx.get_namespace(),
-                                        ictx->id, ictx->snap_id};
-  return list_children(ictx, parent_spec, images);
+  std::vector<librados::snap_t> snap_ids;
+  if (ictx->snap_id != CEPH_NOSNAP) {
+    snap_ids.push_back(ictx->snap_id);
+  } else {
+    snap_ids = ictx->snaps;
+  }
+  for (auto snap_id : snap_ids) {
+    cls::rbd::ParentImageSpec parent_spec{ictx->md_ctx.get_id(),
+                                          ictx->md_ctx.get_namespace(),
+                                          ictx->id, snap_id};
+    int r = list_children(ictx, parent_spec, images);
+    if (r < 0) {
+      return r;
+    }
+  }
+  return 0;
 }
 
 template <typename I>
@@ -252,8 +266,6 @@ int Image<I>::list_children(I *ictx,
     return 0;
   }
 
-  images->clear();
-
   librados::Rados rados(ictx->md_ctx);
 
   // search all pools for clone v1 children dependent on this snapshot