]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: import/export image_order.
authorDongsheng Yang <dongsheng.yang@easystack.cn>
Thu, 13 Oct 2016 11:00:33 +0000 (07:00 -0400)
committerDongsheng Yang <dongsheng.yang@easystack.cn>
Sun, 19 Feb 2017 12:42:03 +0000 (20:42 +0800)
Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
src/tools/rbd/Utils.h
src/tools/rbd/action/Export.cc
src/tools/rbd/action/Import.cc

index 54250f1702130cf53bb17a9a6c25af8ded6b55f2..f1819abed280820cf3c503fcb4b9c69c6a18a80b 100644 (file)
@@ -27,6 +27,9 @@ static const std::string RBD_DIFF_BANNER_V2 ("rbd diff v2\n");
 #define RBD_DIFF_ZERO          'z'
 #define RBD_DIFF_END           'e'
 
+#define RBD_EXPORT_IMAGE_ORDER         'O'
+#define RBD_EXPORT_IMAGE_END           'E'
+
 enum SnapshotPresence {
   SNAPSHOT_PRESENCE_NONE,
   SNAPSHOT_PRESENCE_PERMITTED,
index 6c07440ee16e3674f6f9112eda511afb736bd872..b269f36ad6c4dfd47d69a37fb5037dc26de702c4 100644 (file)
@@ -400,6 +400,19 @@ static int do_export(librbd::Image& image, const char *path, bool no_progress, i
     uint64_t size = info.size;
     ::encode(size, bl);
 
+    // TODO add more priorities here, such as image_feature...
+    __u8 tag;
+
+    // encode order
+    tag = RBD_EXPORT_IMAGE_ORDER;
+    ::encode(tag, bl);
+    ::encode(uint64_t(info.order), bl);
+
+    // encode end tag
+    tag = RBD_EXPORT_IMAGE_END;
+    ::encode(tag, bl);
+
+    // write bl to fd.
     r = bl.write_fd(fd);
     if (r < 0) {
       goto out;
index b72689d454d0d2e3da1fc6ca824bc95464d04780..b64f8ca63eb943a43a82669d7b7f0796f7c66231 100644 (file)
@@ -387,6 +387,38 @@ static int do_import(librbd::RBD &rbd, librados::IoCtx& io_ctx,
     if (r < 0) {
       goto done;
     }
+
+    // As V1 format for image is already deprecated, import image in V2 by default.
+    uint64_t image_format = 2;
+    if (opts.get(RBD_IMAGE_OPTION_FORMAT, &image_format) != 0) {
+      opts.set(RBD_IMAGE_OPTION_FORMAT, image_format);
+    }
+
+    while (1) {
+      __u8 tag;
+      r = safe_read_exact(fd, &tag, 1);
+      if (r < 0) {
+       goto done;
+      }
+
+      if (tag == RBD_EXPORT_IMAGE_END) {
+       break;
+      } else if (tag == RBD_EXPORT_IMAGE_ORDER) {
+       uint64_t order = 0;
+       r = safe_read_exact(fd, &order, 8);
+       if (r < 0) {
+         goto done;
+       }
+       if (opts.get(RBD_IMAGE_OPTION_ORDER, &order) != 0) {
+         opts.set(RBD_IMAGE_OPTION_ORDER, order);
+       }
+      } else {
+       std::cerr << "rbd: invalid tag in image priority zone: " << tag << std::endl;
+       r = -EINVAL;
+       goto done;
+      }
+      //TODO, set the image options according flags and appending data.
+    }
   }
 
   r = rbd.create4(io_ctx, imgname, size, opts);