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_rename(librbd::RBD
&rbd
, librados::IoCtx
& io_ctx
,
19 const char *imgname
, const char *destname
)
21 int r
= rbd
.rename(io_ctx
, imgname
, destname
);
27 void get_arguments(po::options_description
*positional
,
28 po::options_description
*options
) {
29 at::add_image_spec_options(positional
, options
, at::ARGUMENT_MODIFIER_SOURCE
);
30 at::add_image_spec_options(positional
, options
, at::ARGUMENT_MODIFIER_DEST
);
33 int execute(const po::variables_map
&vm
,
34 const std::vector
<std::string
> &ceph_global_init_args
) {
36 std::string pool_name
;
37 std::string namespace_name
;
38 std::string image_name
;
39 std::string snap_name
;
40 int r
= utils::get_pool_image_snapshot_names(
41 vm
, at::ARGUMENT_MODIFIER_SOURCE
, &arg_index
, &pool_name
, &namespace_name
,
42 &image_name
, &snap_name
, true, utils::SNAPSHOT_PRESENCE_NONE
,
43 utils::SPEC_VALIDATION_NONE
);
48 std::string dst_image_name
;
49 std::string dst_snap_name
;
50 std::string dst_pool_name
= pool_name
;
51 std::string dst_namespace_name
= namespace_name
;
52 r
= utils::get_pool_image_snapshot_names(
53 vm
, at::ARGUMENT_MODIFIER_DEST
, &arg_index
, &dst_pool_name
,
54 &dst_namespace_name
, &dst_image_name
, &dst_snap_name
, true,
55 utils::SNAPSHOT_PRESENCE_NONE
, utils::SPEC_VALIDATION_FULL
);
60 if (pool_name
!= dst_pool_name
) {
61 std::cerr
<< "rbd: mv/rename across pools not supported" << std::endl
62 << "source pool: " << pool_name
<< " dest pool: " << dst_pool_name
65 } else if (namespace_name
!= dst_namespace_name
) {
66 std::cerr
<< "rbd: mv/rename across namespaces not supported" << std::endl
67 << "source namespace: " << namespace_name
<< " dest namespace: "
68 << dst_namespace_name
<< std::endl
;
72 librados::Rados rados
;
73 librados::IoCtx io_ctx
;
74 r
= utils::init(pool_name
, namespace_name
, &rados
, &io_ctx
);
80 r
= do_rename(rbd
, io_ctx
, image_name
.c_str(), dst_image_name
.c_str());
82 std::cerr
<< "rbd: rename error: " << cpp_strerror(r
) << std::endl
;
89 {"rename"}, {"mv"}, "Rename image within pool.", "", &get_arguments
,