From f0d36b7a39b32601e25b932df02fa53552bef246 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Thu, 6 Oct 2016 14:31:27 -0400 Subject: [PATCH] rbd: support overriding image data pool when creating images Fixes: http://tracker.ceph.com/issues/17424 Signed-off-by: Jason Dillaman --- src/test/cli/rbd/help.t | 10 ++++++++-- src/tools/rbd/ArgumentTypes.cc | 3 ++- src/tools/rbd/ArgumentTypes.h | 1 + src/tools/rbd/Utils.cc | 20 +++++++++++++++++++- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/test/cli/rbd/help.t b/src/test/cli/rbd/help.t index 2af8912fa6363..ea9e6eeacad3a 100644 --- a/src/test/cli/rbd/help.t +++ b/src/test/cli/rbd/help.t @@ -145,6 +145,7 @@ [--object-size ] [--image-feature ] [--image-shared] [--stripe-unit ] [--stripe-count ] + [--data-pool ] [--journal-splay-width ] [--journal-object-size ] [--journal-pool ] @@ -174,6 +175,7 @@ --image-shared shared image --stripe-unit arg stripe unit --stripe-count arg stripe count + --data-pool arg data pool --journal-splay-width arg number of active journal objects --journal-object-size arg size of journal objects --journal-pool arg pool for journal objects @@ -189,6 +191,7 @@ [--object-size ] [--image-feature ] [--image-shared] [--stripe-unit ] [--stripe-count ] + [--data-pool ] [--journal-splay-width ] [--journal-object-size ] [--journal-pool ] [--no-progress] @@ -218,6 +221,7 @@ --image-shared shared image --stripe-unit arg stripe unit --stripe-count arg stripe count + --data-pool arg data pool --journal-splay-width arg number of active journal objects --journal-object-size arg size of journal objects --journal-pool arg pool for journal objects @@ -234,7 +238,7 @@ [--order ] [--object-size ] [--image-feature ] [--image-shared] [--stripe-unit ] - [--stripe-count ] + [--stripe-count ] [--data-pool ] [--journal-splay-width ] [--journal-object-size ] [--journal-pool ] --size @@ -261,6 +265,7 @@ --image-shared shared image --stripe-unit arg stripe unit --stripe-count arg stripe count + --data-pool arg data pool --journal-splay-width arg number of active journal objects --journal-object-size arg size of journal objects --journal-pool arg pool for journal objects @@ -576,7 +581,7 @@ [--order ] [--object-size ] [--image-feature ] [--image-shared] [--stripe-unit ] - [--stripe-count ] + [--stripe-count ] [--data-pool ] [--journal-splay-width ] [--journal-object-size ] [--journal-pool ] [--no-progress] @@ -606,6 +611,7 @@ --image-shared shared image --stripe-unit arg stripe unit --stripe-count arg stripe count + --data-pool arg data pool --journal-splay-width arg number of active journal objects --journal-object-size arg size of journal objects --journal-pool arg pool for journal objects diff --git a/src/tools/rbd/ArgumentTypes.cc b/src/tools/rbd/ArgumentTypes.cc index 910aef041fa18..9ec3ec8a3f8bf 100644 --- a/src/tools/rbd/ArgumentTypes.cc +++ b/src/tools/rbd/ArgumentTypes.cc @@ -268,7 +268,8 @@ void add_create_image_options(po::options_description *opt, ("image features\n" + get_short_features_help(true)).c_str()) (IMAGE_SHARED.c_str(), po::bool_switch(), "shared image") (IMAGE_STRIPE_UNIT.c_str(), po::value(), "stripe unit") - (IMAGE_STRIPE_COUNT.c_str(), po::value(), "stripe count"); + (IMAGE_STRIPE_COUNT.c_str(), po::value(), "stripe count") + (IMAGE_DATA_POOL.c_str(), po::value(), "data pool"); add_create_journal_options(opt); } diff --git a/src/tools/rbd/ArgumentTypes.h b/src/tools/rbd/ArgumentTypes.h index 016a91bf5ea38..325b0418b659c 100644 --- a/src/tools/rbd/ArgumentTypes.h +++ b/src/tools/rbd/ArgumentTypes.h @@ -69,6 +69,7 @@ static const std::string IMAGE_SHARED("image-shared"); static const std::string IMAGE_SIZE("size"); static const std::string IMAGE_STRIPE_UNIT("stripe-unit"); static const std::string IMAGE_STRIPE_COUNT("stripe-count"); +static const std::string IMAGE_DATA_POOL("data-pool"); static const std::string JOURNAL_OBJECT_SIZE("journal-object-size"); static const std::string JOURNAL_SPLAY_WIDTH("journal-splay-width"); diff --git a/src/tools/rbd/Utils.cc b/src/tools/rbd/Utils.cc index e5c8fc6bd47ac..679de96964cc6 100644 --- a/src/tools/rbd/Utils.cc +++ b/src/tools/rbd/Utils.cc @@ -519,6 +519,7 @@ int get_image_options(const boost::program_options::variables_map &vm, bool get_format, librbd::ImageOptions *opts) { uint64_t order = 0, stripe_unit = 0, stripe_count = 0, object_size = 0; uint64_t features = 0, features_clear = 0, features_set = 0; + std::string data_pool; bool order_specified = true; bool features_specified = false; bool features_clear_specified = false; @@ -560,6 +561,10 @@ int get_image_options(const boost::program_options::variables_map &vm, } } + if (vm.count(at::IMAGE_DATA_POOL)) { + data_pool = vm[at::IMAGE_DATA_POOL].as(); + } + if (get_format) { uint64_t format = 0; bool format_specified = false; @@ -597,6 +602,17 @@ int get_image_options(const boost::program_options::variables_map &vm, } } + if (!data_pool.empty()) { + if (format_specified && format == 1) { + std::cerr << "rbd: data pool not allowed with format 1; " + << "use --image-format 2" << std::endl; + return -EINVAL; + } else { + format = 2; + format_specified = true; + } + } + if (format_specified) { int r = g_conf->set_val("rbd_default_format", stringify(format)); assert(r == 0); @@ -617,7 +633,9 @@ int get_image_options(const boost::program_options::variables_map &vm, opts->set(RBD_IMAGE_OPTION_STRIPE_UNIT, stripe_unit); opts->set(RBD_IMAGE_OPTION_STRIPE_COUNT, stripe_count); } - + if (!data_pool.empty()) { + opts->set(RBD_IMAGE_OPTION_DATA_POOL, data_pool); + } int r = get_journal_options(vm, opts); if (r < 0) { return r; -- 2.39.5