]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: use an overridable finish handler for the image dispatcher
authorJason Dillaman <dillaman@redhat.com>
Mon, 31 Aug 2020 22:27:32 +0000 (18:27 -0400)
committerJason Dillaman <dillaman@redhat.com>
Fri, 18 Sep 2020 03:52:32 +0000 (23:52 -0400)
This mimics the design from the object dispatcher and will allow
for simplified in-flight IO tracking.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
17 files changed:
src/librbd/exclusive_lock/ImageDispatch.cc
src/librbd/exclusive_lock/ImageDispatch.h
src/librbd/io/ImageDispatch.cc
src/librbd/io/ImageDispatch.h
src/librbd/io/ImageDispatchInterface.h
src/librbd/io/ImageDispatchSpec.cc
src/librbd/io/ImageDispatchSpec.h
src/librbd/io/ImageDispatcher.cc
src/librbd/io/QosImageDispatch.cc
src/librbd/io/QosImageDispatch.h
src/librbd/io/QueueImageDispatch.cc
src/librbd/io/QueueImageDispatch.h
src/librbd/io/RefreshImageDispatch.cc
src/librbd/io/RefreshImageDispatch.h
src/librbd/io/WriteBlockImageDispatch.cc
src/librbd/io/WriteBlockImageDispatch.h
src/test/librbd/mock/io/MockImageDispatch.h

