]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: pass bytes-read statistics from deep-copy through handler
authorJason Dillaman <dillaman@redhat.com>
Fri, 3 Apr 2020 19:24:14 +0000 (15:24 -0400)
committerJason Dillaman <dillaman@redhat.com>
Fri, 3 Apr 2020 19:24:14 +0000 (15:24 -0400)
These simple stats will be utilized by rbd-mirror to compute throughput
metrics for snapshot-based mirroring.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/deep_copy/Handler.h
src/librbd/deep_copy/ImageCopyRequest.cc
src/librbd/deep_copy/ObjectCopyRequest.cc
src/librbd/deep_copy/ObjectCopyRequest.h
src/librbd/io/CopyupRequest.cc
src/librbd/operation/MigrateRequest.cc
src/test/librbd/deep_copy/test_mock_ImageCopyRequest.cc
src/test/librbd/deep_copy/test_mock_ObjectCopyRequest.cc
src/test/librbd/io/test_mock_CopyupRequest.cc
src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc

index cd4eb1db3eed37c2ae85fb10967c2c3f00972045..fea553ee2dd242efef8417894058bc1bb764596a 100644 (file)
@@ -13,11 +13,16 @@ namespace deep_copy {
 struct Handler {
   virtual ~Handler() {}
 
+  virtual void handle_read(uint64_t bytes_read) = 0;
+
   virtual int update_progress(uint64_t object_number,
                               uint64_t object_count) = 0;
 };
 
 struct NoOpHandler : public Handler {
+  void handle_read(uint64_t bytes_read) override {
+  }
+
   int update_progress(uint64_t object_number,
                       uint64_t object_count) override {
     return 0;
index 8b2b610300ff12c158112ade32ca01ab17c7f435..739e55c33ccc240890434c5f1a962e8efc740e07 100644 (file)
@@ -162,9 +162,9 @@ int ImageCopyRequest<I>::send_next_object_copy() {
     [this, ono](int r) {
       handle_object_copy(ono, r);
     });
-  ObjectCopyRequest<I> *req = ObjectCopyRequest<I>::create(
+  auto req = ObjectCopyRequest<I>::create(
     m_src_image_ctx, m_dst_image_ctx, m_src_snap_id_start, m_dst_snap_id_start,
-    m_snap_map, ono, m_flatten, ctx);
+    m_snap_map, ono, m_flatten, m_handler, ctx);
   req->send();
   return 0;
 }
index 23f31bae64ea8d463e27e9ece8c17d4efa2b9448..4e8d23d53fb6af103e1f258e5c7eeef3e7649496 100644 (file)
@@ -7,6 +7,7 @@
 #include "librbd/ExclusiveLock.h"
 #include "librbd/ObjectMap.h"
 #include "librbd/Utils.h"
+#include "librbd/deep_copy/Handler.h"
 #include "librbd/io/AioCompletion.h"
 #include "librbd/io/AsyncOperation.h"
 #include "librbd/io/ImageRequest.h"
@@ -47,13 +48,14 @@ ObjectCopyRequest<I>::ObjectCopyRequest(I *src_image_ctx,
                                         librados::snap_t dst_snap_id_start,
                                         const SnapMap &snap_map,
                                         uint64_t dst_object_number,
-                                        bool flatten, Context *on_finish)
+                                        bool flatten, Handler* handler,
+                                        Context *on_finish)
   : m_src_image_ctx(src_image_ctx),
     m_dst_image_ctx(dst_image_ctx), m_cct(dst_image_ctx->cct),
     m_src_snap_id_start(src_snap_id_start),
     m_dst_snap_id_start(dst_snap_id_start), m_snap_map(snap_map),
     m_dst_object_number(dst_object_number), m_flatten(flatten),
-    m_on_finish(on_finish) {
+    m_handler(handler), m_on_finish(on_finish) {
   ceph_assert(src_image_ctx->data_ctx.is_valid());
   ceph_assert(dst_image_ctx->data_ctx.is_valid());
   ceph_assert(!m_snap_map.empty());
@@ -222,6 +224,16 @@ void ObjectCopyRequest<I>::handle_read_object(int r) {
     return;
   }
 
+  if (m_handler != nullptr) {
+    uint64_t bytes_read = 0;
+
+    auto index = *m_read_snaps.begin();
+    for (auto &copy_op : m_read_ops[index]) {
+      bytes_read += copy_op.out_bl.length();
+    }
+    m_handler->handle_read(bytes_read);
+  }
+
   ceph_assert(!m_read_snaps.empty());
   m_read_snaps.erase(m_read_snaps.begin());
 
index 20f3ea37b252d50e2e0de236996b9cb3d3c96c3d..5d57a8b32c222c7ef8018a875f6b782f0d13328c 100644 (file)
@@ -24,6 +24,8 @@ namespace io { class AsyncOperation; }
 
 namespace deep_copy {
 
+struct Handler;
+
 template <typename ImageCtxT = librbd::ImageCtx>
 class ObjectCopyRequest {
 public:
@@ -33,16 +35,17 @@ public:
                                    librados::snap_t dst_snap_id_start,
                                    const SnapMap &snap_map,
                                    uint64_t object_number, bool flatten,
-                                   Context *on_finish) {
+                                   Handler* handler, Context *on_finish) {
     return new ObjectCopyRequest(src_image_ctx, dst_image_ctx,
                                  src_snap_id_start, dst_snap_id_start, snap_map,
-                                 object_number, flatten, on_finish);
+                                 object_number, flatten, handler, on_finish);
   }
 
   ObjectCopyRequest(ImageCtxT *src_image_ctx, ImageCtxT *dst_image_ctx,
                     librados::snap_t src_snap_id_start,
                     librados::snap_t dst_snap_id_start, const SnapMap &snap_map,
-                    uint64_t object_number, bool flatten, Context *on_finish);
+                    uint64_t object_number, bool flatten, Handler* handler,
+                    Context *on_finish);
 
   void send();
 
@@ -145,6 +148,7 @@ private:
   SnapMap m_snap_map;
   uint64_t m_dst_object_number;
   bool m_flatten;
+  Handler* m_handler;
   Context *m_on_finish;
 
   decltype(m_src_image_ctx->data_ctx) m_src_io_ctx;
index 066d15f4eaa17f04e2c150e2d965c57d00a54a01..94b80ecca1e86e8f95e79209db9e9dbe62f2ae35 100644 (file)
@@ -241,7 +241,7 @@ void CopyupRequest<I>::deep_copy() {
     CopyupRequest<I>, &CopyupRequest<I>::handle_deep_copy>(this);
   auto req = deep_copy::ObjectCopyRequest<I>::create(
     m_image_ctx->parent, m_image_ctx, 0, 0,
-    m_image_ctx->migration_info.snap_map, m_object_no, m_flatten, ctx);
+    m_image_ctx->migration_info.snap_map, m_object_no, m_flatten, nullptr, ctx);
 
   req->send();
 }
index 890d26c4b07b85bc086ba0fd494881194c443cf3..fdd7164d3c6cdb7cf8be7b172cc43d7a7dcdd525 100644 (file)
@@ -130,7 +130,7 @@ private:
 
       auto req = deep_copy::ObjectCopyRequest<I>::create(
         image_ctx.parent, &image_ctx, 0, 0, image_ctx.migration_info.snap_map,
-        m_object_no, image_ctx.migration_info.flatten, ctx);
+        m_object_no, image_ctx.migration_info.flatten, nullptr, ctx);
 
       ldout(cct, 20) << "deep copy object req " << req << ", object_no "
                      << m_object_no << dendl;
