]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: allow 'children' command work if no snap specified
authorMykola Golub <mgolub@suse.com>
Thu, 7 Feb 2019 10:06:55 +0000 (10:06 +0000)
committerMykola Golub <mgolub@suse.com>
Tue, 19 Feb 2019 08:43:09 +0000 (08:43 +0000)
Signed-off-by: Mykola Golub <mgolub@suse.com>
src/test/cli/rbd/help.t
src/test/cli/rbd/not-enough-args.t
src/tools/rbd/action/Children.cc

index 76ea32829e1bd789e4e4052a37f8502b7a91f01f..a93323be735f0d854540f907715cfd08a63892af 100644 (file)
@@ -6,7 +6,8 @@
   Positional arguments:
     <command>
       bench                             Simple benchmark.
-      children                          Display children of snapshot.
+      children                          Display children of an image or its
+                                        snapshot.
       clone                             Clone a snapshot into a CoW child image.
       config global get                 Get a global-level configuration override.
       config global list (... ls)       List global-level configuration overrides.
   usage: rbd children [--pool <pool>] [--namespace <namespace>] 
                       [--image <image>] [--snap <snap>] [--snap-id <snap-id>] 
                       [--all] [--format <format>] [--pretty-format] 
-                      <snap-spec> 
+                      <image-or-snap-spec> 
   
-  Display children of snapshot.
+  Display children of an image or its snapshot.
   
   Positional arguments
-    <snap-spec>          snapshot specification
-                         (example:
-                         [<pool-name>/[<namespace-name>/]]<image-name>@<snapshot-n
-                         ame>)
+    <image-or-snap-spec>  image or snapshot specification
+                          (example:
+                          [<pool-name>/[<namespace-name>/]]<image-name>[@<snap-nam
+                          e>])
   
   Optional arguments
-    -p [ --pool ] arg    pool name
-    --namespace arg      namespace name
-    --image arg          image name
-    --snap arg           snapshot name
-    --snap-id arg        snapshot id
-    -a [ --all ]         list all children of snapshot (include trash)
-    --format arg         output format (plain, json, or xml) [default: plain]
-    --pretty-format      pretty formatting (json and xml)
+    -p [ --pool ] arg     pool name
+    --namespace arg       namespace name
+    --image arg           image name
+    --snap arg            snapshot name
+    --snap-id arg         snapshot id
+    -a [ --all ]          list all children (include trash)
+    --format arg          output format (plain, json, or xml) [default: plain]
+    --pretty-format       pretty formatting (json and xml)
   
   rbd help clone
   usage: rbd clone [--pool <pool>] [--namespace <namespace>] [--image <image>] 
index cc9078b83328ad7ac35850a14bf55e05deb59d9c..3f613e6bbd8bb422014950e26d03e40af486f2a2 100644 (file)
@@ -22,9 +22,6 @@
   $ rbd children
   rbd: image name was not specified
   [22]
-  $ rbd children foo
-  rbd: snapshot name was not specified
-  [22]
   $ rbd flatten
   rbd: image name was not specified
   [22]
index b13195506a01df77d117e97eac44a64d2cae2ee9..b419c4c791601076dadc27b64b547a10857f193b 100644 (file)
@@ -69,20 +69,19 @@ int do_list_children(librados::IoCtx &io_ctx, librbd::Image &image,
 
 void get_arguments(po::options_description *positional,
                    po::options_description *options) {
-  at::add_snap_spec_options(positional, options, at::ARGUMENT_MODIFIER_NONE);
+  at::add_image_or_snap_spec_options(positional, options,
+                                     at::ARGUMENT_MODIFIER_NONE);
   at::add_snap_id_option(options);
   options->add_options()
-    ("all,a", po::bool_switch(), "list all children of snapshot (include trash)");
+    ("all,a", po::bool_switch(), "list all children (include trash)");
   at::add_format_options(options);
 }
 
 int execute(const po::variables_map &vm,
             const std::vector<std::string> &ceph_global_init_args) {
   uint64_t snap_id = LIBRADOS_SNAP_HEAD;
-  auto snap_presence = utils::SNAPSHOT_PRESENCE_REQUIRED;
   if (vm.count(at::SNAPSHOT_ID)) {
     snap_id = vm[at::SNAPSHOT_ID].as<uint64_t>();
-    snap_presence = utils::SNAPSHOT_PRESENCE_PERMITTED;
   }
 
   size_t arg_index = 0;
@@ -92,7 +91,8 @@ int execute(const po::variables_map &vm,
   std::string snap_name;
   int r = utils::get_pool_image_snapshot_names(
     vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, &pool_name, &namespace_name,
-    &image_name, &snap_name, true, snap_presence, utils::SPEC_VALIDATION_NONE);
+    &image_name, &snap_name, true, utils::SNAPSHOT_PRESENCE_PERMITTED,
+    utils::SPEC_VALIDATION_NONE);
   if (r < 0) {
     return r;
   }
@@ -118,9 +118,9 @@ int execute(const po::variables_map &vm,
     return r;
   }
 
-  if (snap_id == LIBRADOS_SNAP_HEAD) {
+  if (!snap_name.empty()) {
     r = image.snap_set(snap_name.c_str());
-  } else {
+  } else if (snap_id != LIBRADOS_SNAP_HEAD) {
     r = image.snap_set_by_id(snap_id);
   }
   if (r == -ENOENT) {
@@ -142,8 +142,8 @@ int execute(const po::variables_map &vm,
 }
 
 Shell::Action action(
-  {"children"}, {}, "Display children of snapshot.", "", &get_arguments,
-  &execute);
+  {"children"}, {}, "Display children of an image or its snapshot.", "",
+  &get_arguments, &execute);
 
 } // namespace children
 } // namespace action