index dc276f1e410f8e2f306339481576844876a2272c..d6eb958e286dffb6dc867424343ce98da66ec1e7 100644 (file)
@@ -108,7 +108,8 @@ bool ImageDispatch<I>::read(
     io::ReadResult &&read_result, int op_flags,
     const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    io::DispatchResult* dispatch_result, Context* on_dispatched) {
+    io::DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "image_extents=" << image_extents << dendl;
 
@@ -124,7 +125,8 @@ bool ImageDispatch<I>::write(
     io::AioCompletion* aio_comp, io::Extents &&image_extents, bufferlist &&bl,
     int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    io::DispatchResult* dispatch_result, Context* on_dispatched) {
+    io::DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << ", image_extents=" << image_extents
                  << dendl;
@@ -141,7 +143,8 @@ bool ImageDispatch<I>::discard(
     io::AioCompletion* aio_comp, io::Extents &&image_extents,
     uint32_t discard_granularity_bytes, const ZTracer::Trace &parent_trace,
     uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
-    io::DispatchResult* dispatch_result, Context* on_dispatched) {
+    io::DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << ", image_extents=" << image_extents
                  << dendl;
@@ -158,7 +161,8 @@ bool ImageDispatch<I>::write_same(
     io::AioCompletion* aio_comp, io::Extents &&image_extents, bufferlist &&bl,
     int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    io::DispatchResult* dispatch_result, Context* on_dispatched) {
+    io::DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << ", image_extents=" << image_extents
                  << dendl;
@@ -176,7 +180,8 @@ bool ImageDispatch<I>::compare_and_write(
     bufferlist &&cmp_bl, bufferlist &&bl, uint64_t *mismatch_offset,
     int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    io::DispatchResult* dispatch_result, Context* on_dispatched) {
+    io::DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << ", image_extents=" << image_extents
                  << dendl;
@@ -193,7 +198,8 @@ bool ImageDispatch<I>::flush(
     io::AioCompletion* aio_comp, io::FlushSource flush_source,
     const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    io::DispatchResult* dispatch_result, Context* on_dispatched) {
+    io::DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << dendl;
 
index 965499c45d433ddb7993fb3f6c9e90d1436dfea8..5a3e9259c8ed4d13e538cde7489bb9af3da9c3a5 100644 (file)
@@ -54,34 +54,40 @@ public:
       io::ReadResult &&read_result, int op_flags,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      io::DispatchResult* dispatch_result, Context* on_dispatched) override;
+      io::DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool write(
       io::AioCompletion* aio_comp, io::Extents &&image_extents, bufferlist &&bl,
       int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      io::DispatchResult* dispatch_result, Context* on_dispatched) override;
+      io::DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool discard(
       io::AioCompletion* aio_comp, io::Extents &&image_extents,
       uint32_t discard_granularity_bytes,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      io::DispatchResult* dispatch_result, Context* on_dispatched) override;
+      io::DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool write_same(
       io::AioCompletion* aio_comp, io::Extents &&image_extents, bufferlist &&bl,
       int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      io::DispatchResult* dispatch_result, Context* on_dispatched) override;
+      io::DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool compare_and_write(
       io::AioCompletion* aio_comp, io::Extents &&image_extents,
       bufferlist &&cmp_bl, bufferlist &&bl, uint64_t *mismatch_offset,
       int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      io::DispatchResult* dispatch_result, Context* on_dispatched) override;
+      io::DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool flush(
       io::AioCompletion* aio_comp, io::FlushSource flush_source,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      io::DispatchResult* dispatch_result, Context* on_dispatched) override;
+      io::DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
 
   void handle_finished(int r, uint64_t tid) override {
   }
index 21262e591ff8ac27a3c65adee73b38c6d013044e..7c7d85849d9c24fa43211b524adbdeac737e59d2 100644 (file)
@@ -36,7 +36,8 @@ bool ImageDispatch<I>::read(
     AioCompletion* aio_comp, Extents &&image_extents, ReadResult &&read_result,
     int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "image_extents=" << image_extents << dendl;
 
@@ -54,7 +55,8 @@ bool ImageDispatch<I>::write(
     AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
     int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "image_extents=" << image_extents << dendl;
 
@@ -72,7 +74,8 @@ bool ImageDispatch<I>::discard(
     AioCompletion* aio_comp, Extents &&image_extents,
     uint32_t discard_granularity_bytes, const ZTracer::Trace &parent_trace,
     uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "image_extents=" << image_extents << dendl;
 
@@ -90,7 +93,8 @@ bool ImageDispatch<I>::write_same(
     AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
     int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "image_extents=" << image_extents << dendl;
 
@@ -109,7 +113,8 @@ bool ImageDispatch<I>::compare_and_write(
     bufferlist &&bl, uint64_t *mismatch_offset, int op_flags,
     const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "image_extents=" << image_extents << dendl;
 
@@ -127,7 +132,8 @@ bool ImageDispatch<I>::flush(
     AioCompletion* aio_comp, FlushSource flush_source,
     const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << dendl;
 
index cc56264cddc7a0f9aa63849fd2811e99a6bfb689..c1f15404f9c7ccadefe7c72c29d9b47043e73b36 100644 (file)
@@ -38,34 +38,40 @@ public:
       ReadResult &&read_result, int op_flags,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool write(
       AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
       int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool discard(
       AioCompletion* aio_comp, Extents &&image_extents,
       uint32_t discard_granularity_bytes,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool write_same(
       AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
       int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool compare_and_write(
       AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&cmp_bl,
       bufferlist &&bl, uint64_t *mismatch_offset, int op_flags,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool flush(
       AioCompletion* aio_comp, FlushSource flush_source,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
 
   void handle_finished(int r, uint64_t tid) override {}
 
index ffe53d0f9c4f2ede482c42790a7b9b263ce78cee..6b0770dc8df0bfbda1d6ba144d564d58e41347a1 100644 (file)
@@ -35,34 +35,40 @@ struct ImageDispatchInterface {
       ReadResult &&read_result, int op_flags,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) = 0;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) = 0;
   virtual bool write(
       AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
       int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) = 0;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) = 0;
   virtual bool discard(
       AioCompletion* aio_comp, Extents &&image_extents,
       uint32_t discard_granularity_bytes,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) = 0;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) = 0;
   virtual bool write_same(
       AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
       int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) = 0;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) = 0;
   virtual bool compare_and_write(
       AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&cmp_bl,
       bufferlist &&bl, uint64_t *mismatch_offset, int op_flags,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) = 0;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) = 0;
   virtual bool flush(
       AioCompletion* aio_comp, FlushSource flush_source,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) = 0;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) = 0;
 
   virtual void handle_finished(int r, uint64_t tid) = 0;
 
index 9b363861191973bb2ff9847efe91b35583134ea3..95d8224ae904a790504cd5416f8259761319d149 100644 (file)
@@ -38,18 +38,13 @@ void ImageDispatchSpec::C_Dispatcher::complete(int r) {
 }
 
 void ImageDispatchSpec::C_Dispatcher::finish(int r) {
-  image_dispatch_spec->finish(r);
+  delete image_dispatch_spec;
 }
 
 void ImageDispatchSpec::send() {
   image_dispatcher->send(this);
 }
 
-void ImageDispatchSpec::finish(int r) {
-  image_dispatcher->finish(r, dispatch_layer, tid);
-  delete this;
-}
-
 void ImageDispatchSpec::fail(int r) {
   dispatch_result = DISPATCH_RESULT_COMPLETE;
   aio_comp->fail(r);
index 7dccf94bc2975c8b14233508fedcbd896ad790f4..8b17b2591b2d6d592ea7c9bce3e0e44ddcf36aa7 100644 (file)
@@ -204,8 +204,6 @@ private:
     aio_comp->image_dispatcher_ctx = &dispatcher_ctx;
     aio_comp->get();
   }
-
-  void finish(int r);
 };
 
 } // namespace io
index 9a37029e615da53968852d6daaf184e3d85b13f1..5226e9ec95da66c16696a2e045e6610a262318ec 100644 (file)
@@ -44,6 +44,7 @@ struct ImageDispatcher<I>::SendVisitor : public boost::static_visitor<bool> {
       image_dispatch_spec->parent_trace, image_dispatch_spec->tid,
       &image_dispatch_spec->image_dispatch_flags,
       &image_dispatch_spec->dispatch_result,
+      &image_dispatch_spec->aio_comp->image_dispatcher_ctx,
       &image_dispatch_spec->dispatcher_ctx);
   }
 
@@ -55,6 +56,7 @@ struct ImageDispatcher<I>::SendVisitor : public boost::static_visitor<bool> {
       image_dispatch_spec->parent_trace, image_dispatch_spec->tid,
       &image_dispatch_spec->image_dispatch_flags,
       &image_dispatch_spec->dispatch_result,
+      &image_dispatch_spec->aio_comp->image_dispatcher_ctx,
       &image_dispatch_spec->dispatcher_ctx);
   }
 
@@ -65,6 +67,7 @@ struct ImageDispatcher<I>::SendVisitor : public boost::static_visitor<bool> {
       image_dispatch_spec->op_flags, image_dispatch_spec->parent_trace,
       image_dispatch_spec->tid, &image_dispatch_spec->image_dispatch_flags,
       &image_dispatch_spec->dispatch_result,
+      &image_dispatch_spec->aio_comp->image_dispatcher_ctx,
       &image_dispatch_spec->dispatcher_ctx);
   }
 
@@ -75,6 +78,7 @@ struct ImageDispatcher<I>::SendVisitor : public boost::static_visitor<bool> {
       image_dispatch_spec->op_flags, image_dispatch_spec->parent_trace,
       image_dispatch_spec->tid, &image_dispatch_spec->image_dispatch_flags,
       &image_dispatch_spec->dispatch_result,
+      &image_dispatch_spec->aio_comp->image_dispatcher_ctx,
       &image_dispatch_spec->dispatcher_ctx);
   }
 
@@ -88,6 +92,7 @@ struct ImageDispatcher<I>::SendVisitor : public boost::static_visitor<bool> {
       image_dispatch_spec->parent_trace, image_dispatch_spec->tid,
       &image_dispatch_spec->image_dispatch_flags,
       &image_dispatch_spec->dispatch_result,
+      &image_dispatch_spec->aio_comp->image_dispatcher_ctx,
       &image_dispatch_spec->dispatcher_ctx);
   }
 
@@ -97,6 +102,7 @@ struct ImageDispatcher<I>::SendVisitor : public boost::static_visitor<bool> {
       image_dispatch_spec->parent_trace, image_dispatch_spec->tid,
       &image_dispatch_spec->image_dispatch_flags,
       &image_dispatch_spec->dispatch_result,
+      &image_dispatch_spec->aio_comp->image_dispatcher_ctx,
       &image_dispatch_spec->dispatcher_ctx);
   }
 };
index 8badb58b1a4ac907d5fae39f68a98d21b875e356..66da8d440e45bfc30c40c9b459c9531bc924b0fe 100644 (file)
@@ -118,13 +118,14 @@ bool QosImageDispatch<I>::read(
     AioCompletion* aio_comp, Extents &&image_extents, ReadResult &&read_result,
     int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << ", image_extents=" << image_extents
                  << dendl;
 
   if (needs_throttle(true, image_extents, tid, image_dispatch_flags,
-                     dispatch_result, on_dispatched)) {
+                     dispatch_result, on_finish, on_dispatched)) {
     return true;
   }
 
@@ -136,13 +137,14 @@ bool QosImageDispatch<I>::write(
     AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
     int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << ", image_extents=" << image_extents
                  << dendl;
 
   if (needs_throttle(false, image_extents, tid, image_dispatch_flags,
-                     dispatch_result, on_dispatched)) {
+                     dispatch_result, on_finish, on_dispatched)) {
     return true;
   }
 
@@ -154,13 +156,14 @@ bool QosImageDispatch<I>::discard(
     AioCompletion* aio_comp, Extents &&image_extents,
     uint32_t discard_granularity_bytes, const ZTracer::Trace &parent_trace,
     uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << ", image_extents=" << image_extents
                  << dendl;
 
   if (needs_throttle(false, image_extents, tid, image_dispatch_flags,
-                     dispatch_result, on_dispatched)) {
+                     dispatch_result, on_finish, on_dispatched)) {
     return true;
   }
 
@@ -172,13 +175,14 @@ bool QosImageDispatch<I>::write_same(
     AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
     int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << ", image_extents=" << image_extents
                  << dendl;
 
   if (needs_throttle(false, image_extents, tid, image_dispatch_flags,
-                     dispatch_result, on_dispatched)) {
+                     dispatch_result, on_finish, on_dispatched)) {
     return true;
   }
 
@@ -191,13 +195,14 @@ bool QosImageDispatch<I>::compare_and_write(
     bufferlist &&bl, uint64_t *mismatch_offset, int op_flags,
     const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << ", image_extents=" << image_extents
                  << dendl;
 
   if (needs_throttle(false, image_extents, tid, image_dispatch_flags,
-                     dispatch_result, on_dispatched)) {
+                     dispatch_result, on_finish, on_dispatched)) {
     return true;
   }
 
@@ -209,7 +214,8 @@ bool QosImageDispatch<I>::flush(
     AioCompletion* aio_comp, FlushSource flush_source,
     const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << dendl;
 
@@ -243,13 +249,18 @@ template <typename I>
 bool QosImageDispatch<I>::needs_throttle(
     bool read_op, const Extents& image_extents, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   auto extent_length = get_extent_length(image_extents);
   bool all_qos_flags_set = false;
 
   if (!read_op) {
     m_flush_tracker->start_io(tid);
+    *on_finish = new LambdaContext([this, tid, on_finish=*on_finish](int r) {
+        handle_finished(r, tid);
+        on_finish->complete(r);
+      });
   }
   *dispatch_result = DISPATCH_RESULT_CONTINUE;
 
index 04ed33c001038b55bd1fe31e2ff9818dcac2110d..4ddd21b99cdd49e7bbfd6a0b075453af0788abcc 100644 (file)
@@ -55,34 +55,40 @@ public:
       ReadResult &&read_result, int op_flags,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool write(
       AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
       int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool discard(
       AioCompletion* aio_comp, Extents &&image_extents,
       uint32_t discard_granularity_bytes,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool write_same(
       AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
       int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool compare_and_write(
       AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&cmp_bl,
       bufferlist &&bl, uint64_t *mismatch_offset, int op_flags,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool flush(
       AioCompletion* aio_comp, FlushSource flush_source,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
 
   void handle_finished(int r, uint64_t tid) override;
 
@@ -98,7 +104,8 @@ private:
                          uint32_t flag);
   bool needs_throttle(bool read_op, const Extents& image_extents, uint64_t tid,
                       std::atomic<uint32_t>* image_dispatch_flags,
-                      DispatchResult* dispatch_result, Context* on_dispatched);
+                      DispatchResult* dispatch_result, Context** on_finish,
+                      Context* on_dispatched);
   void handle_throttle_ready(Tag&& tag, uint64_t flag);
 
 };
index a07557aa278e91e288248e9e8048a8097e4cdf98..f59d484d5c46f2d5efc69b619a34896766792ca0 100644 (file)
@@ -42,11 +42,12 @@ bool QueueImageDispatch<I>::read(
     AioCompletion* aio_comp, Extents &&image_extents, ReadResult &&read_result,
     int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << dendl;
 
-  return enqueue(true, tid, dispatch_result, on_dispatched);
+  return enqueue(true, tid, dispatch_result, on_finish, on_dispatched);
 }
 
 template <typename I>
@@ -54,11 +55,12 @@ bool QueueImageDispatch<I>::write(
     AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
     int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << dendl;
 
-  return enqueue(false, tid, dispatch_result, on_dispatched);
+  return enqueue(false, tid, dispatch_result, on_finish, on_dispatched);
 }
 
 template <typename I>
@@ -66,11 +68,12 @@ bool QueueImageDispatch<I>::discard(
     AioCompletion* aio_comp, Extents &&image_extents,
     uint32_t discard_granularity_bytes, const ZTracer::Trace &parent_trace,
     uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << dendl;
 
-  return enqueue(false, tid, dispatch_result, on_dispatched);
+  return enqueue(false, tid, dispatch_result, on_finish, on_dispatched);
 }
 
 template <typename I>
@@ -78,11 +81,12 @@ bool QueueImageDispatch<I>::write_same(
     AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
     int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << dendl;
 
-  return enqueue(false, tid, dispatch_result, on_dispatched);
+  return enqueue(false, tid, dispatch_result, on_finish, on_dispatched);
 }
 
 template <typename I>
@@ -91,11 +95,12 @@ bool QueueImageDispatch<I>::compare_and_write(
     bufferlist &&bl, uint64_t *mismatch_offset, int op_flags,
     const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << dendl;
 
-  return enqueue(false, tid, dispatch_result, on_dispatched);
+  return enqueue(false, tid, dispatch_result, on_finish, on_dispatched);
 }
 
 template <typename I>
@@ -103,7 +108,8 @@ bool QueueImageDispatch<I>::flush(
     AioCompletion* aio_comp, FlushSource flush_source,
     const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << dendl;
 
@@ -123,13 +129,17 @@ void QueueImageDispatch<I>::handle_finished(int r, uint64_t tid) {
 template <typename I>
 bool QueueImageDispatch<I>::enqueue(
     bool read_op, uint64_t tid, DispatchResult* dispatch_result,
-    Context* on_dispatched) {
+    Context** on_finish, Context* on_dispatched) {
   if (!m_image_ctx->non_blocking_aio) {
     return false;
   }
 
   if (!read_op) {
     m_flush_tracker->start_io(tid);
+    *on_finish = new LambdaContext([this, tid, on_finish=*on_finish](int r) {
+        handle_finished(r, tid);
+        on_finish->complete(r);
+      });
   }
 
   *dispatch_result = DISPATCH_RESULT_CONTINUE;
index 5592d1d5bd754b26211c49e86d668f32376f7110..cbadad95ec1d385d3e161e9d7577a7fd277d900d 100644 (file)
@@ -42,34 +42,40 @@ public:
       ReadResult &&read_result, int op_flags,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool write(
       AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
       int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool discard(
       AioCompletion* aio_comp, Extents &&image_extents,
       uint32_t discard_granularity_bytes,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool write_same(
       AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
       int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool compare_and_write(
       AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&cmp_bl,
       bufferlist &&bl, uint64_t *mismatch_offset, int op_flags,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool flush(
       AioCompletion* aio_comp, FlushSource flush_source,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
 
   void handle_finished(int r, uint64_t tid) override;
 
@@ -79,7 +85,7 @@ private:
   FlushTracker<ImageCtxT>* m_flush_tracker;
 
   bool enqueue(bool read_op, uint64_t tid, DispatchResult* dispatch_result,
-               Context* on_dispatched);
+               Context** on_finish, Context* on_dispatched);
 
 };
 
index 24a2038ca7ece1ec07ecc2e302ecd63f3be66cbe..9ba3bda03ba19666c475d6904666dbb4d4f6c9a5 100644 (file)
@@ -32,7 +32,8 @@ bool RefreshImageDispatch<I>::read(
     AioCompletion* aio_comp, Extents &&image_extents, ReadResult &&read_result,
     int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << ", image_extents=" << image_extents
                  << dendl;
@@ -49,7 +50,8 @@ bool RefreshImageDispatch<I>::write(
     AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
     int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << ", image_extents=" << image_extents
                  << dendl;
@@ -66,7 +68,8 @@ bool RefreshImageDispatch<I>::discard(
     AioCompletion* aio_comp, Extents &&image_extents,
     uint32_t discard_granularity_bytes, const ZTracer::Trace &parent_trace,
     uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << ", image_extents=" << image_extents
                  << dendl;
@@ -83,7 +86,8 @@ bool RefreshImageDispatch<I>::write_same(
     AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
     int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << ", image_extents=" << image_extents
                  << dendl;
@@ -101,7 +105,8 @@ bool RefreshImageDispatch<I>::compare_and_write(
     bufferlist &&bl, uint64_t *mismatch_offset, int op_flags,
     const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << ", image_extents=" << image_extents
                  << dendl;
@@ -118,7 +123,8 @@ bool RefreshImageDispatch<I>::flush(
     AioCompletion* aio_comp, FlushSource flush_source,
     const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << dendl;
 
index 154ff64b0752194b434f791f25db2bd3dd0b05e1..3510b350f4cc8d1a2446922ec15d9bb6bf602a45 100644 (file)
@@ -38,34 +38,40 @@ public:
       ReadResult &&read_result, int op_flags,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool write(
       AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
       int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool discard(
       AioCompletion* aio_comp, Extents &&image_extents,
       uint32_t discard_granularity_bytes,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool write_same(
       AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
       int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool compare_and_write(
       AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&cmp_bl,
       bufferlist &&bl, uint64_t *mismatch_offset, int op_flags,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool flush(
       AioCompletion* aio_comp, FlushSource flush_source,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
 
   void handle_finished(int r, uint64_t tid) override {}
 
index 729ecc5e60041c87bd4b93b528b74597caf96552..d7895f1658cb9b93d117061d917f56584f2ca15d 100644 (file)
@@ -124,28 +124,17 @@ void WriteBlockImageDispatch<I>::wait_on_writes_unblocked(
   on_unblocked->complete(0);
 }
 
-template <typename I>
-bool WriteBlockImageDispatch<I>::read(
-    AioCompletion* aio_comp, Extents &&image_extents, ReadResult &&read_result,
-    int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
-    std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
-  auto cct = m_image_ctx->cct;
-  ldout(cct, 20) << "tid=" << tid << dendl;
-
-  return process_io(true, tid, dispatch_result, on_dispatched);
-}
-
 template <typename I>
 bool WriteBlockImageDispatch<I>::write(
     AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
     int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << dendl;
 
-  return process_io(false, tid, dispatch_result, on_dispatched);
+  return process_io(tid, dispatch_result, on_finish, on_dispatched);
 }
 
 template <typename I>
@@ -153,11 +142,12 @@ bool WriteBlockImageDispatch<I>::discard(
     AioCompletion* aio_comp, Extents &&image_extents,
     uint32_t discard_granularity_bytes, const ZTracer::Trace &parent_trace,
     uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << dendl;
 
-  return process_io(false, tid, dispatch_result, on_dispatched);
+  return process_io(tid, dispatch_result, on_finish, on_dispatched);
 }
 
 template <typename I>
@@ -165,11 +155,12 @@ bool WriteBlockImageDispatch<I>::write_same(
     AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
     int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << dendl;
 
-  return process_io(false, tid, dispatch_result, on_dispatched);
+  return process_io(tid, dispatch_result, on_finish, on_dispatched);
 }
 
 template <typename I>
@@ -178,11 +169,12 @@ bool WriteBlockImageDispatch<I>::compare_and_write(
     bufferlist &&bl, uint64_t *mismatch_offset, int op_flags,
     const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << dendl;
 
-  return process_io(false, tid, dispatch_result, on_dispatched);
+  return process_io(tid, dispatch_result, on_finish, on_dispatched);
 }
 
 template <typename I>
@@ -190,7 +182,8 @@ bool WriteBlockImageDispatch<I>::flush(
     AioCompletion* aio_comp, FlushSource flush_source,
     const ZTracer::Trace &parent_trace, uint64_t tid,
     std::atomic<uint32_t>* image_dispatch_flags,
-    DispatchResult* dispatch_result, Context* on_dispatched) {
+    DispatchResult* dispatch_result, Context** on_finish,
+    Context* on_dispatched) {
   auto cct = m_image_ctx->cct;
   ldout(cct, 20) << "tid=" << tid << dendl;
 
@@ -198,7 +191,7 @@ bool WriteBlockImageDispatch<I>::flush(
     return false;
   }
 
-  return process_io(false, tid, dispatch_result, on_dispatched);
+  return process_io(tid, dispatch_result, on_finish, on_dispatched);
 }
 
 template <typename I>
@@ -208,10 +201,7 @@ void WriteBlockImageDispatch<I>::handle_finished(int r, uint64_t tid) {
 
   std::unique_lock locker{m_lock};
   auto it = m_in_flight_write_tids.find(tid);
-  if (it == m_in_flight_write_tids.end()) {
-    // assumed to be a read op
-    return;
-  }
+  ceph_assert(it != m_in_flight_write_tids.end());
   m_in_flight_write_tids.erase(it);
 
   bool writes_blocked = false;
@@ -228,19 +218,20 @@ void WriteBlockImageDispatch<I>::handle_finished(int r, uint64_t tid) {
 
 template <typename I>
 bool WriteBlockImageDispatch<I>::process_io(
-    bool read_op, uint64_t tid, DispatchResult* dispatch_result,
+    uint64_t tid, DispatchResult* dispatch_result, Context** on_finish,
     Context* on_dispatched) {
   std::unique_lock locker{m_lock};
-  if (!read_op) {
-    if (m_write_blockers > 0 || !m_on_dispatches.empty()) {
-      *dispatch_result = DISPATCH_RESULT_RESTART;
-      m_on_dispatches.push_back(on_dispatched);
-      return true;
-    }
-
-    m_in_flight_write_tids.insert(tid);
+  if (m_write_blockers > 0 || !m_on_dispatches.empty()) {
+    *dispatch_result = DISPATCH_RESULT_RESTART;
+    m_on_dispatches.push_back(on_dispatched);
+    return true;
   }
 
+  *on_finish = new LambdaContext([this, tid, on_finish=*on_finish](int r) {
+      handle_finished(r, tid);
+      on_finish->complete(r);
+    });
+  m_in_flight_write_tids.insert(tid);
   return false;
 }
 
index 42e7fed82822053ee35439fa7c3c7970af593a2c..adbb357c1cd26d1a53b7190daa84697395a12d91 100644 (file)
@@ -52,34 +52,42 @@ public:
       ReadResult &&read_result, int op_flags,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override {
+    return false;
+  }
   bool write(
       AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
       int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool discard(
       AioCompletion* aio_comp, Extents &&image_extents,
       uint32_t discard_granularity_bytes,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool write_same(
       AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
       int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool compare_and_write(
       AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&cmp_bl,
       bufferlist &&bl, uint64_t *mismatch_offset, int op_flags,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
   bool flush(
       AioCompletion* aio_comp, FlushSource flush_source,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override;
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override;
 
   void handle_finished(int r, uint64_t tid) override;
 
@@ -99,8 +107,8 @@ private:
   Contexts m_write_blocker_contexts;
   Contexts m_unblocked_write_waiter_contexts;
 
-  bool process_io(bool read_op, uint64_t tid, DispatchResult* dispatch_result,
-                  Context* on_dispatched);
+  bool process_io(uint64_t tid, DispatchResult* dispatch_result,
+                  Context** on_finish, Context* on_dispatched);
   void flush_io(Context* on_finish);
 
   void handle_blocked_writes(int r);
index 80afcec5633209e728db581cc74db870dd4ca02f..683c8003ec0602342fe7ce019041973ce33d6f91 100644 (file)
@@ -25,7 +25,8 @@ public:
       ReadResult &&read_result, int op_flags,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override {
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override {
     return false;
   }
 
@@ -33,7 +34,8 @@ public:
       AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
       int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override {
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override {
     return false;
   }
 
@@ -42,7 +44,8 @@ public:
       uint32_t discard_granularity_bytes,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override {
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override {
     return false;
   }
 
@@ -50,7 +53,8 @@ public:
       AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
       int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override {
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override {
     return false;
   }
 
@@ -59,7 +63,8 @@ public:
       bufferlist &&bl, uint64_t *mismatch_offset, int op_flags,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override {
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override {
     return false;
   }
 
@@ -67,7 +72,8 @@ public:
       AioCompletion* aio_comp, FlushSource flush_source,
       const ZTracer::Trace &parent_trace, uint64_t tid,
       std::atomic<uint32_t>* image_dispatch_flags,
-      DispatchResult* dispatch_result, Context* on_dispatched) override {
+      DispatchResult* dispatch_result, Context** on_finish,
+      Context* on_dispatched) override {
     return false;
   }