From e387f9195545522351306ce420bd758b888dc774 Mon Sep 17 00:00:00 2001 From: Mykola Golub Date: Thu, 26 Apr 2018 00:02:57 +0300 Subject: [PATCH] rbd: deep copy option to copy clone parent data Signed-off-by: Mykola Golub --- qa/workunits/rbd/cli_generic.sh | 17 +++++++++++++++++ src/test/cli/rbd/help.t | 4 +++- src/tools/rbd/ArgumentTypes.cc | 6 ++++++ src/tools/rbd/ArgumentTypes.h | 3 +++ src/tools/rbd/Utils.cc | 14 ++++++++++++++ src/tools/rbd/Utils.h | 3 +++ src/tools/rbd/action/Copy.cc | 1 + 7 files changed, 47 insertions(+), 1 deletion(-) diff --git a/qa/workunits/rbd/cli_generic.sh b/qa/workunits/rbd/cli_generic.sh index 17d1aea8c6a69..2447848a0c6de 100755 --- a/qa/workunits/rbd/cli_generic.sh +++ b/qa/workunits/rbd/cli_generic.sh @@ -496,6 +496,7 @@ test_deep_copy_clone() { rbd snap create testimg2@snap2 rbd deep copy testimg2 testimg3 rbd info testimg3 | grep 'size 256MiB' + rbd info testimg3 | grep 'parent: rbd/testimg1@snap1' rbd snap ls testimg3 | grep -v 'SNAPID' | wc -l | grep 1 rbd snap ls testimg3 | grep '.*snap2.*' rbd info testimg2 | grep 'features:.*deep-flatten' || rbd snap rm testimg2@snap2 @@ -503,6 +504,22 @@ test_deep_copy_clone() { rbd flatten testimg2 rbd flatten testimg3 rbd snap unprotect testimg1@snap1 + rbd snap purge testimg2 + rbd snap purge testimg3 + rbd rm testimg2 + rbd rm testimg3 + + rbd snap protect testimg1@snap1 + rbd clone testimg1@snap1 testimg2 + rbd snap create testimg2@snap2 + rbd deep copy --flatten testimg2 testimg3 + rbd info testimg3 | grep 'size 256MiB' + rbd info testimg3 | grep -v 'parent:' + rbd snap ls testimg3 | grep -v 'SNAPID' | wc -l | grep 1 + rbd snap ls testimg3 | grep '.*snap2.*' + rbd info testimg2 | grep 'features:.*deep-flatten' || rbd snap rm testimg2@snap2 + rbd flatten testimg2 + rbd snap unprotect testimg1@snap1 remove_images } diff --git a/src/test/cli/rbd/help.t b/src/test/cli/rbd/help.t index bce34fcd855a6..c791ef12cb3bb 100644 --- a/src/test/cli/rbd/help.t +++ b/src/test/cli/rbd/help.t @@ -312,7 +312,8 @@ [--stripe-count ] [--data-pool ] [--journal-splay-width ] [--journal-object-size ] - [--journal-pool ] [--no-progress] + [--journal-pool ] [--flatten] + [--no-progress] Deep copy src image to dest. @@ -343,6 +344,7 @@ --journal-splay-width arg number of active journal objects --journal-object-size arg size of journal objects --journal-pool arg pool for journal objects + --flatten fill clone with parent data (make it independent) --no-progress disable progress output Image Features: diff --git a/src/tools/rbd/ArgumentTypes.cc b/src/tools/rbd/ArgumentTypes.cc index 2f44ede7befec..1ccabc431017a 100644 --- a/src/tools/rbd/ArgumentTypes.cc +++ b/src/tools/rbd/ArgumentTypes.cc @@ -367,6 +367,12 @@ void add_export_format_option(boost::program_options::options_description *opt) ("export-format", po::value(), "format of image file"); } +void add_flatten_option(boost::program_options::options_description *opt) { + opt->add_options() + (IMAGE_FLATTEN.c_str(), po::bool_switch(), + "fill clone with parent data (make it independent)"); +} + std::string get_short_features_help(bool append_suffix) { std::ostringstream oss; bool first_feature = true; diff --git a/src/tools/rbd/ArgumentTypes.h b/src/tools/rbd/ArgumentTypes.h index c97edbddb65a3..887ae78166127 100644 --- a/src/tools/rbd/ArgumentTypes.h +++ b/src/tools/rbd/ArgumentTypes.h @@ -73,6 +73,7 @@ static const std::string IMAGE_STRIPE_COUNT("stripe-count"); 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 JOURNAL_OBJECT_SIZE("journal-object-size"); static const std::string JOURNAL_SPLAY_WIDTH("journal-splay-width"); @@ -205,6 +206,8 @@ void add_verbose_option(boost::program_options::options_description *opt); void add_no_error_option(boost::program_options::options_description *opt); +void add_flatten_option(boost::program_options::options_description *opt); + std::string get_short_features_help(bool append_suffix); std::string get_long_features_help(); diff --git a/src/tools/rbd/Utils.cc b/src/tools/rbd/Utils.cc index 334156721c2c6..17039114fb736 100644 --- a/src/tools/rbd/Utils.cc +++ b/src/tools/rbd/Utils.cc @@ -773,6 +773,11 @@ int get_image_options(const boost::program_options::variables_map &vm, return r; } + r = get_flatten_option(vm, opts); + if (r < 0) { + return r; + } + return 0; } @@ -811,6 +816,15 @@ int get_journal_options(const boost::program_options::variables_map &vm, return 0; } +int get_flatten_option(const boost::program_options::variables_map &vm, + librbd::ImageOptions *opts) { + if (vm.count(at::IMAGE_FLATTEN) && vm[at::IMAGE_FLATTEN].as()) { + uint64_t flatten = 1; + opts->set(RBD_IMAGE_OPTION_FLATTEN, flatten); + } + return 0; +} + int get_image_size(const boost::program_options::variables_map &vm, uint64_t *size) { if (vm.count(at::IMAGE_SIZE) == 0) { diff --git a/src/tools/rbd/Utils.h b/src/tools/rbd/Utils.h index 9822a8856ecbb..b1b606397a4c5 100644 --- a/src/tools/rbd/Utils.h +++ b/src/tools/rbd/Utils.h @@ -161,6 +161,9 @@ int get_image_options(const boost::program_options::variables_map &vm, int get_journal_options(const boost::program_options::variables_map &vm, librbd::ImageOptions *opts); +int get_flatten_option(const boost::program_options::variables_map &vm, + librbd::ImageOptions *opts); + int get_image_size(const boost::program_options::variables_map &vm, uint64_t *size); diff --git a/src/tools/rbd/action/Copy.cc b/src/tools/rbd/action/Copy.cc index cad4c980ab54e..96d63f2a31daf 100644 --- a/src/tools/rbd/action/Copy.cc +++ b/src/tools/rbd/action/Copy.cc @@ -122,6 +122,7 @@ void get_arguments_deep(po::options_description *positional, at::ARGUMENT_MODIFIER_SOURCE); at::add_image_spec_options(positional, options, at::ARGUMENT_MODIFIER_DEST); at::add_create_image_options(options, false); + at::add_flatten_option(options); at::add_no_progress_option(options); } -- 2.39.5