]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-mirror: replace complex object op tuple with struct
authorJason Dillaman <dillaman@redhat.com>
Tue, 21 Feb 2017 16:52:00 +0000 (11:52 -0500)
committerNathan Cutler <ncutler@suse.com>
Thu, 13 Apr 2017 21:23:24 +0000 (23:23 +0200)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
(cherry picked from commit 0c181527c0e151784a0f7c466aaa70b0772f91b1)

src/tools/rbd_mirror/image_sync/ObjectCopyRequest.cc
src/tools/rbd_mirror/image_sync/ObjectCopyRequest.h

index df607e2ad20ba05e95494c175b427a964aac8bf7..900a5f7162400ee40d2e27e764a6c53a638f46e8 100644 (file)
@@ -104,16 +104,16 @@ void ObjectCopyRequest<I>::send_read_object() {
   bool read_required = false;
   librados::ObjectReadOperation op;
   for (auto &sync_op : sync_ops) {
-    switch (std::get<0>(sync_op)) {
+    switch (sync_op.type) {
     case SYNC_OP_TYPE_WRITE:
       if (!read_required) {
         dout(20) << ": remote_snap_seq=" << remote_snap_seq << dendl;
         read_required = true;
       }
-      dout(20) << ": read op: " << std::get<1>(sync_op) << "~"
-               << std::get<2>(sync_op) << dendl;
-      op.sparse_read(std::get<1>(sync_op), std::get<2>(sync_op), &std::get<4>(sync_op),
-                     &std::get<3>(sync_op), nullptr);
+      dout(20) << ": read op: " << sync_op.offset << "~" << sync_op.length
+               << dendl;
+      op.sparse_read(sync_op.offset, sync_op.length, &sync_op.extent_map,
+                     &sync_op.out_bl, nullptr);
       op.set_op_flags2(LIBRADOS_OP_FLAG_FADVISE_SEQUENTIAL |
                        LIBRADOS_OP_FLAG_FADVISE_NOCACHE);
       break;
@@ -178,11 +178,11 @@ void ObjectCopyRequest<I>::send_write_object() {
   uint64_t buffer_offset;
   librados::ObjectWriteOperation op;
   for (auto &sync_op : sync_ops) {
-    switch (std::get<0>(sync_op)) {
+    switch (sync_op.type) {
     case SYNC_OP_TYPE_WRITE:
-      object_offset = std::get<1>(sync_op);
+      object_offset = sync_op.offset;
       buffer_offset = 0;
-      for (auto it : std::get<4>(sync_op)) {
+      for (auto it : sync_op.extent_map) {
         if (object_offset < it.first) {
           dout(20) << ": zero op: " << object_offset << "~"
                    << it.first - object_offset << dendl;
@@ -190,15 +190,15 @@ void ObjectCopyRequest<I>::send_write_object() {
         }
         dout(20) << ": write op: " << it.first << "~" << it.second << dendl;
         bufferlist tmpbl;
-        tmpbl.substr_of(std::get<3>(sync_op), buffer_offset, it.second);
+        tmpbl.substr_of(sync_op.out_bl, buffer_offset, it.second);
         op.write(it.first, tmpbl);
         op.set_op_flags2(LIBRADOS_OP_FLAG_FADVISE_SEQUENTIAL |
                          LIBRADOS_OP_FLAG_FADVISE_NOCACHE);
         buffer_offset += it.second;
         object_offset = it.first + it.second;
       }
-      if (object_offset < std::get<1>(sync_op) + std::get<2>(sync_op)) {
-        uint64_t sync_op_end = std::get<1>(sync_op) + std::get<2>(sync_op);
+      if (object_offset < sync_op.offset + sync_op.length) {
+        uint64_t sync_op_end = sync_op.offset + sync_op.length;
         assert(sync_op_end <= m_snap_object_sizes[remote_snap_seq]);
         if (sync_op_end == m_snap_object_sizes[remote_snap_seq]) {
           dout(20) << ": trunc op: " << object_offset << dendl;
@@ -212,12 +212,12 @@ void ObjectCopyRequest<I>::send_write_object() {
       }
       break;
     case SYNC_OP_TYPE_TRUNC:
-      if (std::get<1>(sync_op) > m_snap_object_sizes[remote_snap_seq]) {
+      if (sync_op.offset > m_snap_object_sizes[remote_snap_seq]) {
         // skip (must have been updated in WRITE op case issuing trunc op)
         break;
       }
-      dout(20) << ": trunc op: " << std::get<1>(sync_op) << dendl;
-      op.truncate(std::get<1>(sync_op));
+      dout(20) << ": trunc op: " << sync_op.offset << dendl;
+      op.truncate(sync_op.offset);
       break;
     case SYNC_OP_TYPE_REMOVE:
       dout(20) << ": remove op" << dendl;
@@ -334,7 +334,6 @@ void ObjectCopyRequest<I>::compute_diffs() {
              << "diff=" << diff << ", "
              << "end_size=" << end_size << ", "
              << "exists=" << exists << dendl;
-
     if (exists) {
       // clip diff to size of object (in case it was truncated)
       if (end_size < prev_end_size) {
@@ -363,16 +362,12 @@ void ObjectCopyRequest<I>::compute_diffs() {
                  << it.get_len() << dendl;
         m_snap_sync_ops[end_remote_snap_id].emplace_back(SYNC_OP_TYPE_WRITE,
                                                          it.get_start(),
-                                                         it.get_len(),
-                                                         bufferlist(),
-                                                         std::map<uint64_t, uint64_t>());
+                                                         it.get_len());
       }
       if (end_size < prev_end_size) {
         dout(20) << ": trunc op: " << end_size << dendl;
         m_snap_sync_ops[end_remote_snap_id].emplace_back(SYNC_OP_TYPE_TRUNC,
-                                                         end_size, 0U,
-                                                         bufferlist(),
-                                                         std::map<uint64_t, uint64_t>());
+                                                         end_size, 0U);
       }
       m_snap_object_sizes[end_remote_snap_id] = end_size;
     } else {
@@ -380,8 +375,7 @@ void ObjectCopyRequest<I>::compute_diffs() {
         // object remove
         dout(20) << ": remove op" << dendl;
         m_snap_sync_ops[end_remote_snap_id].emplace_back(SYNC_OP_TYPE_REMOVE,
-                                                         0U, 0U, bufferlist(),
-                                                         std::map<uint64_t, uint64_t>());
+                                                         0U, 0U);
       }
     }
 
index fb9126e39b3bc2d9e77d11f7fc879082770e9035..2ade599787f11fa607933538b09f6c9b51f78a6f 100644 (file)
@@ -11,7 +11,6 @@
 #include <list>
 #include <map>
 #include <string>
-#include <tuple>
 #include <vector>
 
 class Context;
@@ -81,7 +80,21 @@ private:
     SYNC_OP_TYPE_REMOVE
   };
 
-  typedef std::tuple<SyncOpType, uint64_t, uint64_t, bufferlist, std::map<uint64_t, uint64_t> > SyncOp;
+  typedef std::map<uint64_t, uint64_t> ExtentMap;
+
+  struct SyncOp {
+    SyncOp(SyncOpType type, uint64_t offset, uint64_t length)
+      : type(type), offset(offset), length(length) {
+    }
+
+    SyncOpType type;
+    uint64_t offset;
+    uint64_t length;
+
+    ExtentMap extent_map;
+    bufferlist out_bl;
+  };
+
   typedef std::list<SyncOp> SyncOps;
   typedef std::map<librados::snap_t, SyncOps> SnapSyncOps;
   typedef std::map<librados::snap_t, uint8_t> SnapObjectStates;