]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
librbd: add image dispatch layer to image dispatch spec
authorJason Dillaman <dillaman@redhat.com>
Mon, 4 May 2020 23:21:06 +0000 (19:21 -0400)
committerJason Dillaman <dillaman@redhat.com>
Thu, 14 May 2020 15:56:45 +0000 (11:56 -0400)
This will allow image extent-based IOs to skip layers. Also added helpful
enums for the start of user-based API requests and internal requests.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
12 files changed:
src/librbd/api/DiffIterate.cc
src/librbd/image/CloseRequest.cc
src/librbd/image/RefreshRequest.cc
src/librbd/io/ImageDispatchSpec.h
src/librbd/io/ImageRequestWQ.cc
src/librbd/io/Types.h
src/librbd/operation/ResizeRequest.cc
src/test/librbd/image/test_mock_RefreshRequest.cc
src/test/librbd/io/test_mock_ImageRequestWQ.cc
src/test/librbd/journal/test_Replay.cc
src/test/librbd/operation/test_mock_ResizeRequest.cc
src/test/rbd_mirror/test_ImageSync.cc

index 7e47c7ec3a82ec6d0879fdae3314a86ec224bfd1..4235679507da46b4e17932ebb6e0632b7a62f8dc 100644 (file)
@@ -251,7 +251,8 @@ int DiffIterate<I>::diff_iterate(I *ictx,
     auto aio_comp = io::AioCompletion::create_and_start(&flush_ctx, ictx,
                                                         io::AIO_TYPE_FLUSH);
     auto req = io::ImageDispatchSpec<I>::create_flush_request(
-      *ictx, aio_comp, io::FLUSH_SOURCE_INTERNAL, {});
+      *ictx, io::IMAGE_DISPATCH_LAYER_INTERNAL_START,
+      aio_comp, io::FLUSH_SOURCE_INTERNAL, {});
     req->send();
     delete req;
   }
index b9cdbba6a25a075aa5548d68da4e985fec9783b3..998459c2cde09b52e9cc1d86e26251b575123061 100644 (file)
@@ -168,7 +168,8 @@ void CloseRequest<I>::send_flush() {
   auto aio_comp = io::AioCompletion::create_and_start(ctx, m_image_ctx,
                                                       io::AIO_TYPE_FLUSH);
   auto req = io::ImageDispatchSpec<I>::create_flush_request(
-    *m_image_ctx, aio_comp, io::FLUSH_SOURCE_INTERNAL, {});
+    *m_image_ctx, io::IMAGE_DISPATCH_LAYER_INTERNAL_START, aio_comp,
+    io::FLUSH_SOURCE_INTERNAL, {});
   req->send();
   delete req;
 }
index 560b22ee6106b0bde65e54fb4ce9dfa4c4c65541..eea4fd1dc43d6678524a5b2376da787ee1a55fe8 100644 (file)
@@ -1225,7 +1225,8 @@ Context *RefreshRequest<I>::send_flush_aio() {
     auto aio_comp = io::AioCompletion::create_and_start(
       ctx, util::get_image_ctx(&m_image_ctx), io::AIO_TYPE_FLUSH);
     auto req = io::ImageDispatchSpec<I>::create_flush_request(
-      m_image_ctx, aio_comp, io::FLUSH_SOURCE_INTERNAL, {});
+      m_image_ctx, io::IMAGE_DISPATCH_LAYER_INTERNAL_START, aio_comp,
+      io::FLUSH_SOURCE_INTERNAL, {});
     req->send();
     delete req;
     return nullptr;
index 8bb602bd2cbb69b3eb85fbbab0a99067d1016bfe..a73b297eefcf57ae6e5bde75479277bd800bc74e 100644 (file)
@@ -84,47 +84,57 @@ public:
   };
 
   C_Dispatcher dispatcher_ctx;
