From: Mykola Golub Date: Sun, 11 Feb 2024 09:43:30 +0000 (+0000) Subject: tools/rbd: make 'children' command support --image-id X-Git-Tag: v19.1.0~292^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=5442f7eb218ff9024365f3a28e4affb5add1ee1e;p=ceph.git tools/rbd: make 'children' command support --image-id Fixes: https://tracker.ceph.com/issues/64376 Signed-off-by: Mykola Golub --- diff --git a/PendingReleaseNotes b/PendingReleaseNotes index a413b6276f2f0..2e41462a1eb68 100644 --- a/PendingReleaseNotes +++ b/PendingReleaseNotes @@ -133,6 +133,8 @@ CephFS: Disallow delegating preallocated inode ranges to clients. Config notifications to topics owned by other users. A new configuration parameter: ``rgw_topic_require_publish_policy`` can be enabled to deny ``sns:Publish`` permissions unless explicitly granted by topic policy. +* RBD: The option ``--image-id`` has been added to `rbd children` CLI command, + so it can be run for images in the trash. >=18.0.0 diff --git a/qa/workunits/rbd/cli_generic.sh b/qa/workunits/rbd/cli_generic.sh index c35bbe8f83e6a..15c47074db5f9 100755 --- a/qa/workunits/rbd/cli_generic.sh +++ b/qa/workunits/rbd/cli_generic.sh @@ -432,6 +432,7 @@ test_trash() { rbd trash mv test2 ID=`rbd trash ls | cut -d ' ' -f 1` rbd info --image-id $ID | grep "rbd image 'test2'" + rbd children --image-id $ID | wc -l | grep 0 rbd trash restore $ID rbd ls | grep test2 @@ -449,6 +450,7 @@ test_trash() { rbd create $RBD_CREATE_ARGS -s 1 test1 rbd snap create test1@snap1 rbd snap protect test1@snap1 + rbd clone test1@snap1 clone rbd trash mv test1 rbd trash ls | grep test1 @@ -459,7 +461,10 @@ test_trash() { ID=`rbd trash ls | cut -d ' ' -f 1` rbd snap ls --image-id $ID | grep -v 'SNAPID' | wc -l | grep 1 rbd snap ls --image-id $ID | grep '.*snap1.*' + rbd children --image-id $ID | wc -l | grep 1 + rbd children --image-id $ID | grep 'clone' + rbd rm clone rbd snap unprotect --image-id $ID --snap snap1 rbd snap rm --image-id $ID --snap snap1 rbd snap ls --image-id $ID | grep -v 'SNAPID' | wc -l | grep 0 diff --git a/src/test/cli/rbd/help.t b/src/test/cli/rbd/help.t index 2d1c901462c76..866bd8f11c85f 100644 --- a/src/test/cli/rbd/help.t +++ b/src/test/cli/rbd/help.t @@ -195,9 +195,9 @@ rbd help children usage: rbd children [--pool ] [--namespace ] - [--image ] [--snap ] [--snap-id ] - [--all] [--descendants] [--format ] - [--pretty-format] + [--image ] [--snap ] [--image-id ] + [--snap-id ] [--all] [--descendants] + [--format ] [--pretty-format] Display children of an image or its snapshot. @@ -212,6 +212,7 @@ --namespace arg namespace name --image arg image name --snap arg snapshot name + --image-id arg image id --snap-id arg snapshot id -a [ --all ] list all children (include trash) --descendants include all descendants diff --git a/src/tools/rbd/action/Children.cc b/src/tools/rbd/action/Children.cc index 58e861b6928bc..6881989abb25e 100644 --- a/src/tools/rbd/action/Children.cc +++ b/src/tools/rbd/action/Children.cc @@ -84,6 +84,7 @@ void get_arguments(po::options_description *positional, po::options_description *options) { at::add_image_or_snap_spec_options(positional, options, at::ARGUMENT_MODIFIER_NONE); + at::add_image_id_option(options); at::add_snap_id_option(options); options->add_options() ("all,a", po::bool_switch(), "list all children (include trash)"); @@ -104,14 +105,26 @@ int execute(const po::variables_map &vm, std::string namespace_name; std::string image_name; std::string snap_name; + std::string image_id; + + if (vm.count(at::IMAGE_ID)) { + image_id = vm[at::IMAGE_ID].as(); + } + int r = utils::get_pool_image_snapshot_names( vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, &pool_name, &namespace_name, - &image_name, &snap_name, true, utils::SNAPSHOT_PRESENCE_PERMITTED, - utils::SPEC_VALIDATION_NONE); + &image_name, &snap_name, image_id.empty(), + utils::SNAPSHOT_PRESENCE_PERMITTED, utils::SPEC_VALIDATION_NONE); if (r < 0) { return r; } + if (!image_id.empty() && !image_name.empty()) { + std::cerr << "rbd: trying to access image using both name and id." + << std::endl; + return -EINVAL; + } + if (snap_id != LIBRADOS_SNAP_HEAD && !snap_name.empty()) { std::cerr << "rbd: trying to access snapshot using both name and id." << std::endl; @@ -127,8 +140,8 @@ int execute(const po::variables_map &vm, librados::Rados rados; librados::IoCtx io_ctx; librbd::Image image; - r = utils::init_and_open_image(pool_name, namespace_name, image_name, "", "", - true, &rados, &io_ctx, &image); + r = utils::init_and_open_image(pool_name, namespace_name, image_name, + image_id, "", true, &rados, &io_ctx, &image); if (r < 0) { return r; }