From: Jason Dillaman Date: Tue, 21 Apr 2020 00:37:56 +0000 (-0400) Subject: rbd: add '--mirror-image-mode' optional to image creation actions X-Git-Tag: v16.1.0~2505^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6da56d798248369f15191d8d5ec3b093f8dca831;p=ceph.git rbd: add '--mirror-image-mode' optional to image creation actions This allows the user to enable mirroring while creating, cloning, copying, importing, or migrating an image. Signed-off-by: Jason Dillaman --- diff --git a/src/test/cli/rbd/help.t b/src/test/cli/rbd/help.t index 1f9aff38fb95..fc2bc57749cf 100644 --- a/src/test/cli/rbd/help.t +++ b/src/test/cli/rbd/help.t @@ -218,6 +218,7 @@ [--image-feature ] [--image-shared] [--stripe-unit ] [--stripe-count ] [--data-pool ] + [--mirror-image-mode ] [--journal-splay-width ] [--journal-object-size ] [--journal-pool ] @@ -249,6 +250,7 @@ --stripe-unit arg stripe unit in B/K/M --stripe-count arg stripe count --data-pool arg data pool + --mirror-image-mode arg mirror image mode [journal or snapshot] --journal-splay-width arg number of active journal objects --journal-object-size arg size of journal objects [4K <= size <= 64M] --journal-pool arg pool for journal objects @@ -419,6 +421,7 @@ [--image-feature ] [--image-shared] [--stripe-unit ] [--stripe-count ] [--data-pool ] + [--mirror-image-mode ] [--journal-splay-width ] [--journal-object-size ] [--journal-pool ] [--sparse-size ] @@ -452,6 +455,7 @@ --stripe-unit arg stripe unit in B/K/M --stripe-count arg stripe count --data-pool arg data pool + --mirror-image-mode arg mirror image mode [journal or snapshot] --journal-splay-width arg number of active journal objects --journal-object-size arg size of journal objects [4K <= size <= 64M] --journal-pool arg pool for journal objects @@ -470,6 +474,7 @@ [--image-feature ] [--image-shared] [--stripe-unit ] [--stripe-count ] [--data-pool ] + [--mirror-image-mode ] [--journal-splay-width ] [--journal-object-size ] [--journal-pool ] @@ -495,6 +500,7 @@ --stripe-unit arg stripe unit in B/K/M --stripe-count arg stripe count --data-pool arg data pool + --mirror-image-mode arg mirror image mode [journal or snapshot] --journal-splay-width arg number of active journal objects --journal-object-size arg size of journal objects [4K <= size <= 64M] --journal-pool arg pool for journal objects @@ -516,6 +522,7 @@ [--image-feature ] [--image-shared] [--stripe-unit ] [--stripe-count ] [--data-pool ] + [--mirror-image-mode ] [--journal-splay-width ] [--journal-object-size ] [--journal-pool ] [--flatten] @@ -549,6 +556,7 @@ --stripe-unit arg stripe unit in B/K/M --stripe-count arg stripe count --data-pool arg data pool + --mirror-image-mode arg mirror image mode [journal or snapshot] --journal-splay-width arg number of active journal objects --journal-object-size arg size of journal objects [4K <= size <= 64M] --journal-pool arg pool for journal objects @@ -1091,6 +1099,7 @@ [--image-feature ] [--image-shared] [--stripe-unit ] [--stripe-count ] [--data-pool ] + [--mirror-image-mode ] [--journal-splay-width ] [--journal-object-size ] [--journal-pool ] @@ -1120,6 +1129,7 @@ --stripe-unit arg stripe unit in B/K/M --stripe-count arg stripe count --data-pool arg data pool + --mirror-image-mode arg mirror image mode [journal or snapshot] --journal-splay-width arg number of active journal objects --journal-object-size arg size of journal objects [4K <= size <= 64M] --journal-pool arg pool for journal objects @@ -1464,6 +1474,7 @@ [--image-shared] [--stripe-unit ] [--stripe-count ] [--data-pool ] + [--mirror-image-mode ] [--journal-splay-width ] [--journal-object-size ] [--journal-pool ] [--flatten] @@ -1493,6 +1504,7 @@ --stripe-unit arg stripe unit in B/K/M --stripe-count arg stripe count --data-pool arg data pool + --mirror-image-mode arg mirror image mode [journal or snapshot] --journal-splay-width arg number of active journal objects --journal-object-size arg size of journal objects [4K <= size <= 64M] --journal-pool arg pool for journal objects diff --git a/src/tools/rbd/ArgumentTypes.cc b/src/tools/rbd/ArgumentTypes.cc index e21c60aa3f7d..74a460fcf1e8 100644 --- a/src/tools/rbd/ArgumentTypes.cc +++ b/src/tools/rbd/ArgumentTypes.cc @@ -243,7 +243,9 @@ void add_create_image_options(po::options_description *opt, (IMAGE_SHARED.c_str(), po::bool_switch(), "shared image") (IMAGE_STRIPE_UNIT.c_str(), po::value(), "stripe unit in B/K/M") (IMAGE_STRIPE_COUNT.c_str(), po::value(), "stripe count") - (IMAGE_DATA_POOL.c_str(), po::value(), "data pool"); + (IMAGE_DATA_POOL.c_str(), po::value(), "data pool") + (IMAGE_MIRROR_IMAGE_MODE.c_str(), po::value(), + "mirror image mode [journal or snapshot]"); add_create_journal_options(opt); } @@ -461,6 +463,19 @@ void validate(boost::any& v, const std::vector& values, } } +void validate(boost::any& v, const std::vector& values, + MirrorImageMode* mirror_image_mode, int) { + po::validators::check_first_occurrence(v); + const std::string &s = po::validators::get_single_string(values); + if (s == "journal") { + v = boost::any(RBD_MIRROR_IMAGE_MODE_JOURNAL); + } else if (s == "snapshot") { + v = boost::any(RBD_MIRROR_IMAGE_MODE_SNAPSHOT); + } else { + throw po::validation_error(po::validation_error::invalid_option_value); + } +} + void validate(boost::any& v, const std::vector& values, Format *target_type, int) { po::validators::check_first_occurrence(v); diff --git a/src/tools/rbd/ArgumentTypes.h b/src/tools/rbd/ArgumentTypes.h index 23bb02b9cd0c..0554acceee96 100644 --- a/src/tools/rbd/ArgumentTypes.h +++ b/src/tools/rbd/ArgumentTypes.h @@ -69,6 +69,7 @@ static const std::string IMAGE_DATA_POOL("data-pool"); static const std::string IMAGE_SPARSE_SIZE("sparse-size"); static const std::string IMAGE_THICK_PROVISION("thick-provision"); static const std::string IMAGE_FLATTEN("flatten"); +static const std::string IMAGE_MIRROR_IMAGE_MODE("mirror-image-mode"); static const std::string JOURNAL_OBJECT_SIZE("journal-object-size"); static const std::string JOURNAL_SPLAY_WIDTH("journal-splay-width"); @@ -97,6 +98,8 @@ struct ImageFeatures { uint64_t features; }; +struct MirrorImageMode {}; + template struct TypedValue { T value; diff --git a/src/tools/rbd/Utils.cc b/src/tools/rbd/Utils.cc index f02adb8a32ee..7698dae9a634 100644 --- a/src/tools/rbd/Utils.cc +++ b/src/tools/rbd/Utils.cc @@ -555,6 +555,11 @@ int get_image_options(const boost::program_options::variables_map &vm, return r; } + if (vm.count(at::IMAGE_MIRROR_IMAGE_MODE)) { + opts->set(RBD_IMAGE_OPTION_MIRROR_IMAGE_MODE, + vm[at::IMAGE_MIRROR_IMAGE_MODE].as()); + } + return 0; }