]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: remove unncessary templating from io::ImageDispatchSpec
authorJason Dillaman <dillaman@redhat.com>
Mon, 31 Aug 2020 20:04:34 +0000 (16:04 -0400)
committerJason Dillaman <dillaman@redhat.com>
Fri, 18 Sep 2020 00:40:09 +0000 (20:40 -0400)
This was a remnant of the original implimentation for the image
dispatch spec. Now it more closely aligns with the object dispatch
spec.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
18 files changed:
src/librbd/api/DiffIterate.cc
src/librbd/api/Io.cc
src/librbd/exclusive_lock/ImageDispatch.cc
src/librbd/image/CloseRequest.cc
src/librbd/image/RefreshRequest.cc
src/librbd/io/ImageDispatchInterface.h
src/librbd/io/ImageDispatchSpec.cc
src/librbd/io/ImageDispatchSpec.h
src/librbd/io/ImageDispatcher.cc
src/librbd/io/ImageDispatcher.h
src/librbd/io/WriteBlockImageDispatch.cc
src/librbd/operation/ResizeRequest.cc
src/test/librbd/image/test_mock_RefreshRequest.cc
src/test/librbd/journal/test_Replay.cc
src/test/librbd/mock/io/MockImageDispatcher.h
src/test/librbd/operation/test_mock_ResizeRequest.cc
src/test/librbd/test_fixture.cc
src/test/rbd_mirror/test_ImageSync.cc