index 95c157a10c2f00375df5bb434143187fd015c38a..4ee6320f3e5c9fdc6f6a6cfb113d7951db406a78 100644 (file)
@@ -55,7 +55,8 @@ struct ObjectCopyRequest<librbd::MockTestImageCtx> {
       librados::snap_t src_snap_id_start,
       librados::snap_t dst_snap_id_start,
       const SnapMap &snap_map,
-      uint64_t object_number, bool flatten, Context *on_finish) {
+      uint64_t object_number, bool flatten, Handler* handler,
+      Context *on_finish) {
     ceph_assert(s_instance != nullptr);
     std::lock_guard locker{s_instance->lock};
     s_instance->snap_map = &snap_map;
index 056792cd5e3a8676360224df35eec292600cd441..c2e03db37b715ac7353ec564efbcdc57017f044d 100644 (file)
@@ -211,7 +211,7 @@ public:
     expect_get_object_name(mock_dst_image_ctx);
     return new MockObjectCopyRequest(&mock_src_image_ctx, &mock_dst_image_ctx,
                                      src_snap_id_start, dst_snap_id_start,
-                                     m_snap_map, 0, false, on_finish);
+                                     m_snap_map, 0, false, nullptr, on_finish);
   }
 
   void expect_set_snap_read(librados::MockTestMemIoCtxImpl &mock_io_ctx,
index 50c2f7b56ff3aca107d72922f6d78b5faa776d80..6a979b0ceb74cd7181968c1e8c74fcef8319891b 100644 (file)
@@ -51,7 +51,7 @@ struct ObjectCopyRequest<librbd::MockTestImageCtx> {
                                    librados::snap_t dst_snap_id_start,
                                    const SnapMap &snap_map,
                                    uint64_t object_number, bool flatten,
-                                   Context *on_finish) {
+                                   Handler*, Context *on_finish) {
     ceph_assert(s_instance != nullptr);
     s_instance->object_number = object_number;
     s_instance->flatten = flatten;
index 5656b16a01de3c435fe58375fb443c434a0b0ca1..2982f86a2b2ee87ee7f58df411ca722545a13232 100644 (file)
@@ -103,6 +103,9 @@ struct Replayer<I>::DeepCopyHandler : public librbd::deep_copy::Handler {
   DeepCopyHandler(Replayer* replayer) : replayer(replayer) {
   }
 
+  void handle_read(uint64_t bytes_read) override {
+  }
+
   int update_progress(uint64_t object_number, uint64_t object_count) override {
     replayer->handle_copy_image_progress(object_number, object_count);
     return 0;