rbd help snap remove
usage: rbd snap remove [--pool <pool>] [--namespace <namespace>]
- [--image <image>] [--snap <snap>] [--no-progress]
- [--image-id <image-id>] [--force]
+ [--image <image>] [--snap <snap>]
+ [--image-id <image-id>] [--snap-id <snap-id>]
+ [--no-progress] [--force]
<snap-spec>
Delete a snapshot.
--namespace arg namespace name
--image arg image name
--snap arg snapshot name
- --no-progress disable progress output
--image-id arg image id
+ --snap-id arg snapshot id
+ --no-progress disable progress output
--force flatten children and unprotect snapshot if needed.
rbd help snap rename
void get_remove_arguments(po::options_description *positional,
po::options_description *options) {
at::add_snap_spec_options(positional, options, at::ARGUMENT_MODIFIER_NONE);
- at::add_no_progress_option(options);
at::add_image_id_option(options);
+ at::add_snap_id_option(options);
+ at::add_no_progress_option(options);
options->add_options()
("force", po::bool_switch(), "flatten children and unprotect snapshot if needed.");
std::string image_name;
std::string snap_name;
std::string image_id;
+ uint64_t snap_id = CEPH_NOSNAP;
bool force = vm["force"].as<bool>();
+ bool no_progress = vm[at::NO_PROGRESS].as<bool>();
if (vm.count(at::IMAGE_ID)) {
image_id = vm[at::IMAGE_ID].as<std::string>();
}
+ if (vm.count(at::SNAPSHOT_ID)) {
+ snap_id = vm[at::SNAPSHOT_ID].as<uint64_t>();
+ }
int r = utils::get_pool_image_snapshot_names(
vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, &pool_name, &namespace_name,
&image_name, &snap_name, image_id.empty(),
- utils::SNAPSHOT_PRESENCE_REQUIRED, utils::SPEC_VALIDATION_NONE);
+ (snap_id == CEPH_NOSNAP ? utils::SNAPSHOT_PRESENCE_REQUIRED :
+ 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::cerr << "rbd: trying to access image using both name and id."
<< std::endl;
return -EINVAL;
+ } else if (!snap_name.empty() && snap_id != CEPH_NOSNAP) {
+ std::cerr << "rbd: trying to access snapshot using both name and id."
+ << std::endl;
+ return -EINVAL;
+ } else if ((force || no_progress) && snap_id != CEPH_NOSNAP) {
+ std::cerr << "rbd: force and no-progress options not permitted when "
+ << "removing by id." << std::endl;
+ return -EINVAL;
}
librados::Rados rados;
return r;
}
- r = do_remove_snap(image, snap_name.c_str(), force, vm[at::NO_PROGRESS].as<bool>());
+ if (!snap_name.empty()) {
+ r = do_remove_snap(image, snap_name.c_str(), force, no_progress);
+ } else {
+ r = image.snap_remove_by_id(snap_id);
+ }
+
if (r < 0) {
if (r == -EBUSY) {
- std::cerr << "rbd: snapshot '" << snap_name << "' "
- << "is protected from removal." << std::endl;
+ std::cerr << "rbd: snapshot "
+ << (snap_name.empty() ? std::string("id ") + stringify(snap_id) :
+ std::string("'") + snap_name + "'")
+ << " is protected from removal." << std::endl;
} else {
std::cerr << "rbd: failed to remove snapshot: " << cpp_strerror(r)
<< std::endl;