From 1923b60e8a9c6535766afe212bbd8ed13f08a70b Mon Sep 17 00:00:00 2001 From: Mykola Golub Date: Thu, 7 Feb 2019 10:06:55 +0000 Subject: [PATCH] rbd: allow 'children' command work if no snap specified Signed-off-by: Mykola Golub --- src/test/cli/rbd/help.t | 31 +++++++++++++++--------------- src/test/cli/rbd/not-enough-args.t | 3 --- src/tools/rbd/action/Children.cc | 18 ++++++++--------- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/test/cli/rbd/help.t b/src/test/cli/rbd/help.t index 76ea32829e1bd..a93323be735f0 100644 --- a/src/test/cli/rbd/help.t +++ b/src/test/cli/rbd/help.t @@ -6,7 +6,8 @@ Positional arguments: 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. @@ -173,25 +174,25 @@ usage: rbd children [--pool ] [--namespace ] [--image ] [--snap ] [--snap-id ] [--all] [--format ] [--pretty-format] - + - Display children of snapshot. + Display children of an image or its snapshot. Positional arguments - snapshot specification - (example: - [/[/]]@) + image or snapshot specification + (example: + [/[/]][@]) 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 ] [--namespace ] [--image ] diff --git a/src/test/cli/rbd/not-enough-args.t b/src/test/cli/rbd/not-enough-args.t index cc9078b83328a..3f613e6bbd8bb 100644 --- a/src/test/cli/rbd/not-enough-args.t +++ b/src/test/cli/rbd/not-enough-args.t @@ -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] diff --git a/src/tools/rbd/action/Children.cc b/src/tools/rbd/action/Children.cc index b13195506a01d..b419c4c791601 100644 --- a/src/tools/rbd/action/Children.cc +++ b/src/tools/rbd/action/Children.cc @@ -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 &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(); - 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 -- 2.39.5