]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: parse diff file header for diff merging
authorYunchuan Wen <yunchuanwen@ubuntukylin.com>
Mon, 12 Jan 2015 01:02:51 +0000 (01:02 +0000)
committerYunchuan Wen <yunchuanwen@ubuntukylin.com>
Mon, 12 Jan 2015 01:02:51 +0000 (01:02 +0000)
Signed-off-by: MingXin Liu <mingxinliu@ubuntukylin.com>
Signed-off-by: Yunchuan Wen <yunchuanwen@ubuntukylin.com>
Reviewed-by: Li Wang <liwang@ubuntukylin.com>
src/rbd.cc

index c47658aff3171df44c3c79c9878afe36e400f938..91761af2c1e824aa866cef29e08cebbd079a9328 100644 (file)
@@ -1712,6 +1712,56 @@ static int do_import_diff(librbd::Image &image, const char *path)
   return r;
 }
 
+static int parse_diff_header(int fd, __u8 *tag, string *from, string *to, uint64_t *size)
+{
+  int r;
+
+  {//header
+    char buf[strlen(RBD_DIFF_BANNER) + 1];
+    r = safe_read_exact(fd, buf, strlen(RBD_DIFF_BANNER));
+    if (r < 0)
+      return r;
+
+    buf[strlen(RBD_DIFF_BANNER)] = '\0';
+    if (strcmp(buf, RBD_DIFF_BANNER)) {
+      cerr << "invalid banner '" << buf << "', expected '" << RBD_DIFF_BANNER << "'" << std::endl;
+      return -EINVAL;
+    }
+  }
+
+  while (true) {
+    r = safe_read_exact(fd, tag, 1);
+    if (r < 0)
+      return r;
+
+    if (*tag == 'f') {
+      r = 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') {
+      r = 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') {
+      char buf[8];
+      r = safe_read_exact(fd, buf, 8);
+      if (r < 0)
+        return r;
+
+      bufferlist bl;
+      bl.append(buf, 8);
+      bufferlist::iterator p = bl.begin();
+      ::decode(*size, p);
+    } else {
+      break;
+    }
+  }
+
+  return 0;
+}
+
 /*
  * fd: the diff file to read from
  * pd: the diff file to be written into