]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: deep copy option to copy clone parent data 21624/head
authorMykola Golub <mgolub@suse.com>
Wed, 25 Apr 2018 21:02:57 +0000 (00:02 +0300)
committerMykola Golub <mgolub@suse.com>
Wed, 16 May 2018 13:07:48 +0000 (16:07 +0300)
Signed-off-by: Mykola Golub <mgolub@suse.com>
qa/workunits/rbd/cli_generic.sh
src/test/cli/rbd/help.t
src/tools/rbd/ArgumentTypes.cc
src/tools/rbd/ArgumentTypes.h
src/tools/rbd/Utils.cc
src/tools/rbd/Utils.h
src/tools/rbd/action/Copy.cc

index 17d1aea8c6a6998ae033bdc79cf8fcbbfcf8bb9d..2447848a0c6de244e9245157644c362c533f43d5 100755 (executable)
@@ -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
 }
index bce34fcd855a6275fc18f6f87acc0d32026bf14f..c791ef12cb3bb93a6494cc5f8e67b2a1de888b62 100644 (file)
                        [--stripe-count <stripe-count>] [--data-pool <data-pool>] 
                        [--journal-splay-width <journal-splay-width>] 
                        [--journal-object-size <journal-object-size>] 
-                       [--journal-pool <journal-pool>] [--no-progress] 
+                       [--journal-pool <journal-pool>] [--flatten] 
+                       [--no-progress] 
                        <source-image-or-snap-spec> <dest-image-spec> 
   
   Deep copy src image to dest.
     --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:
index 2f44ede7befec5a102fe5eb295413360844cf740..1ccabc431017adf389b0fa1a91cc504b472e5bbb 100644 (file)
@@ -367,6 +367,12 @@ void add_export_format_option(boost::program_options::options_description *opt)
     ("export-format", po::value<ExportFormat>(), "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;
index c97edbddb65a3f1aced024f4b63ca98c8f4bdef0..887ae78166127f2a95a29315f226a5ed4204167a 100644 (file)
@@ -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();
 
index 334156721c2c63dfa85644c32ef1b6b42b959e78..17039114fb7368b8df2b4da811288ae3b0ffd568 100644 (file)
@@ -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<bool>()) {
+    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) {
index 9822a8856ecbb82dd79564129bce32681fdcec3b..b1b606397a4c5b73d4ff16da7aea115a7f3a20ec 100644 (file)
@@ -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);
 
index cad4c980ab54e401faeea4b0ff83ed517aacc980..96d63f2a31dafd4cc19f9e5df15034a090ae9bf1 100644 (file)
@@ -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);
 }