]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rbd: add option to list all descendant images
authorMykola Golub <mgolub@suse.com>
Fri, 8 Feb 2019 17:54:23 +0000 (17:54 +0000)
committerMykola Golub <mgolub@suse.com>
Tue, 19 Feb 2019 08:58:08 +0000 (08:58 +0000)
Signed-off-by: Mykola Golub <mgolub@suse.com>
qa/workunits/rbd/cli_generic.sh
src/test/cli/rbd/help.t
src/tools/rbd/action/Children.cc

index 97d64577fad5b7219dd40ef60685fe77bece638f..2b46ef785d7ae48e9c98a2568da919b431a3dc80 100755 (executable)
@@ -555,6 +555,7 @@ test_clone_v2() {
     rbd clone --rbd-default-clone-format=1 test1@1 test4
 
     rbd children test1@1 | sort | tr '\n' ' ' | grep -E "test2.*test3.*test4"
+    rbd children --descendants test1 | sort | tr '\n' ' ' | grep -E "test2.*test3.*test4"
 
     rbd remove test4
     rbd snap unprotect test1@1
index 453698a620c40b86ae21884f5978dac902bb3afe..1f642694d01f61938aecf389e47346d881cb72ca 100644 (file)
   rbd help children
   usage: rbd children [--pool <pool>] [--namespace <namespace>] 
                       [--image <image>] [--snap <snap>] [--snap-id <snap-id>] 
-                      [--all] [--format <format>] [--pretty-format] 
+                      [--all] [--descendants] [--format <format>] 
+                      [--pretty-format] 
                       <image-or-snap-spec> 
   
   Display children of an image or its snapshot.
     --snap arg            snapshot name
     --snap-id arg         snapshot id
     -a [ --all ]          list all children (include trash)
+    --descendants         include all descendants
     --format arg          output format (plain, json, or xml) [default: plain]
     --pretty-format       pretty formatting (json and xml)
   
index b419c4c791601076dadc27b64b547a10857f193b..1225862960b46615cb71d8d5da76dd3b3f69a334 100644 (file)
@@ -17,11 +17,16 @@ namespace at = argument_types;
 namespace po = boost::program_options;
 
 int do_list_children(librados::IoCtx &io_ctx, librbd::Image &image,
-                     bool all_flag, Formatter *f)
+                     bool all_flag, bool descendants_flag, Formatter *f)
 {
   std::vector<librbd::linked_image_spec_t> children;
   librbd::RBD rbd;
-  int r = image.list_children3(&children);
+  int r;
+  if (descendants_flag) {
+    r = image.list_descendants(&children);
+  } else {
+    r = image.list_children3(&children);
+  }
   if (r < 0)
     return r;
 
@@ -74,6 +79,8 @@ void get_arguments(po::options_description *positional,
   at::add_snap_id_option(options);
   options->add_options()
     ("all,a", po::bool_switch(), "list all children (include trash)");
+  options->add_options()
+    ("descendants", po::bool_switch(), "include all descendants");
   at::add_format_options(options);
 }
 
@@ -132,7 +139,8 @@ int execute(const po::variables_map &vm,
     return r;
   }
 
-  r = do_list_children(io_ctx, image, vm["all"].as<bool>(), formatter.get());
+  r = do_list_children(io_ctx, image, vm["all"].as<bool>(),
+                       vm["descendants"].as<bool>(), formatter.get());
   if (r < 0) {
     std::cerr << "rbd: listing children failed: " << cpp_strerror(r)
               << std::endl;