diff --git a/qa/workunits/rbd/cli_generic.sh b/qa/workunits/rbd/cli_generic.sh index 97d64577fad..2b46ef785d7 100755 --- a/qa/workunits/rbd/cli_generic.sh +++ b/qa/workunits/rbd/cli_generic.sh @@ -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 diff --git a/src/test/cli/rbd/help.t b/src/test/cli/rbd/help.t index 453698a620c..1f642694d01 100644 --- a/src/test/cli/rbd/help.t +++ b/src/test/cli/rbd/help.t @@ -173,7 +173,8 @@ rbd help children usage: rbd children [--pool ] [--namespace ] [--image ] [--snap ] [--snap-id ] - [--all] [--format ] [--pretty-format] + [--all] [--descendants] [--format ] + [--pretty-format] Display children of an image or its snapshot. @@ -190,6 +191,7 @@ --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) diff --git a/src/tools/rbd/action/Children.cc b/src/tools/rbd/action/Children.cc index b419c4c7916..1225862960b 100644 --- a/src/tools/rbd/action/Children.cc +++ b/src/tools/rbd/action/Children.cc @@ -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 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(), formatter.get()); + r = do_list_children(io_ctx, image, vm["all"].as(), + vm["descendants"].as(), formatter.get()); if (r < 0) { std::cerr << "rbd: listing children failed: " << cpp_strerror(r) << std::endl;