index b34c6ff4afeb27cd005f3595ad1095274e832992..39b7cdea91f0552f1a415ff99b6f8d49c38d7109 100644 (file)
@@ -249,7 +249,7 @@ int DiffIterate<I>::diff_iterate(I *ictx,
     std::shared_lock owner_locker{ictx->owner_lock};
     auto aio_comp = io::AioCompletion::create_and_start(&flush_ctx, ictx,
                                                         io::AIO_TYPE_FLUSH);
-    auto req = io::ImageDispatchSpec<I>::create_flush(
+    auto req = io::ImageDispatchSpec::create_flush(
       *ictx, io::IMAGE_DISPATCH_LAYER_INTERNAL_START,
       aio_comp, io::FLUSH_SOURCE_INTERNAL, {});
     req->send();
index 76d43c4a344f46d08b79b3852d2b0fc995776f7d..7c2d10717294fc08cda289fb80e498c508f20a7a 100644 (file)
@@ -230,7 +230,7 @@ void Io<I>::aio_read(I &image_ctx, io::AioCompletion *aio_comp, uint64_t off,
     return;
   }
 
-  auto req = io::ImageDispatchSpec<I>::create_read(
+  auto req = io::ImageDispatchSpec::create_read(
     image_ctx, io::IMAGE_DISPATCH_LAYER_API_START, aio_comp, {{off, len}},
     std::move(read_result), op_flags, trace);
   req->send();
@@ -261,7 +261,7 @@ void Io<I>::aio_write(I &image_ctx, io::AioCompletion *aio_comp, uint64_t off,
     return;
   }
 
-  auto req = io::ImageDispatchSpec<I>::create_write(
+  auto req = io::ImageDispatchSpec::create_write(
     image_ctx, io::IMAGE_DISPATCH_LAYER_API_START, aio_comp, {{off, len}},
     std::move(bl), op_flags, trace, 0);
   req->send();
@@ -292,7 +292,7 @@ void Io<I>::aio_discard(I &image_ctx, io::AioCompletion *aio_comp, uint64_t off,
     return;
   }
 
-  auto req = io::ImageDispatchSpec<I>::create_discard(
+  auto req = io::ImageDispatchSpec::create_discard(
     image_ctx, io::IMAGE_DISPATCH_LAYER_API_START, aio_comp, off, len,
     discard_granularity_bytes, trace, 0);
   req->send();
@@ -324,7 +324,7 @@ void Io<I>::aio_write_same(I &image_ctx, io::AioCompletion *aio_comp,
     return;
   }
 
-  auto req = io::ImageDispatchSpec<I>::create_write_same(
+  auto req = io::ImageDispatchSpec::create_write_same(
     image_ctx, io::IMAGE_DISPATCH_LAYER_API_START, aio_comp, off, len,
     std::move(bl), op_flags, trace, 0);
   req->send();
@@ -397,7 +397,7 @@ void Io<I>::aio_write_zeroes(I& image_ctx, io::AioCompletion *aio_comp,
       bl.append_zero(len);
 
       aio_comp->aio_type = io::AIO_TYPE_WRITE;
-      auto req = io::ImageDispatchSpec<I>::create_write(
+      auto req = io::ImageDispatchSpec::create_write(
         image_ctx, io::IMAGE_DISPATCH_LAYER_API_START, aio_comp, {{off, len}},
         std::move(bl), op_flags, trace, 0);
       req->send();
@@ -407,7 +407,7 @@ void Io<I>::aio_write_zeroes(I& image_ctx, io::AioCompletion *aio_comp,
       bufferlist bl;
       bl.append_zero(data_length);
 
-      auto req = io::ImageDispatchSpec<I>::create_write_same(
+      auto req = io::ImageDispatchSpec::create_write_same(
         image_ctx, io::IMAGE_DISPATCH_LAYER_API_START, aio_comp, off, len,
         std::move(bl), op_flags, trace, 0);
       req->send();
@@ -435,7 +435,7 @@ void Io<I>::aio_write_zeroes(I& image_ctx, io::AioCompletion *aio_comp,
       Context* prepend_ctx = new io::C_AioRequest(aio_comp);
       auto prepend_aio_comp = io::AioCompletion::create_and_start(
         prepend_ctx, &image_ctx, io::AIO_TYPE_WRITE);
-      auto prepend_req = io::ImageDispatchSpec<I>::create_write(
+      auto prepend_req = io::ImageDispatchSpec::create_write(
         image_ctx, io::IMAGE_DISPATCH_LAYER_API_START, prepend_aio_comp,
         {{prepend_offset, prepend_length}}, std::move(bl), op_flags, trace,
         0);
@@ -449,7 +449,7 @@ void Io<I>::aio_write_zeroes(I& image_ctx, io::AioCompletion *aio_comp,
       Context* append_ctx = new io::C_AioRequest(aio_comp);
       auto append_aio_comp = io::AioCompletion::create_and_start(
         append_ctx, &image_ctx, io::AIO_TYPE_WRITE);
-      auto append_req = io::ImageDispatchSpec<I>::create_write(
+      auto append_req = io::ImageDispatchSpec::create_write(
         image_ctx, io::IMAGE_DISPATCH_LAYER_API_START, append_aio_comp,
         {{append_offset, append_length}}, std::move(bl), op_flags, trace, 0);
       append_req->send();
@@ -461,7 +461,7 @@ void Io<I>::aio_write_zeroes(I& image_ctx, io::AioCompletion *aio_comp,
     Context* write_same_ctx = new io::C_AioRequest(aio_comp);
     auto write_same_aio_comp = io::AioCompletion::create_and_start(
       write_same_ctx, &image_ctx, io::AIO_TYPE_WRITESAME);
-    auto req = io::ImageDispatchSpec<I>::create_write_same(
+    auto req = io::ImageDispatchSpec::create_write_same(
       image_ctx, io::IMAGE_DISPATCH_LAYER_API_START, write_same_aio_comp,
       write_same_offset, write_same_length, std::move(bl), op_flags, trace,
       0);
@@ -472,7 +472,7 @@ void Io<I>::aio_write_zeroes(I& image_ctx, io::AioCompletion *aio_comp,
   // enable partial discard (zeroing) of objects
   uint32_t discard_granularity_bytes = 0;
 
-  auto req = io::ImageDispatchSpec<I>::create_discard(
+  auto req = io::ImageDispatchSpec::create_discard(
     image_ctx, io::IMAGE_DISPATCH_LAYER_API_START, aio_comp, off, len,
     discard_granularity_bytes, trace, 0);
   req->send();
@@ -506,7 +506,7 @@ void Io<I>::aio_compare_and_write(I &image_ctx, io::AioCompletion *aio_comp,
     return;
   }
 
-  auto req = io::ImageDispatchSpec<I>::create_compare_and_write(
+  auto req = io::ImageDispatchSpec::create_compare_and_write(
     image_ctx, io::IMAGE_DISPATCH_LAYER_API_START, aio_comp, {{off, len}},
     std::move(cmp_bl), std::move(bl), mismatch_off, op_flags, trace, 0);
   req->send();
@@ -535,7 +535,7 @@ void Io<I>::aio_flush(I &image_ctx, io::AioCompletion *aio_comp,
     return;
   }
 
-  auto req = io::ImageDispatchSpec<I>::create_flush(
+  auto req = io::ImageDispatchSpec::create_flush(
     image_ctx, io::IMAGE_DISPATCH_LAYER_API_START, aio_comp,
     io::FLUSH_SOURCE_USER, trace);
   req->send();
index 66dda453bf3d8516aa4586e8cd21e10b6867b97d..87007c60a73fed524a29f582c3f2da144673494e 100644 (file)
@@ -70,7 +70,7 @@ void ImageDispatch<I>::set_require_lock(io::Direction direction,
   // push through a flush for any in-flight writes at lower levels
   auto aio_comp = io::AioCompletion::create_and_start(
     on_finish, util::get_image_ctx(m_image_ctx), io::AIO_TYPE_FLUSH);
-  auto req = io::ImageDispatchSpec<I>::create_flush(
+  auto req = io::ImageDispatchSpec::create_flush(
     *m_image_ctx, io::IMAGE_DISPATCH_LAYER_EXCLUSIVE_LOCK, aio_comp,
     io::FLUSH_SOURCE_INTERNAL, {});
   req->send();
index c12cecd52d71000d9c64bb961e821a7fabcec596..04f8b6f630b5fca5f4cbdbf553306c00f299e2ff 100644 (file)
@@ -103,7 +103,7 @@ void CloseRequest<I>::send_flush() {
     CloseRequest<I>, &CloseRequest<I>::handle_flush>(this);
   auto aio_comp = io::AioCompletion::create_and_start(ctx, m_image_ctx,
                                                       io::AIO_TYPE_FLUSH);
-  auto req = io::ImageDispatchSpec<I>::create_flush(
+  auto req = io::ImageDispatchSpec::create_flush(
     *m_image_ctx, io::IMAGE_DISPATCH_LAYER_API_START, aio_comp,
     io::FLUSH_SOURCE_INTERNAL, {});
   req->send();
index 251c89bfebf36d2cf607105bc6c11278320a8880..735d701b61a1ca18bea4b846b3e0d198609db861 100644 (file)
@@ -1245,7 +1245,7 @@ Context *RefreshRequest<I>::send_flush_aio() {
       RefreshRequest<I>, &RefreshRequest<I>::handle_flush_aio>(this);
     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(
+    auto req = io::ImageDispatchSpec::create_flush(
       m_image_ctx, io::IMAGE_DISPATCH_LAYER_INTERNAL_START, aio_comp,
       io::FLUSH_SOURCE_INTERNAL, {});
     req->send();
index d96cb924b92c8a17b90a10377145b8c61f8485e3..ffe53d0f9c4f2ede482c42790a7b9b263ce78cee 100644 (file)
@@ -17,11 +17,11 @@ namespace librbd {
 namespace io {
 
 struct AioCompletion;
-template <typename> struct ImageDispatchSpec;
+struct ImageDispatchSpec;
 
 struct ImageDispatchInterface {
   typedef ImageDispatchLayer DispatchLayer;
-  typedef ImageDispatchSpec<librbd::ImageCtx> DispatchSpec;
+  typedef ImageDispatchSpec DispatchSpec;
 
   virtual ~ImageDispatchInterface() {
   }
index 2ca0d82127b1001456316e6740e022bc9e30b6ee..9b363861191973bb2ff9847efe91b35583134ea3 100644 (file)
@@ -11,8 +11,7 @@
 namespace librbd {
 namespace io {
 
-template <typename I>
-void ImageDispatchSpec<I>::C_Dispatcher::complete(int r) {
+void ImageDispatchSpec::C_Dispatcher::complete(int r) {
   switch (image_dispatch_spec->dispatch_result) {
   case DISPATCH_RESULT_RESTART:
     ceph_assert(image_dispatch_spec->dispatch_layer != 0);
@@ -38,74 +37,23 @@ void ImageDispatchSpec<I>::C_Dispatcher::complete(int r) {
   }
 }
 
-template <typename I>
-void ImageDispatchSpec<I>::C_Dispatcher::finish(int r) {
+void ImageDispatchSpec::C_Dispatcher::finish(int r) {
   image_dispatch_spec->finish(r);
 }
 
-template <typename I>
-struct ImageDispatchSpec<I>::IsWriteOpVisitor
-  : public boost::static_visitor<bool> {
-  bool operator()(const Read&) const {
-    return false;
-  }
-
-  template <typename T>
-  bool operator()(const T&) const {
-    return true;
-  }
-};
-
-template <typename I>
-void ImageDispatchSpec<I>::send() {
+void ImageDispatchSpec::send() {
   image_dispatcher->send(this);
 }
 
-template <typename I>
-void ImageDispatchSpec<I>::finish(int r) {
+void ImageDispatchSpec::finish(int r) {
   image_dispatcher->finish(r, dispatch_layer, tid);
   delete this;
 }
 
-template <typename I>
-void ImageDispatchSpec<I>::fail(int r) {
+void ImageDispatchSpec::fail(int r) {
   dispatch_result = DISPATCH_RESULT_COMPLETE;
   aio_comp->fail(r);
 }
 
-template <typename I>
-uint64_t ImageDispatchSpec<I>::extents_length() {
-  uint64_t length = 0;
-  auto &extents = this->image_extents;
-
-  for (auto &extent : extents) {
-    length += extent.second;
-  }
-  return length;
-}
-
-template <typename I>
-const Extents& ImageDispatchSpec<I>::get_image_extents() const {
-   return this->image_extents;
-}
-
-template <typename I>
-uint64_t ImageDispatchSpec<I>::get_tid() {
-  return this->tid;
-}
-
-template <typename I>
-bool ImageDispatchSpec<I>::is_write_op() const {
-  return boost::apply_visitor(IsWriteOpVisitor(), request);
-}
-
-template <typename I>
-void ImageDispatchSpec<I>::start_op() {
-  tid = 0;
-  aio_comp->start_op();
-}
-
 } // namespace io
 } // namespace librbd
-
-template class librbd::io::ImageDispatchSpec<librbd::ImageCtx>;
index 1c12f3afcb48e491f844c058604aac1176b6b868..7dccf94bc2975c8b14233508fedcbd896ad790f4 100644 (file)
@@ -22,7 +22,6 @@ namespace io {
 
 struct ImageDispatcherInterface;
 
-template <typename ImageCtxT = ImageCtx>
 class ImageDispatchSpec {
 private:
   // helper to avoid extra heap allocation per object IO
@@ -107,54 +106,63 @@ public:
   ZTracer::Trace parent_trace;
   uint64_t tid;
 
+  template <typename ImageCtxT = ImageCtx>
   static ImageDispatchSpec* create_read(
       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, image_dispatch_layer, aio_comp,
+    return new ImageDispatchSpec(image_ctx.io_image_dispatcher,
+                                 image_dispatch_layer, aio_comp,
                                  std::move(image_extents),
                                  Read{std::move(read_result)},
                                  op_flags, parent_trace, 0);
   }
 
+  template <typename ImageCtxT = ImageCtx>
   static ImageDispatchSpec* create_discard(
       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}},
+    return new ImageDispatchSpec(image_ctx.io_image_dispatcher,
+                                 image_dispatch_layer, aio_comp, {{off, len}},
                                  Discard{discard_granularity_bytes},
                                  0, parent_trace, tid);
   }
 
+  template <typename ImageCtxT = ImageCtx>
   static ImageDispatchSpec* create_write(
       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,
+    return new ImageDispatchSpec(image_ctx.io_image_dispatcher,
+                                 image_dispatch_layer, aio_comp,
                                  std::move(image_extents), Write{std::move(bl)},
                                  op_flags, parent_trace, tid);
   }
 
+  template <typename ImageCtxT = ImageCtx>
   static ImageDispatchSpec* create_write_same(
       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,
+    return new ImageDispatchSpec(image_ctx.io_image_dispatcher,
+                                 image_dispatch_layer, aio_comp,
                                  {{off, len}}, WriteSame{std::move(bl)},
                                  op_flags, parent_trace, tid);
   }
 
+  template <typename ImageCtxT = ImageCtx>
   static ImageDispatchSpec* create_compare_and_write(
       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, image_dispatch_layer, aio_comp,
+    return new ImageDispatchSpec(image_ctx.io_image_dispatcher,
+                                 image_dispatch_layer, aio_comp,
                                  std::move(image_extents),
                                  CompareAndWrite{std::move(cmp_bl),
                                                  std::move(bl),
@@ -162,11 +170,13 @@ public:
                                  op_flags, parent_trace, tid);
   }
 
+  template <typename ImageCtxT = ImageCtx>
   static ImageDispatchSpec* create_flush(
       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, {},
+    return new ImageDispatchSpec(image_ctx.io_image_dispatcher,
+                                 image_dispatch_layer, aio_comp, {},
                                  Flush{flush_source}, 0, parent_trace, 0);
   }
 
@@ -177,30 +187,17 @@ public:
   void send();
   void fail(int r);
 
-  bool is_write_op() const;
-
-  void start_op();
-
-  const Extents& get_image_extents() const;
-
-  AioCompletion* get_aio_completion() const {
-    return aio_comp;
-  }
-
-  uint64_t get_tid();
-  bool blocked = false;
-
 private:
   struct SendVisitor;
   struct IsWriteOpVisitor;
   struct TokenRequestedVisitor;
 
-  ImageDispatchSpec(ImageCtxT& image_ctx,
+  ImageDispatchSpec(ImageDispatcherInterface* image_dispatcher,
                     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), image_dispatcher(image_ctx.io_image_dispatcher),
+    : dispatcher_ctx(this), image_dispatcher(image_dispatcher),
       dispatch_layer(image_dispatch_layer), aio_comp(aio_comp),
       image_extents(std::move(image_extents)), request(std::move(request)),
       op_flags(op_flags), parent_trace(parent_trace), tid(tid) {
@@ -209,13 +206,9 @@ private:
   }
 
   void finish(int r);
-
-  uint64_t extents_length();
 };
 
 } // namespace io
 } // namespace librbd
 
-extern template class librbd::io::ImageDispatchSpec<librbd::ImageCtx>;
-
 #endif // CEPH_LIBRBD_IO_IMAGE_DISPATCH_SPEC_H
index c060d5c779a97c5ddeeddc38cc8581342f659b61..9a37029e615da53968852d6daaf184e3d85b13f1 100644 (file)
@@ -28,15 +28,15 @@ namespace io {
 template <typename I>
 struct ImageDispatcher<I>::SendVisitor : public boost::static_visitor<bool> {
   ImageDispatchInterface* image_dispatch;
-  ImageDispatchSpec<I>* image_dispatch_spec;
+  ImageDispatchSpec* image_dispatch_spec;
 
   SendVisitor(ImageDispatchInterface* image_dispatch,
-              ImageDispatchSpec<I>* image_dispatch_spec)
+              ImageDispatchSpec* image_dispatch_spec)
     : image_dispatch(image_dispatch),
       image_dispatch_spec(image_dispatch_spec) {
   }
 
-  bool operator()(typename ImageDispatchSpec<I>::Read& read) const {
+  bool operator()(ImageDispatchSpec::Read& read) const {
     return image_dispatch->read(
       image_dispatch_spec->aio_comp,
       std::move(image_dispatch_spec->image_extents),
@@ -47,7 +47,7 @@ struct ImageDispatcher<I>::SendVisitor : public boost::static_visitor<bool> {
       &image_dispatch_spec->dispatcher_ctx);
   }
 
-  bool operator()(typename ImageDispatchSpec<I>::Discard& discard) const {
+  bool operator()(ImageDispatchSpec::Discard& discard) const {
     return image_dispatch->discard(
       image_dispatch_spec->aio_comp,
       std::move(image_dispatch_spec->image_extents),
@@ -58,7 +58,7 @@ struct ImageDispatcher<I>::SendVisitor : public boost::static_visitor<bool> {
       &image_dispatch_spec->dispatcher_ctx);
   }
 
-  bool operator()(typename ImageDispatchSpec<I>::Write& write) const {
+  bool operator()(ImageDispatchSpec::Write& write) const {
     return image_dispatch->write(
       image_dispatch_spec->aio_comp,
       std::move(image_dispatch_spec->image_extents), std::move(write.bl),
@@ -68,7 +68,7 @@ struct ImageDispatcher<I>::SendVisitor : public boost::static_visitor<bool> {
       &image_dispatch_spec->dispatcher_ctx);
   }
 
-  bool  operator()(typename ImageDispatchSpec<I>::WriteSame& write_same) const {
+  bool  operator()(ImageDispatchSpec::WriteSame& write_same) const {
     return image_dispatch->write_same(
       image_dispatch_spec->aio_comp,
       std::move(image_dispatch_spec->image_extents), std::move(write_same.bl),
@@ -79,7 +79,7 @@ struct ImageDispatcher<I>::SendVisitor : public boost::static_visitor<bool> {
   }
 
   bool  operator()(
-      typename ImageDispatchSpec<I>::CompareAndWrite& compare_and_write) const {
+      ImageDispatchSpec::CompareAndWrite& compare_and_write) const {
     return image_dispatch->compare_and_write(
       image_dispatch_spec->aio_comp,
       std::move(image_dispatch_spec->image_extents),
@@ -91,7 +91,7 @@ struct ImageDispatcher<I>::SendVisitor : public boost::static_visitor<bool> {
       &image_dispatch_spec->dispatcher_ctx);
   }
 
-  bool operator()(typename ImageDispatchSpec<I>::Flush& flush) const {
+  bool operator()(ImageDispatchSpec::Flush& flush) const {
     return image_dispatch->flush(
       image_dispatch_spec->aio_comp, flush.flush_source,
       image_dispatch_spec->parent_trace, image_dispatch_spec->tid,
@@ -211,7 +211,7 @@ void ImageDispatcher<I>::finish(int r, ImageDispatchLayer image_dispatch_layer,
 template <typename I>
 bool ImageDispatcher<I>::send_dispatch(
     ImageDispatchInterface* image_dispatch,
-    ImageDispatchSpec<I>* image_dispatch_spec) {
+    ImageDispatchSpec* image_dispatch_spec) {
   if (image_dispatch_spec->tid == 0) {
     image_dispatch_spec->tid = ++m_next_tid;
   }
index e03f60cd1036e3ad1e8b0896904e68b82f546e1b..bfbea68c9213cd9f202a9cf549058fc1bf9df3b3 100644 (file)
@@ -49,7 +49,7 @@ public:
 protected:
   bool send_dispatch(
     ImageDispatchInterface* image_dispatch,
-    ImageDispatchSpec<ImageCtxT>* image_dispatch_spec) override;
+    ImageDispatchSpec* image_dispatch_spec) override;
 
 private:
   struct SendVisitor;
index d6672de6016411888b2289ad7a56e2e17f0b7ac7..e489524995da36fb02abd3527cbd6e405f027c4b 100644 (file)
@@ -252,7 +252,7 @@ void WriteBlockImageDispatch<I>::flush_io(Context* on_finish) {
   // ensure that all in-flight IO is flushed
   auto aio_comp = AioCompletion::create_and_start(
     on_finish, util::get_image_ctx(m_image_ctx), librbd::io::AIO_TYPE_FLUSH);
-  auto req = ImageDispatchSpec<I>::create_flush(
+  auto req = ImageDispatchSpec::create_flush(
     *m_image_ctx, IMAGE_DISPATCH_LAYER_WRITE_BLOCK, aio_comp,
     FLUSH_SOURCE_INTERNAL, {});
   req->send();
index d90b81fe9740789314f14ac0eb8070392fa303be..57c9a6259d40ec819b4fcfd21e4f1fc0cd8d82f8 100644 (file)
@@ -196,7 +196,7 @@ void ResizeRequest<I>::send_flush_cache() {
     ResizeRequest<I>, &ResizeRequest<I>::handle_flush_cache>(this);
   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(
+  auto req = io::ImageDispatchSpec::create_flush(
     image_ctx, io::IMAGE_DISPATCH_LAYER_INTERNAL_START, aio_comp,
     io::FLUSH_SOURCE_INTERNAL, {});
   req->send();
index 9a31eb91a32ef340b0aedee44c6f327efa8425f7..c9bcf4e014c9153cd8ae1a9d49ed39aa808da49e 100644 (file)
@@ -17,7 +17,6 @@
 #include "librbd/image/GetMetadataRequest.h"
 #include "librbd/image/RefreshRequest.h"
 #include "librbd/image/RefreshParentRequest.h"
-#include "librbd/io/ImageDispatchSpec.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include <arpa/inet.h>
@@ -103,32 +102,6 @@ RefreshParentRequest<MockRefreshImageCtx>* RefreshParentRequest<MockRefreshImage
 
 } // namespace image
 
-namespace io {
-
-template <>
-struct ImageDispatchSpec<librbd::MockRefreshImageCtx> {
-  static ImageDispatchSpec* s_instance;
-  AioCompletion *aio_comp = nullptr;
-
-  static ImageDispatchSpec* create_flush(
-      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;
-  }
-
-  MOCK_CONST_METHOD0(send, void());
-
-  ImageDispatchSpec() {
-    s_instance = this;
-  }
-};
-
-ImageDispatchSpec<librbd::MockRefreshImageCtx>* ImageDispatchSpec<librbd::MockRefreshImageCtx>::s_instance = nullptr;
-
-} // namespace io
 namespace util {
 
 inline ImageCtx *get_image_ctx(librbd::MockRefreshImageCtx *image_ctx) {
@@ -169,7 +142,6 @@ public:
   typedef GetMetadataRequest<MockRefreshImageCtx> MockGetMetadataRequest;
   typedef RefreshRequest<MockRefreshImageCtx> MockRefreshRequest;
   typedef RefreshParentRequest<MockRefreshImageCtx> MockRefreshParentRequest;
-  typedef io::ImageDispatchSpec<librbd::MockRefreshImageCtx> MockIoImageDispatchSpec;
   typedef std::map<std::string, bufferlist> Metadata;
 
   void set_v1_migration_header(ImageCtx *ictx) {
@@ -532,12 +504,15 @@ public:
                   .Times(1);
   }
 
-  void expect_image_flush(MockIoImageDispatchSpec &mock_image_request, int r) {
-    EXPECT_CALL(mock_image_request, send())
-      .WillOnce(Invoke([&mock_image_request, r]() {
-                  mock_image_request.aio_comp->set_request_count(1);
-                  mock_image_request.aio_comp->add_request();
-                  mock_image_request.aio_comp->complete_request(r);
+  void expect_image_flush(MockImageCtx &mock_image_ctx, int r) {
+    EXPECT_CALL(*mock_image_ctx.io_image_dispatcher, send(_))
+      .WillOnce(Invoke([r](io::ImageDispatchSpec* spec) {
+                  ASSERT_TRUE(boost::get<io::ImageDispatchSpec::Flush>(
+                    &spec->request) != nullptr);
+                  spec->dispatch_result = io::DISPATCH_RESULT_COMPLETE;
+                  spec->aio_comp->set_request_count(1);
+                  spec->aio_comp->add_request();
+                  spec->aio_comp->complete_request(r);
                 }));
   }
 
index 90cb6005b1ead6ce2540341cf9c238e1f2a2c870..9b4580e6472f4c012f5b4b3780f185c483ff6067 100644 (file)
@@ -870,7 +870,7 @@ TEST_F(TestJournalReplay, ObjectPosition) {
   C_SaferCond flush_ctx;
   aio_comp = librbd::io::AioCompletion::create_and_start(
     &flush_ctx, ictx, librbd::io::AIO_TYPE_FLUSH);
-  auto req = librbd::io::ImageDispatchSpec<>::create_flush(
+  auto req = librbd::io::ImageDispatchSpec::create_flush(
     *ictx, librbd::io::IMAGE_DISPATCH_LAYER_INTERNAL_START, aio_comp,
     librbd::io::FLUSH_SOURCE_INTERNAL, {});
   req->send();
index 1c7ad1feecd151844c735599247938bcfd6deeb2..249967d9fd27393fb489a4c8fa44222fc9192a64 100644 (file)
@@ -24,7 +24,7 @@ public:
   MOCK_METHOD1(register_dispatch, void(ImageDispatchInterface*));
   MOCK_METHOD2(shut_down_dispatch, void(ImageDispatchLayer, Context*));
 
-  MOCK_METHOD1(send, void(ImageDispatchSpec<>*));
+  MOCK_METHOD1(send, void(ImageDispatchSpec*));
   MOCK_METHOD3(finish, void(int r, ImageDispatchLayer, uint64_t));
 
   MOCK_METHOD1(apply_qos_schedule_tick_min, void(uint64_t));
index fb7d263ba2593e43c7ffe371cc4d4ebd4ca6928e..5464ce1a5f605a67a6926f35f1db80660419b22e 100644 (file)
@@ -9,7 +9,6 @@
 #include "common/bit_vector.hpp"
 #include "librbd/internal.h"
 #include "librbd/ObjectMap.h"
-#include "librbd/io/ImageDispatchSpec.h"
 #include "librbd/operation/ResizeRequest.h"
 #include "librbd/operation/TrimRequest.h"
 #include "gmock/gmock.h"
@@ -25,33 +24,6 @@ inline ImageCtx* get_image_ctx(MockImageCtx* image_ctx) {
 
 } // namespace util
 
-namespace io {
-
-template <>
-struct ImageDispatchSpec<MockImageCtx> {
-  static ImageDispatchSpec* s_instance;
-  AioCompletion *aio_comp = nullptr;
-
-  static ImageDispatchSpec* create_flush(
-      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;
-  }
-
-  MOCK_CONST_METHOD0(send, void());
-
-  ImageDispatchSpec() {
-    s_instance = this;
-  }
-};
-
-ImageDispatchSpec<MockImageCtx>* ImageDispatchSpec<MockImageCtx>::s_instance = nullptr;
-
-} // namespace io
-
 namespace operation {
 
 template <>
@@ -98,7 +70,6 @@ class TestMockOperationResizeRequest : public TestMockFixture {
 public:
   typedef ResizeRequest<MockImageCtx> MockResizeRequest;
   typedef TrimRequest<MockImageCtx> MockTrimRequest;
-  typedef io::ImageDispatchSpec<MockImageCtx> MockIoImageDispatchSpec;
 
   void expect_block_writes(MockImageCtx &mock_image_ctx, int r) {
     EXPECT_CALL(*mock_image_ctx.io_image_dispatcher, block_writes(_))
@@ -153,12 +124,13 @@ public:
                   .WillOnce(FinishRequest(&mock_trim_request, r, &mock_image_ctx));
   }
 
-  void expect_flush_cache(MockImageCtx &mock_image_ctx,
-                          MockIoImageDispatchSpec& mock_io_image_dispatch_spec,
-                          int r) {
-    EXPECT_CALL(mock_io_image_dispatch_spec, send())
-      .WillOnce(Invoke([&mock_image_ctx, &mock_io_image_dispatch_spec, r]() {
-                  auto aio_comp = mock_io_image_dispatch_spec.s_instance->aio_comp;
+  void expect_flush_cache(MockImageCtx &mock_image_ctx, int r) {
+    EXPECT_CALL(*mock_image_ctx.io_image_dispatcher, send(_))
+      .WillOnce(Invoke([&mock_image_ctx, r](io::ImageDispatchSpec* spec) {
+                  ASSERT_TRUE(boost::get<io::ImageDispatchSpec::Flush>(
+                    &spec->request) != nullptr);
+                  spec->dispatch_result = io::DISPATCH_RESULT_COMPLETE;
+                  auto aio_comp = spec->aio_comp;
                   auto ctx = new LambdaContext([aio_comp](int r) {
                     if (r < 0) {
                       aio_comp->fail(r);
@@ -258,8 +230,7 @@ TEST_F(TestMockOperationResizeRequest, ShrinkSuccess) {
   expect_unblock_writes(mock_image_ctx);
 
   MockTrimRequest mock_trim_request;
-  MockIoImageDispatchSpec mock_io_image_dispatch_spec;
-  expect_flush_cache(mock_image_ctx, mock_io_image_dispatch_spec, 0);
+  expect_flush_cache(mock_image_ctx, 0);
   expect_invalidate_cache(mock_image_ctx, 0);
   expect_trim(mock_image_ctx, mock_trim_request, 0);
   expect_block_writes(mock_image_ctx, 0);
@@ -321,8 +292,7 @@ TEST_F(TestMockOperationResizeRequest, TrimError) {
   expect_unblock_writes(mock_image_ctx);
 
   MockTrimRequest mock_trim_request;
-  MockIoImageDispatchSpec mock_io_image_dispatch_spec;
-  expect_flush_cache(mock_image_ctx, mock_io_image_dispatch_spec, 0);
+  expect_flush_cache(mock_image_ctx, 0);
   expect_invalidate_cache(mock_image_ctx, -EBUSY);
   expect_trim(mock_image_ctx, mock_trim_request, -EINVAL);
   expect_commit_op_event(mock_image_ctx, -EINVAL);
@@ -347,8 +317,7 @@ TEST_F(TestMockOperationResizeRequest, FlushCacheError) {
   expect_unblock_writes(mock_image_ctx);
 
   MockTrimRequest mock_trim_request;
-  MockIoImageDispatchSpec mock_io_image_dispatch_spec;
-  expect_flush_cache(mock_image_ctx, mock_io_image_dispatch_spec, -EINVAL);
+  expect_flush_cache(mock_image_ctx, -EINVAL);
   expect_commit_op_event(mock_image_ctx, -EINVAL);
   ASSERT_EQ(-EINVAL, when_resize(mock_image_ctx, ictx->size / 2, true, 0, false));
 }
@@ -371,8 +340,7 @@ TEST_F(TestMockOperationResizeRequest, InvalidateCacheError) {
   expect_unblock_writes(mock_image_ctx);
 
   MockTrimRequest mock_trim_request;
-  MockIoImageDispatchSpec mock_io_image_dispatch_spec;
-  expect_flush_cache(mock_image_ctx, mock_io_image_dispatch_spec, 0);
+  expect_flush_cache(mock_image_ctx, 0);
   expect_invalidate_cache(mock_image_ctx, -EINVAL);
   expect_commit_op_event(mock_image_ctx, -EINVAL);
   ASSERT_EQ(-EINVAL, when_resize(mock_image_ctx, ictx->size / 2, true, 0, false));
@@ -395,8 +363,7 @@ TEST_F(TestMockOperationResizeRequest, PostBlockWritesError) {
   expect_unblock_writes(mock_image_ctx);
 
   MockTrimRequest mock_trim_request;
-  MockIoImageDispatchSpec mock_io_image_dispatch_spec;
-  expect_flush_cache(mock_image_ctx, mock_io_image_dispatch_spec, 0);
+  expect_flush_cache(mock_image_ctx, 0);
   expect_invalidate_cache(mock_image_ctx, 0);
   expect_trim(mock_image_ctx, mock_trim_request, 0);
   expect_block_writes(mock_image_ctx, -EINVAL);
index 76055e698cab5c594382267c9f4f4013c65c3ad2..eccf085ea27db3f9241744bb08a2035572693a14 100644 (file)
@@ -153,7 +153,7 @@ int TestFixture::flush_writeback_cache(librbd::ImageCtx *image_ctx) {
     C_SaferCond 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(
+    auto req = librbd::io::ImageDispatchSpec::create_flush(
       *image_ctx, librbd::io::IMAGE_DISPATCH_LAYER_INTERNAL_START, aio_comp,
       librbd::io::FLUSH_SOURCE_INTERNAL, {});
     req->send();
index 646534ccbd79afb9afc3b524deef2cc6b37eff72..93349ca11639d62cee80a54631923c7a4eacfbc1 100644 (file)
@@ -36,7 +36,7 @@ int flush(librbd::ImageCtx *image_ctx) {
   C_SaferCond 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(
+  auto req = librbd::io::ImageDispatchSpec::create_flush(
     *image_ctx, librbd::io::IMAGE_DISPATCH_LAYER_INTERNAL_START, aio_comp,
     librbd::io::FLUSH_SOURCE_INTERNAL, {});
   req->send();