]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: add sparse size support in rbd
authoryaoning <yaoning@unitedstack.com>
Thu, 19 Jan 2017 02:43:53 +0000 (10:43 +0800)
committerNing Yao <yaoning@unitedstack.com>
Tue, 4 Apr 2017 03:18:52 +0000 (03:18 +0000)
add --sparse_size in rbd command options
add calc_sparse_extent in rbd utils

Signed-off-by: yaoning <yaoning@unitedstack.com>
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

index 0f5ed40a2904caf779a152a9f57b2f5788a1e716..e9b716ad73605c2b12cecf7dd8fea225911e64a3 100644 (file)
                   [--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>] [--sparse-size <sparse-size>] 
+                  [--no-progress] 
                   <source-image-or-snap-spec> <dest-image-spec> 
   
   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
+    --sparse-size arg            sparse size in B/K/M [default: 4K]
     --no-progress                disable progress output
   
   Image Features:
                     [--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>] 
+                    [--sparse-size <sparse-size>] [--no-progress] 
                     [--export-format <export-format>] [--pool <pool>] 
                     [--image <image>] 
                     <path-name> <dest-image-spec> 
     --journal-splay-width arg number of active journal objects
     --journal-object-size arg size of journal objects
     --journal-pool arg        pool for journal objects
+    --sparse-size arg         sparse size in B/K/M [default: 4K]
     --no-progress             disable progress output
     --export-format arg       format of image file
     -p [ --pool ] arg         pool name (deprecated)
   
   rbd help import-diff
   usage: rbd import-diff [--path <path>] [--pool <pool>] [--image <image>] 
-                         [--no-progress] 
+                         [--sparse-size <sparse-size>] [--no-progress] 
                          <path-name> <image-spec> 
   
   Import an incremental diff.
     --path arg           import file (or '-' for stdin)
     -p [ --pool ] arg    pool name
     --image arg          image name
+    --sparse-size arg    sparse size in B/K/M [default: 4K]
     --no-progress        disable progress output
   
   rbd help info
index 9e11bdc77cf7dcdbabbb35d2ee5dffe9985ac394..b04fcc1da32bdb9fc73afec224f422c4d1d9a632 100644 (file)
@@ -293,6 +293,12 @@ void add_size_option(boost::program_options::options_description *opt) {
      "image size (in M/G/T)");
 }
 
+void add_sparse_size_option(boost::program_options::options_description *opt) {
+  opt->add_options()
+    (IMAGE_SPARSE_SIZE.c_str(), po::value<ImageObjectSize>(),
+    "sparse size in B/K/M [default: 4K]");
+}
+
 void add_path_options(boost::program_options::options_description *pos,
                       boost::program_options::options_description *opt,
                       const std::string &description) {
index b8e555a0b77031e1f36a6a45969fd5f6456188fa..d0ea09df900915b79261321e89730e953c8f684d 100644 (file)
@@ -70,6 +70,7 @@ 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 IMAGE_SPARSE_SIZE("sparse-size");
 
 static const std::string JOURNAL_OBJECT_SIZE("journal-object-size");
 static const std::string JOURNAL_SPLAY_WIDTH("journal-splay-width");
@@ -179,6 +180,8 @@ void add_create_journal_options(
 
 void add_size_option(boost::program_options::options_description *opt);
 
+void add_sparse_size_option(boost::program_options::options_description *opt);
+
 void add_path_options(boost::program_options::options_description *pos,
                       boost::program_options::options_description *opt,
                       const std::string &description);
index 99ffc8053c468f5ac0f2cac5c6bb5b6c49df1e72..53f6da334764a0e3f0fbfc84aaefac55dd219b04 100644 (file)
@@ -816,6 +816,36 @@ int snap_set(librbd::Image &image, const std::string &snap_name) {
   return 0;
 }
 
+bool calc_sparse_extent(const bufferptr &bp,
+                        size_t sparse_size,
+                        uint64_t length,
+                        size_t *write_offset,
+                        size_t *write_length,
+                        size_t *offset) {
+  size_t extent_size;
+  if (*offset + sparse_size > length) {
+    extent_size = length - *offset;
+  } else {
+    extent_size = sparse_size;
+  }
+
+  bufferptr extent(bp, *offset, extent_size);
+  *offset += extent_size;
+
+  bool extent_is_zero = extent.is_zero();
+  if (!extent_is_zero) {
+    *write_length += extent_size;
+  }
+  if (extent_is_zero &&  *write_length == 0) {
+    *write_offset += extent_size;
+  }
+
+  if ((extent_is_zero || *offset == length) && *write_length != 0) {
+    return true;
+  }
+  return false;
+}
+
 std::string image_id(librbd::Image& image) {
   std::string id;
   int r = image.get_id(&id);
index a718ded0bdedb7b2dcfd5ba4f0978a922bfc648f..0f72a40942c49c1e708ca81fcde777ed407deaed 100644 (file)
@@ -33,6 +33,7 @@ void aio_completion_callback(librbd::completion_t completion,
 } // namespace detail
 
 static const std::string RBD_DIFF_BANNER ("rbd diff v1\n");
+static const size_t RBD_DEFAULT_SPARSE_SIZE = 4096;
 
 static const std::string RBD_IMAGE_BANNER_V2 ("rbd image v2\n");
 static const std::string RBD_IMAGE_DIFFS_BANNER_V2 ("rbd image diffss v2\n");
@@ -167,6 +168,13 @@ int init_and_open_image(const std::string &pool_name,
 
 int snap_set(librbd::Image &image, const std::string &snap_name);
 
+bool calc_sparse_extent(const bufferptr &bp,
+                        size_t sparse_size,
+                        uint64_t length,
+                        size_t *write_offset,
+                        size_t *write_length,
+                        size_t *offset);
+
 std::string image_id(librbd::Image& image);
 
 std::string mirror_image_state(librbd::mirror_image_state_t mirror_image_state);