]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: split ReadRequest
authorYuan Lu <yuan.y.lu@intel.com>
Tue, 12 May 2020 09:23:13 +0000 (17:23 +0800)
committerlixiaoy1 <xiaoyan.li@intel.com>
Mon, 3 Aug 2020 09:37:13 +0000 (05:37 -0400)
Signed-off-by: Peterson, Scott <scott.d.peterson@intel.com>
Signed-off-by: Li, Xiaoyan <xiaoyan.li@intel.com>
Signed-off-by: Lu, Yuan <yuan.y.lu@intel.com>
Signed-off-by: Chamarthy, Mahati <mahati.chamarthy@intel.com>
src/librbd/CMakeLists.txt
src/librbd/cache/ReplicatedWriteLog.cc
src/librbd/cache/rwl/ReadRequest.cc [new file with mode: 0644]
src/librbd/cache/rwl/ReadRequest.h [new file with mode: 0644]
src/librbd/cache/rwl/Request.cc
src/librbd/cache/rwl/Request.h

index 00fcc1d75719dc42bbf8f495f752c97bfd3907b6..c9f6146ec9860840a09a49b9d5536ac447f1ad56 100644 (file)
@@ -197,6 +197,7 @@ if(WITH_RBD_RWL)
     cache/rwl/LogEntry.cc
     cache/rwl/LogMap.cc
     cache/rwl/LogOperation.cc
+    cache/rwl/ReadRequest.cc
     cache/rwl/Request.cc
     cache/rwl/SyncPoint.cc
     cache/rwl/Types.cc
index 38309723054fc54102aedb57278c2a861c820c53..bcc434a74c7d6e2abfe7167b7b8319e4bb763489 100644 (file)
@@ -17,6 +17,7 @@
 #include "librbd/asio/ContextWQ.h"
 #include "librbd/cache/rwl/ImageCacheState.h"
 #include "librbd/cache/rwl/LogEntry.h"
+#include "librbd/cache/rwl/ReadRequest.h"
 #include "librbd/cache/rwl/Types.h"
 #include <map>
 #include <vector>
diff --git a/src/librbd/cache/rwl/ReadRequest.cc b/src/librbd/cache/rwl/ReadRequest.cc
new file mode 100644 (file)
index 0000000..d986060
--- /dev/null
@@ -0,0 +1,68 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include "ReadRequest.h"
+
+#define dout_subsys ceph_subsys_rbd_rwl
+#undef dout_prefix
+#define dout_prefix *_dout << "librbd::cache::rwl::ReadRequest: " << this << " " \
+                           <<  __func__ << ": "
+
+namespace librbd {
+namespace cache {
+namespace rwl {
+
+void C_ReadRequest::finish(int r) {
+  ldout(m_cct, 20) << "(" << get_name() << "): r=" << r << dendl;
+  int hits = 0;
+  int misses = 0;
+  int hit_bytes = 0;
+  int miss_bytes = 0;
+  if (r >= 0) {
+    /*
+     * At this point the miss read has completed. We'll iterate through
+     * read_extents and produce *m_out_bl by assembling pieces of miss_bl
+     * and the individual hit extent bufs in the read extents that represent
+     * hits.
+     */
+    uint64_t miss_bl_offset = 0;
+    for (auto &extent : read_extents) {
+      if (extent.m_bl.length()) {
+        /* This was a hit */
+        ceph_assert(extent.second == extent.m_bl.length());
+        ++hits;
+        hit_bytes += extent.second;
+        m_out_bl->claim_append(extent.m_bl);
+      } else {
+        /* This was a miss. */
+        ++misses;
+        miss_bytes += extent.second;
+        bufferlist miss_extent_bl;
+        miss_extent_bl.substr_of(miss_bl, miss_bl_offset, extent.second);
+        /* Add this read miss bufferlist to the output bufferlist */
+        m_out_bl->claim_append(miss_extent_bl);
+        /* Consume these bytes in the read miss bufferlist */
+        miss_bl_offset += extent.second;
+      }
+    }
+  }
+  ldout(m_cct, 20) << "(" << get_name() << "): r=" << r << " bl=" << *m_out_bl << dendl;
+  utime_t now = ceph_clock_now();
+  ceph_assert((int)m_out_bl->length() == hit_bytes + miss_bytes);
+  m_on_finish->complete(r);
+  m_perfcounter->inc(l_librbd_rwl_rd_bytes, hit_bytes + miss_bytes);
+  m_perfcounter->inc(l_librbd_rwl_rd_hit_bytes, hit_bytes);
+  m_perfcounter->tinc(l_librbd_rwl_rd_latency, now - m_arrived_time);
+  if (!misses) {
+    m_perfcounter->inc(l_librbd_rwl_rd_hit_req, 1);
+    m_perfcounter->tinc(l_librbd_rwl_rd_hit_latency, now - m_arrived_time);
+  } else {
+    if (hits) {
+      m_perfcounter->inc(l_librbd_rwl_rd_part_hit_req, 1);
+    }
+  }
+}
+
+} // namespace rwl
+} // namespace cache
+} // namespace librbd
diff --git a/src/librbd/cache/rwl/ReadRequest.h b/src/librbd/cache/rwl/ReadRequest.h
new file mode 100644 (file)
index 0000000..9daf7d1
--- /dev/null
@@ -0,0 +1,45 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#ifndef CEPH_LIBRBD_CACHE_RWL_READ_REQUEST_H
+#define CEPH_LIBRBD_CACHE_RWL_READ_REQUEST_H
+
+#include "include/Context.h"
+#include "librbd/cache/rwl/Types.h"
+
+namespace librbd {
+namespace cache {
+namespace rwl {
+
+typedef std::vector<rwl::ImageExtentBuf> ImageExtentBufs;
+
+class C_ReadRequest : public Context {
+public:
+  io::Extents miss_extents; // move back to caller
+  ImageExtentBufs read_extents;
+  bufferlist miss_bl;
+
+  C_ReadRequest(CephContext *cct, utime_t arrived, PerfCounters *perfcounter, bufferlist *out_bl, Context *on_finish)
+    : m_cct(cct), m_on_finish(on_finish), m_out_bl(out_bl),
+      m_arrived_time(arrived), m_perfcounter(perfcounter) {}
+  ~C_ReadRequest() {}
+
+  void finish(int r) override;
+
+  const char *get_name() const {
+    return "C_ReadRequest";
+  }
+
+private:
+  CephContext *m_cct;
+  Context *m_on_finish;
+  bufferlist *m_out_bl;
+  utime_t m_arrived_time;
+  PerfCounters *m_perfcounter;
+};
+
+} // namespace rwl
+} // namespace cache
+} // namespace librbd
+
+#endif // CEPH_LIBRBD_CACHE_RWL_READ_REQUEST_H
index d2d2fd8a36c82bcd24186391882bc89f3a90e907..1a3d8e9b2e4a0e11f3402c89eedc97e11c27e676 100644 (file)
@@ -410,57 +410,6 @@ std::ostream &operator<<(std::ostream &os,
   return os;
 }
 
