From: Jason Dillaman Date: Thu, 4 Apr 2019 20:46:37 +0000 (-0400) Subject: librbd: pass journal tid through flush object dispatch spec X-Git-Tag: v15.1.0~2945^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6c35ca969b06c24707d3e56dd0545b258e4f9e8a;p=ceph.git librbd: pass journal tid through flush object dispatch spec This permits moving the journal flush and commit logic down to the journal object dispatch layer. Signed-off-by: Jason Dillaman --- diff --git a/src/librbd/cache/ObjectCacherObjectDispatch.cc b/src/librbd/cache/ObjectCacherObjectDispatch.cc index 25a05a2f50d9..adf6b31d90b7 100644 --- a/src/librbd/cache/ObjectCacherObjectDispatch.cc +++ b/src/librbd/cache/ObjectCacherObjectDispatch.cc @@ -347,8 +347,8 @@ bool ObjectCacherObjectDispatch::compare_and_write( template bool ObjectCacherObjectDispatch::flush( io::FlushSource flush_source, const ZTracer::Trace &parent_trace, - io::DispatchResult* dispatch_result, Context** on_finish, - Context* on_dispatched) { + uint64_t* journal_tid, io::DispatchResult* dispatch_result, + Context** on_finish, Context* on_dispatched) { auto cct = m_image_ctx->cct; ldout(cct, 20) << dendl; diff --git a/src/librbd/cache/ObjectCacherObjectDispatch.h b/src/librbd/cache/ObjectCacherObjectDispatch.h index 19394e43f711..e01c7f700550 100644 --- a/src/librbd/cache/ObjectCacherObjectDispatch.h +++ b/src/librbd/cache/ObjectCacherObjectDispatch.h @@ -82,8 +82,8 @@ public: bool flush( io::FlushSource flush_source, const ZTracer::Trace &parent_trace, - io::DispatchResult* dispatch_result, Context** on_finish, - Context* on_dispatched) override; + uint64_t* journal_tid, io::DispatchResult* dispatch_result, + Context** on_finish, Context* on_dispatched) override; bool invalidate_cache(Context* on_finish) override; bool reset_existence_cache(Context* on_finish) override; diff --git a/src/librbd/io/ImageRequest.cc b/src/librbd/io/ImageRequest.cc index 5a74fabf0e96..b4c4b794db54 100644 --- a/src/librbd/io/ImageRequest.cc +++ b/src/librbd/io/ImageRequest.cc @@ -614,30 +614,21 @@ void ImageFlushRequest::send_request() { // ensure no locks are held when flush is complete ctx = librbd::util::create_async_context_callback(image_ctx, ctx); + uint64_t journal_tid = 0; if (journaling) { // in-flight ops are flushed prior to closing the journal - uint64_t journal_tid = image_ctx.journal->append_io_event( + ceph_assert(image_ctx.journal != NULL); + journal_tid = image_ctx.journal->append_io_event( journal::EventEntry(journal::AioFlushEvent()), 0, 0, false, 0); - - ctx = new FunctionContext( - [&image_ctx, journal_tid, ctx](int r) { - image_ctx.journal->commit_io_event(journal_tid, r); - ctx->complete(r); - }); - ctx = new FunctionContext( - [&image_ctx, journal_tid, ctx](int r) { - image_ctx.journal->flush_event(journal_tid, ctx); - }); - } else { - // flush rbd cache only when journaling is not enabled - auto object_dispatch_spec = ObjectDispatchSpec::create_flush( - &image_ctx, OBJECT_DISPATCH_LAYER_NONE, m_flush_source, this->m_trace, - ctx); - ctx = new FunctionContext([object_dispatch_spec](int r) { - object_dispatch_spec->send(); - }); } + auto object_dispatch_spec = ObjectDispatchSpec::create_flush( + &image_ctx, OBJECT_DISPATCH_LAYER_NONE, m_flush_source, journal_tid, + this->m_trace, ctx); + ctx = new FunctionContext([object_dispatch_spec](int r) { + object_dispatch_spec->send(); + }); + // ensure all in-flight IOs are settled if non-user flush request image_ctx.flush_async_operations(ctx); aio_comp->start_op(true); diff --git a/src/librbd/io/ObjectDispatch.h b/src/librbd/io/ObjectDispatch.h index 32e8272d739e..5957b2766113 100644 --- a/src/librbd/io/ObjectDispatch.h +++ b/src/librbd/io/ObjectDispatch.h @@ -74,8 +74,8 @@ public: bool flush( FlushSource flush_source, const ZTracer::Trace &parent_trace, - DispatchResult* dispatch_result, Context** on_finish, - Context* on_dispatched) override { + uint64_t* journal_tid, DispatchResult* dispatch_result, + Context** on_finish, Context* on_dispatched) override { return false; } diff --git a/src/librbd/io/ObjectDispatchInterface.h b/src/librbd/io/ObjectDispatchInterface.h index fddf0db1475a..a3d815c9c5f6 100644 --- a/src/librbd/io/ObjectDispatchInterface.h +++ b/src/librbd/io/ObjectDispatchInterface.h @@ -68,8 +68,8 @@ struct ObjectDispatchInterface { virtual bool flush( FlushSource flush_source, const ZTracer::Trace &parent_trace, - DispatchResult* dispatch_result, Context** on_finish, - Context* on_dispatched) = 0; + uint64_t* journal_tid, DispatchResult* dispatch_result, + Context** on_finish, Context* on_dispatched) = 0; virtual bool invalidate_cache(Context* on_finish) = 0; virtual bool reset_existence_cache(Context* on_finish) = 0; diff --git a/src/librbd/io/ObjectDispatchSpec.h b/src/librbd/io/ObjectDispatchSpec.h index a26d89fe4560..8580796cfe11 100644 --- a/src/librbd/io/ObjectDispatchSpec.h +++ b/src/librbd/io/ObjectDispatchSpec.h @@ -127,8 +127,10 @@ public: struct FlushRequest { FlushSource flush_source; + uint64_t journal_tid; - FlushRequest(FlushSource flush_source) : flush_source(flush_source) { + FlushRequest(FlushSource flush_source, uint64_t journal_tid) + : flush_source(flush_source), journal_tid(journal_tid) { } }; @@ -235,11 +237,11 @@ public: template static ObjectDispatchSpec* create_flush( ImageCtxT* image_ctx, ObjectDispatchLayer object_dispatch_layer, - FlushSource flush_source, const ZTracer::Trace &parent_trace, - Context *on_finish) { + FlushSource flush_source, uint64_t journal_tid, + const ZTracer::Trace &parent_trace, Context *on_finish) { return new ObjectDispatchSpec(image_ctx->io_object_dispatcher, object_dispatch_layer, - FlushRequest{flush_source}, 0, + FlushRequest{flush_source, journal_tid}, 0, parent_trace, on_finish); } diff --git a/src/librbd/io/ObjectDispatcher.cc b/src/librbd/io/ObjectDispatcher.cc index befc075062ca..6285737a81a9 100644 --- a/src/librbd/io/ObjectDispatcher.cc +++ b/src/librbd/io/ObjectDispatcher.cc @@ -167,6 +167,7 @@ struct ObjectDispatcher::SendVisitor : public boost::static_visitor { bool operator()(ObjectDispatchSpec::FlushRequest& flush) const { return object_dispatch->flush( flush.flush_source, object_dispatch_spec->parent_trace, + &flush.journal_tid, &object_dispatch_spec->dispatch_result, &object_dispatch_spec->dispatcher_ctx.on_finish, &object_dispatch_spec->dispatcher_ctx); diff --git a/src/librbd/io/SimpleSchedulerObjectDispatch.cc b/src/librbd/io/SimpleSchedulerObjectDispatch.cc index a76abf903729..687f8670bd6f 100644 --- a/src/librbd/io/SimpleSchedulerObjectDispatch.cc +++ b/src/librbd/io/SimpleSchedulerObjectDispatch.cc @@ -311,8 +311,8 @@ bool SimpleSchedulerObjectDispatch::compare_and_write( template bool SimpleSchedulerObjectDispatch::flush( io::FlushSource flush_source, const ZTracer::Trace &parent_trace, - io::DispatchResult* dispatch_result, Context** on_finish, - Context* on_dispatched) { + uint64_t* journal_tid, io::DispatchResult* dispatch_result, + Context** on_finish, Context* on_dispatched) { auto cct = m_image_ctx->cct; ldout(cct, 20) << dendl; diff --git a/src/librbd/io/SimpleSchedulerObjectDispatch.h b/src/librbd/io/SimpleSchedulerObjectDispatch.h index 6cfd4f626850..f15966c308ae 100644 --- a/src/librbd/io/SimpleSchedulerObjectDispatch.h +++ b/src/librbd/io/SimpleSchedulerObjectDispatch.h @@ -89,8 +89,8 @@ public: bool flush( io::FlushSource flush_source, const ZTracer::Trace &parent_trace, - io::DispatchResult* dispatch_result, Context** on_finish, - Context* on_dispatched) override; + uint64_t* journal_tid, io::DispatchResult* dispatch_result, + Context** on_finish, Context* on_dispatched) override; bool invalidate_cache(Context* on_finish) override { return false; diff --git a/src/librbd/journal/ObjectDispatch.cc b/src/librbd/journal/ObjectDispatch.cc index 737f5efe0f4e..ebe09fe7e195 100644 --- a/src/librbd/journal/ObjectDispatch.cc +++ b/src/librbd/journal/ObjectDispatch.cc @@ -174,6 +174,32 @@ bool ObjectDispatch::compare_and_write( return true; } +template +bool ObjectDispatch::flush( + io::FlushSource flush_source, const ZTracer::Trace &parent_trace, + uint64_t* journal_tid, io::DispatchResult* dispatch_result, + Context** on_finish, Context* on_dispatched) { + if (*journal_tid == 0) { + // non-journaled IO + return false; + } + + auto cct = m_image_ctx->cct; + ldout(cct, 20) << dendl; + + auto ctx = *on_finish; + *on_finish = new FunctionContext( + [image_ctx=m_image_ctx, ctx, journal_tid=*journal_tid](int r) { + image_ctx->journal->commit_io_event(journal_tid, r); + ctx->complete(r); + }); + + *dispatch_result = io::DISPATCH_RESULT_CONTINUE; + wait_or_flush_event(*journal_tid, io::OBJECT_DISPATCH_FLAG_FLUSH, + on_dispatched); + return true; +} + template void ObjectDispatch::extent_overwritten( uint64_t object_no, uint64_t object_off, uint64_t object_len, diff --git a/src/librbd/journal/ObjectDispatch.h b/src/librbd/journal/ObjectDispatch.h index b5ae747e2f4a..d58c3f9e53d8 100644 --- a/src/librbd/journal/ObjectDispatch.h +++ b/src/librbd/journal/ObjectDispatch.h @@ -80,10 +80,8 @@ public: bool flush( io::FlushSource flush_source, const ZTracer::Trace &parent_trace, - io::DispatchResult* dispatch_result, Context** on_finish, - Context* on_dispatched) override { - return false; - } + uint64_t* journal_tid, io::DispatchResult* dispatch_result, + Context** on_finish, Context* on_dispatched) override; bool invalidate_cache(Context* on_finish) override { return false; diff --git a/src/test/librbd/io/test_mock_SimpleSchedulerObjectDispatch.cc b/src/test/librbd/io/test_mock_SimpleSchedulerObjectDispatch.cc index 071969c5f7fe..860b2d676b00 100644 --- a/src/test/librbd/io/test_mock_SimpleSchedulerObjectDispatch.cc +++ b/src/test/librbd/io/test_mock_SimpleSchedulerObjectDispatch.cc @@ -212,7 +212,7 @@ TEST_F(TestMockIoSimpleSchedulerObjectDispatch, Flush) { C_SaferCond cond; Context *on_finish = &cond; ASSERT_FALSE(mock_simple_scheduler_object_dispatch.flush( - FLUSH_SOURCE_USER, {}, nullptr, &on_finish, nullptr)); + FLUSH_SOURCE_USER, {}, nullptr, nullptr, &on_finish, nullptr)); ASSERT_EQ(on_finish, &cond); // not modified on_finish->complete(0); ASSERT_EQ(0, cond.wait()); @@ -308,7 +308,7 @@ TEST_F(TestMockIoSimpleSchedulerObjectDispatch, WriteDelayedFlush) { C_SaferCond cond3; Context *on_finish3 = &cond3; ASSERT_FALSE(mock_simple_scheduler_object_dispatch.flush( - FLUSH_SOURCE_USER, {}, nullptr, &on_finish3, nullptr)); + FLUSH_SOURCE_USER, {}, nullptr, nullptr, &on_finish3, nullptr)); ASSERT_EQ(on_finish3, &cond3); on_finish1->complete(0); diff --git a/src/test/librbd/mock/io/MockObjectDispatch.h b/src/test/librbd/mock/io/MockObjectDispatch.h index 5f308dab7bdc..ac09bcfa6e8d 100644 --- a/src/test/librbd/mock/io/MockObjectDispatch.h +++ b/src/test/librbd/mock/io/MockObjectDispatch.h @@ -100,12 +100,13 @@ public: dispatch_result, on_dispatched); } - MOCK_METHOD3(execute_flush, bool(FlushSource, DispatchResult*, + MOCK_METHOD4(execute_flush, bool(FlushSource, uint64_t*, DispatchResult*, Context*)); bool flush(FlushSource flush_source, const ZTracer::Trace &parent_trace, - DispatchResult* dispatch_result, Context** on_finish, - Context* on_dispatched) { - return execute_flush(flush_source, dispatch_result, on_dispatched); + uint64_t* journal_tid, DispatchResult* dispatch_result, + Context** on_finish, Context* on_dispatched) { + return execute_flush(flush_source, journal_tid, dispatch_result, + on_dispatched); } MOCK_METHOD1(invalidate_cache, bool(Context*));