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
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
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
rbd help children
usage: rbd children [--pool <pool>] [--namespace <namespace>]
- [--image <image>] [--snap <snap>] [--snap-id <snap-id>]
- [--all] [--descendants] [--format <format>]
- [--pretty-format]
+ [--image <image>] [--snap <snap>] [--image-id <image-id>]
+ [--snap-id <snap-id>] [--all] [--descendants]
+ [--format <format>] [--pretty-format]
<image-or-snap-spec>
Display children of an image or its snapshot.
--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
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)");
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<std::string>();
+ }
+
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;
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;
}