-void C_ReadRequest::finish(int r) {
-  ldout(m_cct, 20) << "(" << get_name() << "): r=" << r << dendl;
-  int hits = 0;
-  int misses = 0;
-  int hit_bytes = 0;
-  int miss_bytes = 0;
-  if (r >= 0) {
-    /*
-     * At this point the miss read has completed. We'll iterate through
-     * read_extents and produce *m_out_bl by assembling pieces of miss_bl
-     * and the individual hit extent bufs in the read extents that represent
-     * hits.
-     */
-    uint64_t miss_bl_offset = 0;
-    for (auto &extent : read_extents) {
-      if (extent.m_bl.length()) {
-        /* This was a hit */
-        ceph_assert(extent.second == extent.m_bl.length());
-        ++hits;
-        hit_bytes += extent.second;
-        m_out_bl->claim_append(extent.m_bl);
-      } else {
-        /* This was a miss. */
-        ++misses;
-        miss_bytes += extent.second;
-        bufferlist miss_extent_bl;
-        miss_extent_bl.substr_of(miss_bl, miss_bl_offset, extent.second);
-        /* Add this read miss bufferlist to the output bufferlist */
-        m_out_bl->claim_append(miss_extent_bl);
-        /* Consume these bytes in the read miss bufferlist */
-        miss_bl_offset += extent.second;
-      }
-    }
-  }
-  ldout(m_cct, 20) << "(" << get_name() << "): r=" << r << " bl=" << *m_out_bl << dendl;
-  utime_t now = ceph_clock_now();
-  ceph_assert((int)m_out_bl->length() == hit_bytes + miss_bytes);
-  m_on_finish->complete(r);
-  m_perfcounter->inc(l_librbd_rwl_rd_bytes, hit_bytes + miss_bytes);
-  m_perfcounter->inc(l_librbd_rwl_rd_hit_bytes, hit_bytes);
-  m_perfcounter->tinc(l_librbd_rwl_rd_latency, now - m_arrived_time);
-  if (!misses) {
-    m_perfcounter->inc(l_librbd_rwl_rd_hit_req, 1);
-    m_perfcounter->tinc(l_librbd_rwl_rd_hit_latency, now - m_arrived_time);
-  } else {
-    if (hits) {
-      m_perfcounter->inc(l_librbd_rwl_rd_part_hit_req, 1);
-    }
-  }
-}
-
 template <typename T>
 C_DiscardRequest<T>::C_DiscardRequest(T &rwl, const utime_t arrived, io::Extents &&image_extents,
                                       uint32_t discard_granularity_bytes, ceph::mutex &lock,
@@ -671,33 +620,6 @@ std::ostream &operator<<(std::ostream &os,
   return os;
 }
 
-std::ostream &operator<<(std::ostream &os,
-                         const BlockGuardReqState &r) {
-  os << "barrier=" << r.barrier << ", "
-     << "current_barrier=" << r.current_barrier << ", "
-     << "detained=" << r.detained << ", "
-     << "queued=" << r.queued;
-  return os;
-}
-
-GuardedRequestFunctionContext::GuardedRequestFunctionContext(boost::function<void(GuardedRequestFunctionContext&)> &&callback)
-  : m_callback(std::move(callback)){ }
-
-GuardedRequestFunctionContext::~GuardedRequestFunctionContext(void) { }
-
-void GuardedRequestFunctionContext::finish(int r) {
-  ceph_assert(cell);
-  m_callback(*this);
-}
-
-std::ostream &operator<<(std::ostream &os,
-                         const GuardedRequest &r) {
-  os << "guard_ctx->state=[" << r.guard_ctx->state << "], "
-     << "block_extent.block_start=" << r.block_extent.block_start << ", "
-     << "block_extent.block_start=" << r.block_extent.block_end;
-  return os;
-}
-
 } // namespace rwl
 } // namespace cache
 } // namespace librbd
