From: Jason Dillaman Date: Mon, 31 Aug 2020 20:04:34 +0000 (-0400) Subject: librbd: remove unncessary templating from io::ImageDispatchSpec X-Git-Tag: v16.1.0~1032^2~13 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=052a0842d83a49a64c9679673beda4f2677ce2a4;p=ceph.git librbd: remove unncessary templating from io::ImageDispatchSpec 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 --- diff --git a/src/librbd/api/DiffIterate.cc b/src/librbd/api/DiffIterate.cc index b34c6ff4afeb..39b7cdea91f0 100644 --- a/src/librbd/api/DiffIterate.cc +++ b/src/librbd/api/DiffIterate.cc @@ -249,7 +249,7 @@ int DiffIterate::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::create_flush( + auto req = io::ImageDispatchSpec::create_flush( *ictx, io::IMAGE_DISPATCH_LAYER_INTERNAL_START, aio_comp, io::FLUSH_SOURCE_INTERNAL, {}); req->send(); diff --git a/src/librbd/api/Io.cc b/src/librbd/api/Io.cc index 76d43c4a344f..7c2d10717294 100644 --- a/src/librbd/api/Io.cc +++ b/src/librbd/api/Io.cc @@ -230,7 +230,7 @@ void Io::aio_read(I &image_ctx, io::AioCompletion *aio_comp, uint64_t off, return; } - auto req = io::ImageDispatchSpec::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::aio_write(I &image_ctx, io::AioCompletion *aio_comp, uint64_t off, return; } - auto req = io::ImageDispatchSpec::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::aio_discard(I &image_ctx, io::AioCompletion *aio_comp, uint64_t off, return; } - auto req = io::ImageDispatchSpec::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::aio_write_same(I &image_ctx, io::AioCompletion *aio_comp, return; } - auto req = io::ImageDispatchSpec::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::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::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::aio_write_zeroes(I& image_ctx, io::AioCompletion *aio_comp, bufferlist bl; bl.append_zero(data_length); - auto req = io::ImageDispatchSpec::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::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::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::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::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::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::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::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::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::aio_compare_and_write(I &image_ctx, io::AioCompletion *aio_comp, return; } - auto req = io::ImageDispatchSpec::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::aio_flush(I &image_ctx, io::AioCompletion *aio_comp, return; } - auto req = io::ImageDispatchSpec::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(); diff --git a/src/librbd/exclusive_lock/ImageDispatch.cc b/src/librbd/exclusive_lock/ImageDispatch.cc index 66dda453bf3d..87007c60a73f 100644 --- a/src/librbd/exclusive_lock/ImageDispatch.cc +++ b/src/librbd/exclusive_lock/ImageDispatch.cc @@ -70,7 +70,7 @@ void ImageDispatch::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::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(); diff --git a/src/librbd/image/CloseRequest.cc b/src/librbd/image/CloseRequest.cc index c12cecd52d71..04f8b6f630b5 100644 --- a/src/librbd/image/CloseRequest.cc +++ b/src/librbd/image/CloseRequest.cc @@ -103,7 +103,7 @@ void CloseRequest::send_flush() { CloseRequest, &CloseRequest::handle_flush>(this); auto aio_comp = io::AioCompletion::create_and_start(ctx, m_image_ctx, io::AIO_TYPE_FLUSH); - auto req = io::ImageDispatchSpec::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(); diff --git a/src/librbd/image/RefreshRequest.cc b/src/librbd/image/RefreshRequest.cc index 251c89bfebf3..735d701b61a1 100644 --- a/src/librbd/image/RefreshRequest.cc +++ b/src/librbd/image/RefreshRequest.cc @@ -1245,7 +1245,7 @@ Context *RefreshRequest::send_flush_aio() { RefreshRequest, &RefreshRequest::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::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(); diff --git a/src/librbd/io/ImageDispatchInterface.h b/src/librbd/io/ImageDispatchInterface.h index d96cb924b92c..ffe53d0f9c4f 100644 --- a/src/librbd/io/ImageDispatchInterface.h +++ b/src/librbd/io/ImageDispatchInterface.h @@ -17,11 +17,11 @@ namespace librbd { namespace io { struct AioCompletion; -template struct ImageDispatchSpec; +struct ImageDispatchSpec; struct ImageDispatchInterface { typedef ImageDispatchLayer DispatchLayer; - typedef ImageDispatchSpec DispatchSpec; + typedef ImageDispatchSpec DispatchSpec; virtual ~ImageDispatchInterface() { } diff --git a/src/librbd/io/ImageDispatchSpec.cc b/src/librbd/io/ImageDispatchSpec.cc index 2ca0d82127b1..9b3638611919 100644 --- a/src/librbd/io/ImageDispatchSpec.cc +++ b/src/librbd/io/ImageDispatchSpec.cc @@ -11,8 +11,7 @@ namespace librbd { namespace io { -template -void ImageDispatchSpec::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::C_Dispatcher::complete(int r) { } } -template -void ImageDispatchSpec::C_Dispatcher::finish(int r) { +void ImageDispatchSpec::C_Dispatcher::finish(int r) { image_dispatch_spec->finish(r); } -template -struct ImageDispatchSpec::IsWriteOpVisitor - : public boost::static_visitor { - bool operator()(const Read&) const { - return false; - } - - template - bool operator()(const T&) const { - return true; - } -}; - -template -void ImageDispatchSpec::send() { +void ImageDispatchSpec::send() { image_dispatcher->send(this); } -template -void ImageDispatchSpec::finish(int r) { +void ImageDispatchSpec::finish(int r) { image_dispatcher->finish(r, dispatch_layer, tid); delete this; } -template -void ImageDispatchSpec::fail(int r) { +void ImageDispatchSpec::fail(int r) { dispatch_result = DISPATCH_RESULT_COMPLETE; aio_comp->fail(r); } -template -uint64_t ImageDispatchSpec::extents_length() { - uint64_t length = 0; - auto &extents = this->image_extents; - - for (auto &extent : extents) { - length += extent.second; - } - return length; -} - -template -const Extents& ImageDispatchSpec::get_image_extents() const { - return this->image_extents; -} - -template -uint64_t ImageDispatchSpec::get_tid() { - return this->tid; -} - -template -bool ImageDispatchSpec::is_write_op() const { - return boost::apply_visitor(IsWriteOpVisitor(), request); -} - -template -void ImageDispatchSpec::start_op() { - tid = 0; - aio_comp->start_op(); -} - } // namespace io } // namespace librbd - -template class librbd::io::ImageDispatchSpec; diff --git a/src/librbd/io/ImageDispatchSpec.h b/src/librbd/io/ImageDispatchSpec.h index 1c12f3afcb48..7dccf94bc297 100644 --- a/src/librbd/io/ImageDispatchSpec.h +++ b/src/librbd/io/ImageDispatchSpec.h @@ -22,7 +22,6 @@ namespace io { struct ImageDispatcherInterface; -template 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 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 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 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 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 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 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; - #endif // CEPH_LIBRBD_IO_IMAGE_DISPATCH_SPEC_H diff --git a/src/librbd/io/ImageDispatcher.cc b/src/librbd/io/ImageDispatcher.cc index c060d5c779a9..9a37029e615d 100644 --- a/src/librbd/io/ImageDispatcher.cc +++ b/src/librbd/io/ImageDispatcher.cc @@ -28,15 +28,15 @@ namespace io { template struct ImageDispatcher::SendVisitor : public boost::static_visitor { ImageDispatchInterface* image_dispatch; - ImageDispatchSpec* image_dispatch_spec; + ImageDispatchSpec* image_dispatch_spec; SendVisitor(ImageDispatchInterface* image_dispatch, - ImageDispatchSpec* image_dispatch_spec) + ImageDispatchSpec* image_dispatch_spec) : image_dispatch(image_dispatch), image_dispatch_spec(image_dispatch_spec) { } - bool operator()(typename ImageDispatchSpec::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::SendVisitor : public boost::static_visitor { &image_dispatch_spec->dispatcher_ctx); } - bool operator()(typename ImageDispatchSpec::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::SendVisitor : public boost::static_visitor { &image_dispatch_spec->dispatcher_ctx); } - bool operator()(typename ImageDispatchSpec::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::SendVisitor : public boost::static_visitor { &image_dispatch_spec->dispatcher_ctx); } - bool operator()(typename ImageDispatchSpec::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::SendVisitor : public boost::static_visitor { } bool operator()( - typename ImageDispatchSpec::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::SendVisitor : public boost::static_visitor { &image_dispatch_spec->dispatcher_ctx); } - bool operator()(typename ImageDispatchSpec::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::finish(int r, ImageDispatchLayer image_dispatch_layer, template bool ImageDispatcher::send_dispatch( ImageDispatchInterface* image_dispatch, - ImageDispatchSpec* image_dispatch_spec) { + ImageDispatchSpec* image_dispatch_spec) { if (image_dispatch_spec->tid == 0) { image_dispatch_spec->tid = ++m_next_tid; } diff --git a/src/librbd/io/ImageDispatcher.h b/src/librbd/io/ImageDispatcher.h index e03f60cd1036..bfbea68c9213 100644 --- a/src/librbd/io/ImageDispatcher.h +++ b/src/librbd/io/ImageDispatcher.h @@ -49,7 +49,7 @@ public: protected: bool send_dispatch( ImageDispatchInterface* image_dispatch, - ImageDispatchSpec* image_dispatch_spec) override; + ImageDispatchSpec* image_dispatch_spec) override; private: struct SendVisitor; diff --git a/src/librbd/io/WriteBlockImageDispatch.cc b/src/librbd/io/WriteBlockImageDispatch.cc index d6672de60164..e489524995da 100644 --- a/src/librbd/io/WriteBlockImageDispatch.cc +++ b/src/librbd/io/WriteBlockImageDispatch.cc @@ -252,7 +252,7 @@ void WriteBlockImageDispatch::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::create_flush( + auto req = ImageDispatchSpec::create_flush( *m_image_ctx, IMAGE_DISPATCH_LAYER_WRITE_BLOCK, aio_comp, FLUSH_SOURCE_INTERNAL, {}); req->send(); diff --git a/src/librbd/operation/ResizeRequest.cc b/src/librbd/operation/ResizeRequest.cc index d90b81fe9740..57c9a6259d40 100644 --- a/src/librbd/operation/ResizeRequest.cc +++ b/src/librbd/operation/ResizeRequest.cc @@ -196,7 +196,7 @@ void ResizeRequest::send_flush_cache() { ResizeRequest, &ResizeRequest::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::create_flush( + auto req = io::ImageDispatchSpec::create_flush( image_ctx, io::IMAGE_DISPATCH_LAYER_INTERNAL_START, aio_comp, io::FLUSH_SOURCE_INTERNAL, {}); req->send(); diff --git a/src/test/librbd/image/test_mock_RefreshRequest.cc b/src/test/librbd/image/test_mock_RefreshRequest.cc index 9a31eb91a32e..c9bcf4e014c9 100644 --- a/src/test/librbd/image/test_mock_RefreshRequest.cc +++ b/src/test/librbd/image/test_mock_RefreshRequest.cc @@ -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 @@ -103,32 +102,6 @@ RefreshParentRequest* RefreshParentRequest -struct ImageDispatchSpec { - 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* ImageDispatchSpec::s_instance = nullptr; - -} // namespace io namespace util { inline ImageCtx *get_image_ctx(librbd::MockRefreshImageCtx *image_ctx) { @@ -169,7 +142,6 @@ public: typedef GetMetadataRequest MockGetMetadataRequest; typedef RefreshRequest MockRefreshRequest; typedef RefreshParentRequest MockRefreshParentRequest; - typedef io::ImageDispatchSpec MockIoImageDispatchSpec; typedef std::map 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( + &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); })); } diff --git a/src/test/librbd/journal/test_Replay.cc b/src/test/librbd/journal/test_Replay.cc index 90cb6005b1ea..9b4580e6472f 100644 --- a/src/test/librbd/journal/test_Replay.cc +++ b/src/test/librbd/journal/test_Replay.cc @@ -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(); diff --git a/src/test/librbd/mock/io/MockImageDispatcher.h b/src/test/librbd/mock/io/MockImageDispatcher.h index 1c7ad1feecd1..249967d9fd27 100644 --- a/src/test/librbd/mock/io/MockImageDispatcher.h +++ b/src/test/librbd/mock/io/MockImageDispatcher.h @@ -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)); diff --git a/src/test/librbd/operation/test_mock_ResizeRequest.cc b/src/test/librbd/operation/test_mock_ResizeRequest.cc index fb7d263ba259..5464ce1a5f60 100644 --- a/src/test/librbd/operation/test_mock_ResizeRequest.cc +++ b/src/test/librbd/operation/test_mock_ResizeRequest.cc @@ -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 { - 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* ImageDispatchSpec::s_instance = nullptr; - -} // namespace io - namespace operation { template <> @@ -98,7 +70,6 @@ class TestMockOperationResizeRequest : public TestMockFixture { public: typedef ResizeRequest MockResizeRequest; typedef TrimRequest MockTrimRequest; - typedef io::ImageDispatchSpec 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( + &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); diff --git a/src/test/librbd/test_fixture.cc b/src/test/librbd/test_fixture.cc index 76055e698cab..eccf085ea27d 100644 --- a/src/test/librbd/test_fixture.cc +++ b/src/test/librbd/test_fixture.cc @@ -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(); diff --git a/src/test/rbd_mirror/test_ImageSync.cc b/src/test/rbd_mirror/test_ImageSync.cc index 646534ccbd79..93349ca11639 100644 --- a/src/test/rbd_mirror/test_ImageSync.cc +++ b/src/test/rbd_mirror/test_ImageSync.cc @@ -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();