]>
git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd/action/Remove.cc
b407534252b95d94b69cf428aad89e795cceeb21
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "tools/rbd/ArgumentTypes.h"
5 #include "tools/rbd/Shell.h"
6 #include "tools/rbd/Utils.h"
7 #include "common/errno.h"
9 #include <boost/program_options.hpp>
15 namespace at
= argument_types
;
16 namespace po
= boost::program_options
;
18 static int do_delete(librbd::RBD
&rbd
, librados::IoCtx
& io_ctx
,
19 const char *imgname
, bool no_progress
)
21 utils::ProgressContext
pc("Removing image", no_progress
);
22 int r
= rbd
.remove_with_progress(io_ctx
, imgname
, pc
);
31 void get_arguments(po::options_description
*positional
,
32 po::options_description
*options
) {
33 at::add_image_spec_options(positional
, options
, at::ARGUMENT_MODIFIER_NONE
);
34 at::add_no_progress_option(options
);
37 int execute(const po::variables_map
&vm
) {
39 std::string pool_name
;
40 std::string image_name
;
41 std::string snap_name
;
42 int r
= utils::get_pool_image_snapshot_names(
43 vm
, at::ARGUMENT_MODIFIER_NONE
, &arg_index
, &pool_name
, &image_name
,
44 &snap_name
, utils::SNAPSHOT_PRESENCE_NONE
, utils::SPEC_VALIDATION_NONE
);
49 librados::Rados rados
;
50 librados::IoCtx io_ctx
;
51 r
= utils::init(pool_name
, &rados
, &io_ctx
);
56 io_ctx
.set_osdmap_full_try();
59 r
= do_delete(rbd
, io_ctx
, image_name
.c_str(),
60 vm
[at::NO_PROGRESS
].as
<bool>());
62 if (r
== -ENOTEMPTY
) {
63 std::cerr
<< "rbd: image has snapshots - these must be deleted"
64 << " with 'rbd snap purge' before the image can be removed."
66 } else if (r
== -EBUSY
) {
67 std::cerr
<< "rbd: error: image still has watchers"
69 << "This means the image is still open or the client using "
70 << "it crashed. Try again after closing/unmapping it or "
71 << "waiting 30s for the crashed client to timeout."
73 } else if (r
== -EMLINK
) {
75 int image_r
= utils::open_image(io_ctx
, image_name
, true, &image
);
76 librbd::group_spec_t group_spec
;
78 image_r
= image
.get_group(&group_spec
);
81 std::cerr
<< "rbd: error: image belongs to a consistency group "
82 << group_spec
.pool
<< "." << group_spec
.name
;
84 std::cerr
<< "rbd: error: image belongs to a consistency group";
86 std::cerr
<< std::endl
87 << "Remove the image from the consistency group and try again."
91 std::cerr
<< "rbd: delete error: " << cpp_strerror(r
) << std::endl
;
99 {"remove"}, {"rm"}, "Delete an image.", "", &get_arguments
, &execute
);
101 } // namespace remove
102 } // namespace action