index bc8ef9327a6f5befc4cea0442b86eeff8b384296..2ab58e51d715267bc1e18faebc8e436ec308c041 100644 (file)
@@ -233,31 +233,6 @@ private:
                                   const C_FlushRequest<U> &req);
 };
 
-class C_ReadRequest : public Context {
-public:
-  io::Extents miss_extents; // move back to caller
-  ImageExtentBufs read_extents;
-  bufferlist miss_bl;
-
-  C_ReadRequest(CephContext *cct, utime_t arrived, PerfCounters *perfcounter, bufferlist *out_bl, Context *on_finish)
-    : m_cct(cct), m_on_finish(on_finish), m_out_bl(out_bl),
-      m_arrived_time(arrived), m_perfcounter(perfcounter) {}
-  ~C_ReadRequest() {}
-
-  void finish(int r) override;
-
-  const char *get_name() const {
-    return "C_ReadRequest";
-  }
-
-private:
-  CephContext *m_cct;
-  Context *m_on_finish;
-  bufferlist *m_out_bl;
-  utime_t m_arrived_time;
-  PerfCounters *m_perfcounter;
-};
-
 /**
  * This is the custodian of the BlockGuard cell for this discard. As in the
  * case of write, the block guard is not released until the discard persists
@@ -380,21 +355,31 @@ struct BlockGuardReqState {
   bool detained = false;
   bool queued = false; /* Queued for barrier */
   friend std::ostream &operator<<(std::ostream &os,
-                                  const BlockGuardReqState &r);
+                                  const BlockGuardReqState &r) {
+    os << "barrier=" << r.barrier << ", "
+       << "current_barrier=" << r.current_barrier << ", "
+       << "detained=" << r.detained << ", "
+       << "queued=" << r.queued;
+    return os;
+  }
 };
 
 class GuardedRequestFunctionContext : public Context {
 public:
   BlockGuardCell *cell = nullptr;
   BlockGuardReqState state;
-  GuardedRequestFunctionContext(boost::function<void(GuardedRequestFunctionContext&)> &&callback);
-  ~GuardedRequestFunctionContext(void) override;
+  GuardedRequestFunctionContext(boost::function<void(GuardedRequestFunctionContext&)> &&callback)
+    : m_callback(std::move(callback)){ }
+  ~GuardedRequestFunctionContext(void) override { };
   GuardedRequestFunctionContext(const GuardedRequestFunctionContext&) = delete;
   GuardedRequestFunctionContext &operator=(const GuardedRequestFunctionContext&) = delete;
 
 private:
   boost::function<void(GuardedRequestFunctionContext&)> m_callback;
-  void finish(int r) override;
+  void finish(int r) override {
+    ceph_assert(cell);
+    m_callback(*this);
+  }
 };
 
 class GuardedRequest {
@@ -408,7 +393,12 @@ public:
     guard_ctx->state.barrier = barrier;
   }
   friend std::ostream &operator<<(std::ostream &os,
-                                  const GuardedRequest &r);
+                                  const GuardedRequest &r) {
+    os << "guard_ctx->state=[" << r.guard_ctx->state << "], "
+       << "block_extent.block_start=" << r.block_extent.block_start << ", "
+       << "block_extent.block_start=" << r.block_extent.block_end;
+    return os;
+  }
 };
 
 } // namespace rwl