Skip to content

Commit aface5a

Browse files
authored
Merge pull request ceph#55530 from trociny/wip-64376
tools/rbd: make 'children' command support --image-id Reviewed-by: Ilya Dryomov <[email protected]>
2 parents d53ffea + 5442f7e commit aface5a

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

PendingReleaseNotes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ CephFS: Disallow delegating preallocated inode ranges to clients. Config
133133
notifications to topics owned by other users. A new configuration parameter:
134134
``rgw_topic_require_publish_policy`` can be enabled to deny ``sns:Publish``
135135
permissions unless explicitly granted by topic policy.
136+
* RBD: The option ``--image-id`` has been added to `rbd children` CLI command,
137+
so it can be run for images in the trash.
136138

137139
>=18.0.0
138140

qa/workunits/rbd/cli_generic.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ test_trash() {
432432
rbd trash mv test2
433433
ID=`rbd trash ls | cut -d ' ' -f 1`
434434
rbd info --image-id $ID | grep "rbd image 'test2'"
435+
rbd children --image-id $ID | wc -l | grep 0
435436

436437
rbd trash restore $ID
437438
rbd ls | grep test2
@@ -449,6 +450,7 @@ test_trash() {
449450
rbd create $RBD_CREATE_ARGS -s 1 test1
450451
rbd snap create test1@snap1
451452
rbd snap protect test1@snap1
453+
rbd clone test1@snap1 clone
452454
rbd trash mv test1
453455

454456
rbd trash ls | grep test1
@@ -459,7 +461,10 @@ test_trash() {
459461
ID=`rbd trash ls | cut -d ' ' -f 1`
460462
rbd snap ls --image-id $ID | grep -v 'SNAPID' | wc -l | grep 1
461463
rbd snap ls --image-id $ID | grep '.*snap1.*'
464+
rbd children --image-id $ID | wc -l | grep 1
465+
rbd children --image-id $ID | grep 'clone'
462466

467+
rbd rm clone
463468
rbd snap unprotect --image-id $ID --snap snap1
464469
rbd snap rm --image-id $ID --snap snap1
465470
rbd snap ls --image-id $ID | grep -v 'SNAPID' | wc -l | grep 0

src/test/cli/rbd/help.t

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@
195195

196196
rbd help children
197197
usage: rbd children [--pool <pool>] [--namespace <namespace>]
198-
[--image <image>] [--snap <snap>] [--snap-id <snap-id>]
199-
[--all] [--descendants] [--format <format>]
200-
[--pretty-format]
198+
[--image <image>] [--snap <snap>] [--image-id <image-id>]
199+
[--snap-id <snap-id>] [--all] [--descendants]
200+
[--format <format>] [--pretty-format]
201201
<image-or-snap-spec>
202202

203203
Display children of an image or its snapshot.
@@ -212,6 +212,7 @@
212212
--namespace arg namespace name
213213
--image arg image name
214214
--snap arg snapshot name
215+
--image-id arg image id
215216
--snap-id arg snapshot id
216217
-a [ --all ] list all children (include trash)
217218
--descendants include all descendants

src/tools/rbd/action/Children.cc

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ void get_arguments(po::options_description *positional,
8484
po::options_description *options) {
8585
at::add_image_or_snap_spec_options(positional, options,
8686
at::ARGUMENT_MODIFIER_NONE);
87+
at::add_image_id_option(options);
8788
at::add_snap_id_option(options);
8889
options->add_options()
8990
("all,a", po::bool_switch(), "list all children (include trash)");
@@ -104,14 +105,26 @@ int execute(const po::variables_map &vm,
104105
std::string namespace_name;
105106
std::string image_name;
106107
std::string snap_name;
108+
std::string image_id;
109+
110+
if (vm.count(at::IMAGE_ID)) {
111+
image_id = vm[at::IMAGE_ID].as<std::string>();
112+
}
113+
107114
int r = utils::get_pool_image_snapshot_names(
108115
vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, &pool_name, &namespace_name,
109-
&image_name, &snap_name, true, utils::SNAPSHOT_PRESENCE_PERMITTED,
110-
utils::SPEC_VALIDATION_NONE);
116+
&image_name, &snap_name, image_id.empty(),
117+
utils::SNAPSHOT_PRESENCE_PERMITTED, utils::SPEC_VALIDATION_NONE);
111118
if (r < 0) {
112119
return r;
113120
}
114121

122+
if (!image_id.empty() && !image_name.empty()) {
123+
std::cerr << "rbd: trying to access image using both name and id."
124+
<< std::endl;
125+
return -EINVAL;
126+
}
127+
115128
if (snap_id != LIBRADOS_SNAP_HEAD && !snap_name.empty()) {
116129
std::cerr << "rbd: trying to access snapshot using both name and id."
117130
<< std::endl;
@@ -127,8 +140,8 @@ int execute(const po::variables_map &vm,
127140
librados::Rados rados;
128141
librados::IoCtx io_ctx;
129142
librbd::Image image;
130-
r = utils::init_and_open_image(pool_name, namespace_name, image_name, "", "",
131-
true, &rados, &io_ctx, &image);
143+
r = utils::init_and_open_image(pool_name, namespace_name, image_name,
144+
image_id, "", true, &rados, &io_ctx, &image);
132145
if (r < 0) {
133146
return r;
134147
}

0 commit comments

Comments
 (0)