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: v15.2.2~44^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d7e7b630e02e6fa92f61452fd9ad20b8ef9d5f82;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 (cherry picked from commit 6da56d798248369f15191d8d5ec3b093f8dca831) --- diff --git a/src/test/cli/rbd/help.t b/src/test/cli/rbd/help.t index fe3d4dc3efb1..e6f1ee869d15 100644 --- a/src/test/cli/rbd/help.t +++ b/src/test/cli/rbd/help.t @@ -220,6 +220,7 @@ [--image-feature ] [--image-shared] [--stripe-unit ] [--stripe-count ] [--data-pool ] + [--mirror-image-mode ] [--journal-splay-width ] [--journal-object-size ] [--journal-pool ] @@ -252,6 +253,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 @@ -422,6 +424,7 @@ [--image-feature ] [--image-shared] [--stripe-unit ] [--stripe-count ] [--data-pool ] + [--mirror-image-mode ] [--journal-splay-width ] [--journal-object-size ] [--journal-pool ] [--sparse-size ] @@ -456,6 +459,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 @@ -474,6 +478,7 @@ [--image-feature ] [--image-shared] [--stripe-unit ] [--stripe-count ] [--data-pool ] + [--mirror-image-mode ] [--journal-splay-width ] [--journal-object-size ] [--journal-pool ] @@ -502,6 +507,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 @@ -523,6 +529,7 @@ [--image-feature ] [--image-shared] [--stripe-unit ] [--stripe-count ] [--data-pool ] + [--mirror-image-mode ] [--journal-splay-width ] [--journal-object-size ] [--journal-pool ] [--flatten] @@ -557,6 +564,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 @@ -1099,6 +1107,7 @@ [--image-feature ] [--image-shared] [--stripe-unit ] [--stripe-count ] [--data-pool ] + [--mirror-image-mode ] [--journal-splay-width ] [--journal-object-size ] [--journal-pool ] @@ -1131,6 +1140,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 @@ -1477,6 +1487,7 @@ [--image-shared] [--stripe-unit ] [--stripe-count ] [--data-pool ] + [--mirror-image-mode ] [--journal-splay-width ] [--journal-object-size ] [--journal-pool ] [--flatten] @@ -1509,6 +1520,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 74115d8a30aa..cf64f9abe018 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); } @@ -463,6 +465,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 520b654714b8..903e35ca755f 100644 --- a/src/tools/rbd/Utils.cc +++ b/src/tools/rbd/Utils.cc @@ -557,6 +557,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; }