-  ImageDispatchLayer dispatch_layer = IMAGE_DISPATCH_LAYER_NONE;
+  ImageDispatchLayer dispatch_layer;
   DispatchResult dispatch_result = DISPATCH_RESULT_INVALID;
 
   static ImageDispatchSpec* create_read_request(
-      ImageCtxT &image_ctx, AioCompletion *aio_comp, Extents &&image_extents,
+      ImageCtxT &image_ctx, ImageDispatchLayer image_dispatch_layer,
+      AioCompletion *aio_comp, Extents &&image_extents,
       ReadResult &&read_result, int op_flags,
       const ZTracer::Trace &parent_trace) {
-    return new ImageDispatchSpec(image_ctx, aio_comp,
+    return new ImageDispatchSpec(image_ctx, image_dispatch_layer, aio_comp,
                                  std::move(image_extents),
                                  Read{std::move(read_result)},
                                  op_flags, parent_trace, 0);
   }
 
   static ImageDispatchSpec* create_discard_request(
-      ImageCtxT &image_ctx, AioCompletion *aio_comp, uint64_t off, uint64_t len,
-      uint32_t discard_granularity_bytes, const ZTracer::Trace &parent_trace, uint64_t tid) {
-    return new ImageDispatchSpec(image_ctx, aio_comp, {{off, len}},
+      ImageCtxT &image_ctx, ImageDispatchLayer image_dispatch_layer,
+      AioCompletion *aio_comp, uint64_t off, uint64_t len,
+      uint32_t discard_granularity_bytes, const ZTracer::Trace &parent_trace,
+      uint64_t tid) {
+    return new ImageDispatchSpec(image_ctx, image_dispatch_layer, aio_comp,
+                                 {{off, len}},
                                  Discard{discard_granularity_bytes},
                                  0, parent_trace, tid);
   }
 
   static ImageDispatchSpec* create_write_request(
-      ImageCtxT &image_ctx, AioCompletion *aio_comp, Extents &&image_extents,
-      bufferlist &&bl, int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid) {
-    return new ImageDispatchSpec(image_ctx, aio_comp, std::move(image_extents),
-                                 Write{std::move(bl)}, op_flags, parent_trace, tid);
+      ImageCtxT &image_ctx, ImageDispatchLayer image_dispatch_layer,
+      AioCompletion *aio_comp, Extents &&image_extents,
+      bufferlist &&bl, int op_flags, const ZTracer::Trace &parent_trace,
+      uint64_t tid) {
+    return new ImageDispatchSpec(image_ctx, image_dispatch_layer, aio_comp,
+                                 std::move(image_extents), Write{std::move(bl)},
+                                 op_flags, parent_trace, tid);
   }
 
   static ImageDispatchSpec* create_write_same_request(
-      ImageCtxT &image_ctx, AioCompletion *aio_comp, uint64_t off, uint64_t len,
-      bufferlist &&bl, int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid) {
-    return new ImageDispatchSpec(image_ctx, aio_comp, {{off, len}},
-                                 WriteSame{std::move(bl)}, op_flags,
-                                 parent_trace, tid);
+      ImageCtxT &image_ctx, ImageDispatchLayer image_dispatch_layer,
+      AioCompletion *aio_comp, uint64_t off, uint64_t len,
+      bufferlist &&bl, int op_flags, const ZTracer::Trace &parent_trace,
+      uint64_t tid) {
+    return new ImageDispatchSpec(image_ctx, image_dispatch_layer, aio_comp,
+                                 {{off, len}}, WriteSame{std::move(bl)},
+                                 op_flags, parent_trace, tid);
   }
 
   static ImageDispatchSpec* create_compare_and_write_request(
-      ImageCtxT &image_ctx, AioCompletion *aio_comp, Extents &&image_extents,
+      ImageCtxT &image_ctx, ImageDispatchLayer image_dispatch_layer,
+      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) {
-    return new ImageDispatchSpec(image_ctx, aio_comp,
+    return new ImageDispatchSpec(image_ctx, image_dispatch_layer, aio_comp,
                                  std::move(image_extents),
                                  CompareAndWrite{std::move(cmp_bl),
                                                  std::move(bl),
@@ -133,10 +143,11 @@ public:
   }
 
   static ImageDispatchSpec* create_flush_request(
-      ImageCtxT &image_ctx, AioCompletion *aio_comp,
-      FlushSource flush_source, const ZTracer::Trace &parent_trace) {
-    return new ImageDispatchSpec(image_ctx, aio_comp, {}, Flush{flush_source},
-                                 0, parent_trace, 0);
+      ImageCtxT &image_ctx, ImageDispatchLayer image_dispatch_layer,
+      AioCompletion *aio_comp, FlushSource flush_source,
+      const ZTracer::Trace &parent_trace) {
+    return new ImageDispatchSpec(image_ctx, image_dispatch_layer, aio_comp, {},
+                                 Flush{flush_source}, 0, parent_trace, 0);
   }
 
   ~ImageDispatchSpec() {
@@ -185,10 +196,13 @@ private:
   struct IsWriteOpVisitor;
   struct TokenRequestedVisitor;
 
-  ImageDispatchSpec(ImageCtxT& image_ctx, AioCompletion* aio_comp,
-                     Extents&& image_extents, Request&& request,
-                     int op_flags, const ZTracer::Trace& parent_trace, uint64_t tid)
-    : dispatcher_ctx(this), m_image_ctx(image_ctx), m_aio_comp(aio_comp),
+  ImageDispatchSpec(ImageCtxT& image_ctx,
+                    ImageDispatchLayer image_dispatch_layer,
+                    AioCompletion* aio_comp, Extents&& image_extents,
+                    Request&& request, int op_flags,
+                    const ZTracer::Trace& parent_trace, uint64_t tid)
+    : dispatcher_ctx(this), dispatch_layer(image_dispatch_layer),
+      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();
index c8677d0a8c7a15afea51b459ee8a0aef80af9749..f74d20cfb4735c57f2989da67b6c8c5bfd6c6a5d 100644 (file)
@@ -35,7 +35,8 @@ void flush_image(I& image_ctx, Context* on_finish) {
   auto aio_comp = librbd::io::AioCompletion::create_and_start(
     on_finish, util::get_image_ctx(&image_ctx), librbd::io::AIO_TYPE_FLUSH);
   auto req = librbd::io::ImageDispatchSpec<I>::create_flush_request(
-    image_ctx, aio_comp, librbd::io::FLUSH_SOURCE_INTERNAL, {});
+    image_ctx, IMAGE_DISPATCH_LAYER_API_START, aio_comp, FLUSH_SOURCE_INTERNAL,
+    {});
   req->send();
   delete req;
 }
@@ -291,8 +292,8 @@ void ImageRequestWQ<I>::aio_read(AioCompletion *c, uint64_t off, uint64_t len,
   if (m_image_ctx.non_blocking_aio || writes_blocked() || !writes_empty() ||
       require_lock_on_read()) {
     queue(ImageDispatchSpec<I>::create_read_request(
-            m_image_ctx, c, {{off, len}}, std::move(read_result), op_flags,
-            trace));
+            m_image_ctx, IMAGE_DISPATCH_LAYER_API_START, c, {{off, len}},
+            std::move(read_result), op_flags, trace));
   } else {
     c->start_op();
     ImageRequest<I>::aio_read(&m_image_ctx, c, {{off, len}},
@@ -335,7 +336,8 @@ void ImageRequestWQ<I>::aio_write(AioCompletion *c, uint64_t off, uint64_t len,
   }
 
   ImageDispatchSpec<I> *req = ImageDispatchSpec<I>::create_write_request(
-          m_image_ctx, c, {{off, len}}, std::move(bl), op_flags, trace, tid);
+    m_image_ctx, IMAGE_DISPATCH_LAYER_API_START, c, {{off, len}}, std::move(bl),
+    op_flags, trace, tid);
 
   std::shared_lock owner_locker{m_image_ctx.owner_lock};
   if (m_image_ctx.non_blocking_aio || writes_blocked()) {
@@ -381,7 +383,8 @@ void ImageRequestWQ<I>::aio_discard(AioCompletion *c, uint64_t off,
   }
 
   ImageDispatchSpec<I> *req = ImageDispatchSpec<I>::create_discard_request(
-            m_image_ctx, c, off, len, discard_granularity_bytes, trace, tid);
+    m_image_ctx, IMAGE_DISPATCH_LAYER_API_START, c, off, len,
+    discard_granularity_bytes, trace, tid);
 
   std::shared_lock owner_locker{m_image_ctx.owner_lock};
   if (m_image_ctx.non_blocking_aio || writes_blocked()) {
@@ -418,7 +421,7 @@ void ImageRequestWQ<I>::aio_flush(AioCompletion *c, bool native_async) {
   auto tid = ++m_last_tid;
 
   ImageDispatchSpec<I> *req = ImageDispatchSpec<I>::create_flush_request(
-            m_image_ctx, c, FLUSH_SOURCE_USER, trace);
+    m_image_ctx, IMAGE_DISPATCH_LAYER_API_START, c, FLUSH_SOURCE_USER, trace);
 
   {
     std::lock_guard locker{m_lock};
@@ -474,7 +477,8 @@ void ImageRequestWQ<I>::aio_writesame(AioCompletion *c, uint64_t off,
   }
 
   ImageDispatchSpec<I> *req = ImageDispatchSpec<I>::create_write_same_request(
-            m_image_ctx, c, off, len, std::move(bl), op_flags, trace, tid);
+    m_image_ctx, IMAGE_DISPATCH_LAYER_API_START, c, off, len, std::move(bl),
+    op_flags, trace, tid);
 
   std::shared_lock owner_locker{m_image_ctx.owner_lock};
   if (m_image_ctx.non_blocking_aio || writes_blocked()) {
@@ -522,8 +526,8 @@ void ImageRequestWQ<I>::aio_compare_and_write(AioCompletion *c,
   }
 
   ImageDispatchSpec<I> *req = ImageDispatchSpec<I>::create_compare_and_write_request(
-            m_image_ctx, c, {{off, len}}, std::move(cmp_bl), std::move(bl),
-            mismatch_off, op_flags, trace, tid);
+    m_image_ctx, IMAGE_DISPATCH_LAYER_API_START, c, {{off, len}},
+    std::move(cmp_bl), std::move(bl), mismatch_off, op_flags, trace, tid);
 
   std::shared_lock owner_locker{m_image_ctx.owner_lock};
   if (m_image_ctx.non_blocking_aio || writes_blocked()) {
index 9d5ef6d037cf0266d30917b58e4f40276e579a5c..fc10337255c03240bfdf41d702457bdf05db0177 100644 (file)
@@ -63,10 +63,12 @@ enum DispatchResult {
 
 enum ImageDispatchLayer {
   IMAGE_DISPATCH_LAYER_NONE = 0,
+  IMAGE_DISPATCH_LAYER_API_START = IMAGE_DISPATCH_LAYER_NONE,
   IMAGE_DISPATCH_LAYER_QUEUE,
   IMAGE_DISPATCH_LAYER_QOS,
   IMAGE_DISPATCH_LAYER_EXCLUSIVE_LOCK,
   IMAGE_DISPATCH_LAYER_REFRESH,
+  IMAGE_DISPATCH_LAYER_INTERNAL_START = IMAGE_DISPATCH_LAYER_REFRESH,
   IMAGE_DISPATCH_LAYER_JOURNAL,
   IMAGE_DISPATCH_LAYER_WRITEBACK_CACHE,
   IMAGE_DISPATCH_LAYER_CORE,
index a14b6de24f42083bf4be8bc867afc382fe5d039c..53673980e9670be55c982d59c74bd25ed6e7e53e 100644 (file)
@@ -197,7 +197,8 @@ void ResizeRequest<I>::send_flush_cache() {
   auto aio_comp = io::AioCompletion::create_and_start(
     ctx, util::get_image_ctx(&image_ctx), io::AIO_TYPE_FLUSH);
   auto req = io::ImageDispatchSpec<I>::create_flush_request(
-    image_ctx, aio_comp, io::FLUSH_SOURCE_INTERNAL, {});
+    image_ctx, io::IMAGE_DISPATCH_LAYER_INTERNAL_START, aio_comp,
+    io::FLUSH_SOURCE_INTERNAL, {});
   req->send();
   delete req;
 }
index f9a076e3229c3004a19b05e6b4dd7134c071e9ea..ecec4586cf57f832267158709747282e8e83ded5 100644 (file)
@@ -111,8 +111,9 @@ struct ImageDispatchSpec<librbd::MockRefreshImageCtx> {
   AioCompletion *aio_comp = nullptr;
 
   static ImageDispatchSpec* create_flush_request(
-      librbd::MockRefreshImageCtx &image_ctx, AioCompletion *aio_comp,
-      FlushSource flush_source, const ZTracer::Trace &parent_trace) {
+      librbd::MockRefreshImageCtx &image_ctx, ImageDispatchLayer dispatch_layer,
+      AioCompletion *aio_comp, FlushSource flush_source,
+      const ZTracer::Trace &parent_trace) {
     ceph_assert(s_instance != nullptr);
     s_instance->aio_comp = aio_comp;
     return s_instance;
index 8ebea73cf85d1247b775eae7784ef7de9c49d4af..99c8362d887de5260bb62e7dceaa7395de3c411f 100644 (file)
@@ -43,17 +43,18 @@ struct ImageDispatchSpec<librbd::MockTestImageCtx> {
   bool blocked = false;
 
   static ImageDispatchSpec* create_write_request(
-      librbd::MockTestImageCtx &image_ctx, AioCompletion *aio_comp,
-      Extents &&image_extents, bufferlist &&bl, int op_flags,
-      const ZTracer::Trace &parent_trace, uint64_t tid) {
+      librbd::MockTestImageCtx &image_ctx, ImageDispatchLayer dispatch_layer,
+      AioCompletion *aio_comp, Extents &&image_extents, bufferlist &&bl,
+      int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid) {
     ceph_assert(s_instance != nullptr);
     s_instance->aio_comp = aio_comp;
     return s_instance;
   }
 
   static ImageDispatchSpec* create_flush_request(
-      librbd::MockTestImageCtx &image_ctx, AioCompletion *aio_comp,
-      FlushSource flush_source, const ZTracer::Trace &parent_trace) {
+      librbd::MockTestImageCtx &image_ctx, ImageDispatchLayer dispatch_layer,
+      AioCompletion *aio_comp, FlushSource flush_source,
+      const ZTracer::Trace &parent_trace) {
     ceph_assert(s_instance != nullptr);
     s_instance->aio_comp = aio_comp;
     return s_instance;
index f79d752a15a930cd522c6def0b01bd7fe5dfd8de..535198e3a7c9fac6334f40a1cf2164abe95b4acd 100644 (file)
@@ -862,7 +862,8 @@ TEST_F(TestJournalReplay, ObjectPosition) {
   aio_comp = librbd::io::AioCompletion::create_and_start(
     &flush_ctx, ictx, librbd::io::AIO_TYPE_FLUSH);
   auto req = librbd::io::ImageDispatchSpec<>::create_flush_request(
-    *ictx, aio_comp, librbd::io::FLUSH_SOURCE_INTERNAL, {});
+    *ictx, librbd::io::IMAGE_DISPATCH_LAYER_INTERNAL_START, aio_comp,
+    librbd::io::FLUSH_SOURCE_INTERNAL, {});
   req->send();
   delete req;
   ASSERT_EQ(0, flush_ctx.wait());
index 4cbf914313dd1260462a288c63f78955f1293595..764f2721327d9d79766a63b20cffc76d30def741 100644 (file)
@@ -33,8 +33,9 @@ struct ImageDispatchSpec<MockImageCtx> {
   AioCompletion *aio_comp = nullptr;
 
   static ImageDispatchSpec* create_flush_request(
-      MockImageCtx &image_ctx, AioCompletion *aio_comp,
-      FlushSource flush_source, const ZTracer::Trace &parent_trace) {
+      MockImageCtx &image_ctx, ImageDispatchLayer dispatch_layer,
+      AioCompletion *aio_comp, FlushSource flush_source,
+      const ZTracer::Trace &parent_trace) {
     ceph_assert(s_instance != nullptr);
     s_instance->aio_comp = aio_comp;
     return s_instance;
index c8aab54b0b5af1d72a418f895a6320c61a53daf7..2a830609fc783f183e4968cf3adbd4339eb184be 100644 (file)
@@ -36,7 +36,8 @@ int flush(librbd::ImageCtx *image_ctx) {
   auto aio_comp = librbd::io::AioCompletion::create_and_start(
     &ctx, image_ctx, librbd::io::AIO_TYPE_FLUSH);
   auto req = librbd::io::ImageDispatchSpec<>::create_flush_request(
-    *image_ctx, aio_comp, librbd::io::FLUSH_SOURCE_INTERNAL, {});
+    *image_ctx, librbd::io::IMAGE_DISPATCH_LAYER_INTERNAL_START, aio_comp,
+    librbd::io::FLUSH_SOURCE_INTERNAL, {});
   req->send();
   delete req;
   return ctx.wait();