]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
librbd: added io::ImageDispatchSpec::C_Dispatcher
authorJason Dillaman <dillaman@redhat.com>
Wed, 29 Apr 2020 00:34:34 +0000 (20:34 -0400)
committerJason Dillaman <dillaman@redhat.com>
Thu, 14 May 2020 15:56:45 +0000 (11:56 -0400)
This will assist with dispatching image extent-based IO requests
through the image IO dispatcher system (to be added in a later commit).

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/io/ImageDispatchSpec.cc
src/librbd/io/ImageDispatchSpec.h
src/librbd/io/ObjectDispatchSpec.cc
src/librbd/io/Types.h

index a787c57f49ee80278041277578fd752a6d6dced9..1854a6af44bde70a779a4a3cc65fb42830d18416 100644 (file)
 namespace librbd {
 namespace io {
 
+template <typename I>
+void ImageDispatchSpec<I>::C_Dispatcher::complete(int r) {
+  switch (image_dispatch_spec->dispatch_result) {
+  case DISPATCH_RESULT_RESTART:
+    ceph_assert(image_dispatch_spec->dispatch_layer != 0);
+    image_dispatch_spec->dispatch_layer = static_cast<ImageDispatchLayer>(
+      image_dispatch_spec->dispatch_layer - 1);
+    [[fallthrough]];
+  case DISPATCH_RESULT_CONTINUE:
+    if (r < 0) {
+      // bubble dispatch failure through AioCompletion
+      image_dispatch_spec->dispatch_result = DISPATCH_RESULT_COMPLETE;
+      image_dispatch_spec->fail(r);
+      return;
+    }
+
+    image_dispatch_spec->send();
+    break;
+  case DISPATCH_RESULT_COMPLETE:
+    finish(r);
+    break;
+  case DISPATCH_RESULT_INVALID:
+    ceph_abort();
+    break;
+  }
+}
+
+template <typename I>
+void ImageDispatchSpec<I>::C_Dispatcher::finish(int r) {
+  image_dispatch_spec->finish(r);
+}
+
 template <typename I>
 struct ImageDispatchSpec<I>::SendVisitor
   : public boost::static_visitor<void> {
@@ -115,6 +147,11 @@ void ImageDispatchSpec<I>::send() {
   boost::apply_visitor(SendVisitor{this}, m_request);
 }
 
+template <typename I>
+void ImageDispatchSpec<I>::finish(int r) {
+  delete this;
+}
+
 template <typename I>
 void ImageDispatchSpec<I>::fail(int r) {
   m_aio_comp->fail(r);
index bb326374a8451f1ff7ce4430db8ff932e8aab3e5..8bb602bd2cbb69b3eb85fbbab0a99067d1016bfe 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "include/int_types.h"
 #include "include/buffer.h"
+#include "include/Context.h"
 #include "common/zipkin_trace.h"
 #include "librbd/io/AioCompletion.h"
 #include "librbd/io/Types.h"
@@ -20,6 +21,19 @@ namespace io {
 
 template <typename ImageCtxT = ImageCtx>
 class ImageDispatchSpec {
+private:
+  // helper to avoid extra heap allocation per object IO
+  struct C_Dispatcher : public Context {
+    ImageDispatchSpec* image_dispatch_spec;
+
+    C_Dispatcher(ImageDispatchSpec* image_dispatch_spec)
+      : image_dispatch_spec(image_dispatch_spec) {
+    }
+
+    void complete(int r) override;
+    void finish(int r) override;
+  };
+
 public:
   struct Read {
     ReadResult read_result;
@@ -69,6 +83,10 @@ public:
     }
   };
 
+  C_Dispatcher dispatcher_ctx;
+  ImageDispatchLayer dispatch_layer = IMAGE_DISPATCH_LAYER_NONE;
+  DispatchResult dispatch_result = DISPATCH_RESULT_INVALID;
+
   static ImageDispatchSpec* create_read_request(
       ImageCtxT &image_ctx, AioCompletion *aio_comp, Extents &&image_extents,
       ReadResult &&read_result, int op_flags,
@@ -170,7 +188,7 @@ private:
   ImageDispatchSpec(ImageCtxT& image_ctx, AioCompletion* aio_comp,
                      Extents&& image_extents, Request&& request,
                      int op_flags, const ZTracer::Trace& parent_trace, uint64_t tid)
-    : m_image_ctx(image_ctx), m_aio_comp(aio_comp),
+    : dispatcher_ctx(this), m_image_ctx(image_ctx), m_aio_comp(aio_comp),
       m_image_extents(std::move(image_extents)), m_request(std::move(request)),
       m_op_flags(op_flags), m_parent_trace(parent_trace), m_tid(tid) {
     m_aio_comp->get();
@@ -185,6 +203,8 @@ private:
   uint64_t m_tid;
   std::atomic<uint64_t> m_throttled_flag = 0;
 
+  void finish(int r);
+
   uint64_t extents_length();
 };
 
index 0a4a3474eeef4b98cb167e8ed114031e64c87d66..3efff9774f087cf88427aa3bb477d316c47f1ef4 100644 (file)
@@ -23,6 +23,7 @@ void ObjectDispatchSpec::C_Dispatcher::complete(int r) {
     finish(r);
     break;
   case DISPATCH_RESULT_INVALID:
+  case DISPATCH_RESULT_RESTART:
     ceph_abort();
     break;
   }
index e9edced202034c79d49a0f211396aadac1c26a9d..9d5ef6d037cf0266d30917b58e4f40276e579a5c 100644 (file)
@@ -56,10 +56,23 @@ enum Direction {
 
 enum DispatchResult {
   DISPATCH_RESULT_INVALID,
+  DISPATCH_RESULT_RESTART,
   DISPATCH_RESULT_CONTINUE,
   DISPATCH_RESULT_COMPLETE
 };
 
+enum ImageDispatchLayer {
+  IMAGE_DISPATCH_LAYER_NONE = 0,
+  IMAGE_DISPATCH_LAYER_QUEUE,
+  IMAGE_DISPATCH_LAYER_QOS,
+  IMAGE_DISPATCH_LAYER_EXCLUSIVE_LOCK,
+  IMAGE_DISPATCH_LAYER_REFRESH,
+  IMAGE_DISPATCH_LAYER_JOURNAL,
+  IMAGE_DISPATCH_LAYER_WRITEBACK_CACHE,
+  IMAGE_DISPATCH_LAYER_CORE,
+  IMAGE_DISPATCH_LAYER_LAST
+};
+
 enum ObjectDispatchLayer {
   OBJECT_DISPATCH_LAYER_NONE = 0,
   OBJECT_DISPATCH_LAYER_CACHE,