From: Jason Dillaman Date: Fri, 1 May 2020 01:37:56 +0000 (-0400) Subject: librbd: init and shut down image IO dispatch layer X-Git-Tag: v16.1.0~2318^2~19 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ce6004afce14bd9588b6aa5660e3e515cfbddc65;p=ceph.git librbd: init and shut down image IO dispatch layer Signed-off-by: Jason Dillaman --- diff --git a/src/librbd/ImageCtx.cc b/src/librbd/ImageCtx.cc index 1a583aeeb51bb..d5f5e5516af4a 100644 --- a/src/librbd/ImageCtx.cc +++ b/src/librbd/ImageCtx.cc @@ -28,6 +28,7 @@ #include "librbd/exclusive_lock/StandardPolicy.h" #include "librbd/io/AioCompletion.h" #include "librbd/io/AsyncOperation.h" +#include "librbd/io/ImageDispatcher.h" #include "librbd/io/ImageRequestWQ.h" #include "librbd/io/ObjectDispatcher.h" #include "librbd/journal/StandardPolicy.h" @@ -141,6 +142,7 @@ public: this, "librbd::io_work_queue", cct->_conf.get_val("rbd_op_thread_timeout"), thread_pool); + io_image_dispatcher = new io::ImageDispatcher(this); io_object_dispatcher = new io::ObjectDispatcher(this); if (cct->_conf.get_val("rbd_auto_exclusive_lock_until_manual_request")) { @@ -176,6 +178,7 @@ public: io_work_queue->drain(); delete io_object_dispatcher; + delete io_image_dispatcher; delete journal_policy; delete exclusive_lock_policy; diff --git a/src/librbd/ImageCtx.h b/src/librbd/ImageCtx.h index 74feaafd34af3..ef930f57c7812 100644 --- a/src/librbd/ImageCtx.h +++ b/src/librbd/ImageCtx.h @@ -59,6 +59,7 @@ namespace librbd { class AsyncOperation; template class CopyupRequest; template class ImageRequestWQ; + struct ImageDispatcherInterface; struct ObjectDispatcherInterface; } namespace journal { struct Policy; } @@ -181,6 +182,7 @@ namespace librbd { xlist*> resize_reqs; io::ImageRequestWQ *io_work_queue; + io::ImageDispatcherInterface *io_image_dispatcher = nullptr; io::ObjectDispatcherInterface *io_object_dispatcher = nullptr; ContextWQ *op_work_queue; diff --git a/src/librbd/image/CloseRequest.cc b/src/librbd/image/CloseRequest.cc index 998459c2cde09..5dba010b4befe 100644 --- a/src/librbd/image/CloseRequest.cc +++ b/src/librbd/image/CloseRequest.cc @@ -11,6 +11,7 @@ #include "librbd/ObjectMap.h" #include "librbd/Utils.h" #include "librbd/io/AioCompletion.h" +#include "librbd/io/ImageDispatcher.h" #include "librbd/io/ImageDispatchSpec.h" #include "librbd/io/ImageRequestWQ.h" #include "librbd/io/ObjectDispatcherInterface.h" @@ -251,6 +252,29 @@ void CloseRequest::handle_shut_down_object_dispatcher(int r) { lderr(cct) << "failed to shut down object dispatcher: " << cpp_strerror(r) << dendl; } + send_shut_down_image_dispatcher(); +} + +template +void CloseRequest::send_shut_down_image_dispatcher() { + CephContext *cct = m_image_ctx->cct; + ldout(cct, 10) << this << " " << __func__ << dendl; + + m_image_ctx->io_image_dispatcher->shut_down(create_context_callback< + CloseRequest, + &CloseRequest::handle_shut_down_image_dispatcher>(this)); +} + +template +void CloseRequest::handle_shut_down_image_dispatcher(int r) { + CephContext *cct = m_image_ctx->cct; + ldout(cct, 10) << this << " " << __func__ << ": r=" << r << dendl; + + save_result(r); + if (r < 0) { + lderr(cct) << "failed to shut down image dispatcher: " + << cpp_strerror(r) << dendl; + } send_flush_op_work_queue(); } diff --git a/src/librbd/image/CloseRequest.h b/src/librbd/image/CloseRequest.h index fd101beedb331..95c02bb5de977 100644 --- a/src/librbd/image/CloseRequest.h +++ b/src/librbd/image/CloseRequest.h @@ -53,6 +53,9 @@ private: * SHUT_DOWN_OBJECT_DISPATCHER * | * v + * SHUT_DOWN_IMAGE_DISPATCHER + * | + * v * FLUSH_OP_WORK_QUEUE * | * v (skip if no parent) @@ -100,6 +103,9 @@ private: void send_shut_down_object_dispatcher(); void handle_shut_down_object_dispatcher(int r); + void send_shut_down_image_dispatcher(); + void handle_shut_down_image_dispatcher(int r); + void send_flush_op_work_queue(); void handle_flush_op_work_queue(int r); diff --git a/src/librbd/io/ImageDispatchSpec.h b/src/librbd/io/ImageDispatchSpec.h index 90eddb616d13c..f26a297e20727 100644 --- a/src/librbd/io/ImageDispatchSpec.h +++ b/src/librbd/io/ImageDispatchSpec.h @@ -215,10 +215,11 @@ private: 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), - aio_comp(aio_comp), image_extents(std::move(image_extents)), - request(std::move(request)), op_flags(op_flags), - parent_trace(parent_trace), tid(tid), m_image_ctx(image_ctx) { + : dispatcher_ctx(this), image_dispatcher(image_ctx.io_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), + m_image_ctx(image_ctx) { aio_comp->get(); } diff --git a/src/test/librbd/mock/MockImageCtx.h b/src/test/librbd/mock/MockImageCtx.h index dcd620abd76c7..1a35b2933f178 100644 --- a/src/test/librbd/mock/MockImageCtx.h +++ b/src/test/librbd/mock/MockImageCtx.h @@ -13,6 +13,7 @@ #include "test/librbd/mock/MockObjectMap.h" #include "test/librbd/mock/MockOperations.h" #include "test/librbd/mock/MockReadahead.h" +#include "test/librbd/mock/io/MockImageDispatcher.h" #include "test/librbd/mock/io/MockImageRequestWQ.h" #include "test/librbd/mock/io/MockObjectDispatcher.h" #include "common/RWLock.h" @@ -84,6 +85,7 @@ struct MockImageCtx { group_spec(image_ctx.group_spec), layout(image_ctx.layout), io_work_queue(new io::MockImageRequestWQ()), + io_image_dispatcher(new io::MockImageDispatcher()), io_object_dispatcher(new io::MockObjectDispatcher()), op_work_queue(new MockContextWQ()), readahead_max_bytes(image_ctx.readahead_max_bytes), @@ -126,6 +128,7 @@ struct MockImageCtx { delete image_watcher; delete op_work_queue; delete io_work_queue; + delete io_image_dispatcher; delete io_object_dispatcher; } @@ -282,6 +285,7 @@ struct MockImageCtx { std::map*> copyup_list; io::MockImageRequestWQ *io_work_queue; + io::MockImageDispatcher *io_image_dispatcher; io::MockObjectDispatcher *io_object_dispatcher; MockContextWQ *op_work_queue; diff --git a/src/test/librbd/mock/io/MockImageDispatcher.h b/src/test/librbd/mock/io/MockImageDispatcher.h new file mode 100644 index 0000000000000..5eefde7156a6a --- /dev/null +++ b/src/test/librbd/mock/io/MockImageDispatcher.h @@ -0,0 +1,33 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#ifndef CEPH_TEST_LIBRBD_MOCK_IO_IMAGE_DISPATCHER_H +#define CEPH_TEST_LIBRBD_MOCK_IO_IMAGE_DISPATCHER_H + +#include "gmock/gmock.h" +#include "include/Context.h" +#include "librbd/io/ImageDispatcher.h" +#include "librbd/io/ImageDispatchSpec.h" +#include "librbd/io/Types.h" + +class Context; + +namespace librbd { +namespace io { + +struct ImageDispatchInterface; + +struct MockImageDispatcher : public ImageDispatcherInterface { +public: + MOCK_METHOD1(shut_down, void(Context*)); + + MOCK_METHOD1(register_dispatch, void(ImageDispatchInterface*)); + MOCK_METHOD2(shut_down_dispatch, void(ImageDispatchLayer, Context*)); + + MOCK_METHOD1(send, void(ImageDispatchSpec<>*)); +}; + +} // namespace io +} // namespace librbd + +#endif // CEPH_TEST_LIBRBD_MOCK_IO_IMAGE_DISPATCHER_H