]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: use macro for rbd diff tags
authorDongsheng Yang <dongsheng.yang@easystack.cn>
Wed, 6 Jul 2016 09:24:57 +0000 (05:24 -0400)
committerDongsheng Yang <dongsheng.yang@easystack.cn>
Sun, 19 Feb 2017 12:41:28 +0000 (20:41 +0800)
Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
src/tools/rbd/Utils.h
src/tools/rbd/action/ExportDiff.cc
src/tools/rbd/action/ImportDiff.cc
src/tools/rbd/action/MergeDiff.cc

index aa75e06cddc5d40cc5a33820575e34f8781fd93d..b13e555a8c16bbae1371a6efc0154abdf4f136a3 100644 (file)
@@ -16,6 +16,13 @@ namespace utils {
 
 static const std::string RBD_DIFF_BANNER ("rbd diff v1\n");
 
+#define RBD_DIFF_FROM_SNAP     'f'
+#define RBD_DIFF_TO_SNAP       't'
+#define RBD_DIFF_IMAGE_SIZE    's'
+#define RBD_DIFF_WRITE         'w'
+#define RBD_DIFF_ZERO          'z'
+#define RBD_DIFF_END           'e'
+
 enum SnapshotPresence {
   SNAPSHOT_PRESENCE_NONE,
   SNAPSHOT_PRESENCE_PERMITTED,
index df74eab32d3868af1a2e9220736c9e35aa12309f..8047b9a43dd786f1d514d1b624135c6d19c21486 100644 (file)
@@ -98,7 +98,7 @@ private:
                           uint64_t length, bool exists) {
     // extent
     bufferlist bl;
-    __u8 tag = exists ? 'w' : 'z';
+    __u8 tag = exists ? RBD_DIFF_WRITE : RBD_DIFF_ZERO;
     ::encode(tag, bl);
     ::encode(offset, bl);
     ::encode(length, bl);
@@ -142,20 +142,20 @@ static int do_export_diff(librbd::Image& image, const char *fromsnapname,
 
     __u8 tag;
     if (fromsnapname) {
-      tag = 'f';
+      tag = RBD_DIFF_FROM_SNAP;
       ::encode(tag, bl);
       std::string from(fromsnapname);
       ::encode(from, bl);
     }
 
     if (endsnapname) {
-      tag = 't';
+      tag = RBD_DIFF_TO_SNAP;
       ::encode(tag, bl);
       std::string to(endsnapname);
       ::encode(to, bl);
     }
 
-    tag = 's';
+    tag = RBD_DIFF_IMAGE_SIZE;
     ::encode(tag, bl);
     uint64_t endsize = info.size;
     ::encode(endsize, bl);
@@ -179,7 +179,7 @@ static int do_export_diff(librbd::Image& image, const char *fromsnapname,
   }
 
   {
-    __u8 tag = 'e';
+    __u8 tag = RBD_DIFF_END;
     bufferlist bl;
     ::encode(tag, bl);
     r = bl.write_fd(fd);
index 88032c74566b4264fd1fc500e16a7d878b0e7d6e..c9a6b5ee117a0855baef1ee2710e71ef255fb781 100644 (file)
@@ -67,10 +67,10 @@ static int do_import_diff(librbd::Image &image, const char *path,
       goto done;
     }
 
-    if (tag == 'e') {
+    if (tag == RBD_DIFF_END) {
       dout(2) << " end diff" << dendl;
       break;
-    } else if (tag == 'f') {
+    } else if (tag == RBD_DIFF_FROM_SNAP) {
       r = utils::read_string(fd, 4096, &from);   // 4k limit to make sure we don't get a garbage string
       if (r < 0)
         goto done;
@@ -88,7 +88,7 @@ static int do_import_diff(librbd::Image &image, const char *path,
         goto done;
       }
     }
-    else if (tag == 't') {
+    else if (tag == RBD_DIFF_TO_SNAP) {
       r = utils::read_string(fd, 4096, &to);   // 4k limit to make sure we don't get a garbage string
       if (r < 0)
         goto done;
@@ -106,7 +106,7 @@ static int do_import_diff(librbd::Image &image, const char *path,
         r = -EEXIST;
         goto done;
       }
-    } else if (tag == 's') {
+    } else if (tag == RBD_DIFF_IMAGE_SIZE) {
       uint64_t end_size;
       char buf[8];
       r = safe_read_exact(fd, buf, 8);
@@ -126,7 +126,7 @@ static int do_import_diff(librbd::Image &image, const char *path,
       }
       if (from_stdin)
         size = end_size;
-    } else if (tag == 'w' || tag == 'z') {
+    } else if (tag == RBD_DIFF_WRITE || tag == RBD_DIFF_ZERO) {
       uint64_t len;
       char buf[16];
       r = safe_read_exact(fd, buf, 16);
@@ -138,7 +138,7 @@ static int do_import_diff(librbd::Image &image, const char *path,
       ::decode(off, p);
       ::decode(len, p);
 
-      if (tag == 'w') {
+      if (tag == RBD_DIFF_WRITE) {
         bufferptr bp = buffer::create(len);
         r = safe_read_exact(fd, bp.c_str(), len);
         if (r < 0)
index c28cb1d266ccf37165294a4da7617e7bd892c4b9..5c31769d0c4080965c7fcf4593ce6120bddaf032 100644 (file)
@@ -48,17 +48,17 @@ static int parse_diff_header(int fd, __u8 *tag, string *from, string *to, uint64
     if (r < 0)
       return r;
 
-    if (*tag == 'f') {
+    if (*tag == RBD_DIFF_FROM_SNAP) {
       r = utils::read_string(fd, 4096, from);   // 4k limit to make sure we don't get a garbage string
       if (r < 0)
         return r;
       dout(2) << " from snap " << *from << dendl;
-    } else if (*tag == 't') {
+    } else if (*tag == RBD_DIFF_TO_SNAP) {
       r = utils::read_string(fd, 4096, to);   // 4k limit to make sure we don't get a garbage string
       if (r < 0)
         return r;
       dout(2) << " to snap " << *to << dendl;
-    } else if (*tag == 's') {
+    } else if (*tag == RBD_DIFF_IMAGE_SIZE) {
       char buf[8];
       r = safe_read_exact(fd, buf, 8);
       if (r < 0)
@@ -86,13 +86,13 @@ static int parse_diff_body(int fd, __u8 *tag, uint64_t *offset, uint64_t *length
       return r;
   }
 
-  if (*tag == 'e') {
+  if (*tag == RBD_DIFF_END) {
     offset = 0;
     length = 0;
     return 0;
   }
 
-  if (*tag != 'w' && *tag != 'z')
+  if (*tag != RBD_DIFF_WRITE && *tag != RBD_DIFF_ZERO)
     return -ENOTSUP;
 
   char buf[16];
@@ -118,7 +118,7 @@ static int parse_diff_body(int fd, __u8 *tag, uint64_t *offset, uint64_t *length
  */
 static int accept_diff_body(int fd, int pd, __u8 tag, uint64_t offset, uint64_t length)
 {
-  if (tag == 'e')
+  if (tag == RBD_DIFF_END)
     return 0;
 
   bufferlist bl;
@@ -130,7 +130,7 @@ static int accept_diff_body(int fd, int pd, __u8 tag, uint64_t offset, uint64_t
   if (r < 0)
     return r;
 
-  if (tag == 'w') {
+  if (tag == RBD_DIFF_WRITE) {
     bufferptr bp = buffer::create(length);
     r = safe_read_exact(fd, bp.c_str(), length);
     if (r < 0)
@@ -227,18 +227,18 @@ static int do_merge_diff(const char *first, const char *second,
 
     __u8 tag;
     if (f_from.size()) {
-      tag = 'f';
+      tag = RBD_DIFF_FROM_SNAP;
       ::encode(tag, bl);
       ::encode(f_from, bl);
     }
 
     if (s_to.size()) {
-      tag = 't';
+      tag = RBD_DIFF_TO_SNAP;
       ::encode(tag, bl);
       ::encode(s_to, bl);
     }
 
-    tag = 's';
+    tag = RBD_DIFF_IMAGE_SIZE;
     ::encode(tag, bl);
     ::encode(s_size, bl);
 
@@ -271,9 +271,9 @@ static int do_merge_diff(const char *first, const char *second,
         goto done;
       }
 
-      if (f_tag == 'e') {
+      if (f_tag == RBD_DIFF_END) {
         f_end = true;
-        f_tag = 'z';
+        f_tag = RBD_DIFF_ZERO;
         f_off = f_size;
         if (f_size < s_size)
           f_len = s_size - f_size;
@@ -302,7 +302,7 @@ static int do_merge_diff(const char *first, const char *second,
         goto done;
       }
 
-      if (s_tag == 'e') {
+      if (s_tag == RBD_DIFF_END) {
         s_end = true;
         s_off = s_size;
         if (s_size < f_size)
@@ -342,7 +342,7 @@ static int do_merge_diff(const char *first, const char *second,
       uint64_t delta = s_off + s_len - f_off;
       if (delta > f_len)
         delta = f_len;
-      if (f_tag == 'w') {
+      if (f_tag == RBD_DIFF_WRITE) {
         if (first_stdin) {
           bufferptr bp = buffer::create(delta);
           r = safe_read_exact(fd, bp.c_str(), delta);
@@ -380,7 +380,7 @@ static int do_merge_diff(const char *first, const char *second,
   }
 
   {//tail
-    __u8 tag = 'e';
+    __u8 tag = RBD_DIFF_END;
     bufferlist bl;
     ::encode(tag, bl);
     r = bl.write_fd(pd);