]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: pass journal tid through flush object dispatch spec
authorJason Dillaman <dillaman@redhat.com>
Thu, 4 Apr 2019 20:46:37 +0000 (16:46 -0400)
committerJason Dillaman <dillaman@redhat.com>
Thu, 11 Apr 2019 16:47:00 +0000 (12:47 -0400)
This permits moving the journal flush and commit logic down to the
journal object dispatch layer.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
13 files changed:
src/librbd/cache/ObjectCacherObjectDispatch.cc
src/librbd/cache/ObjectCacherObjectDispatch.h
src/librbd/io/ImageRequest.cc
src/librbd/io/ObjectDispatch.h
src/librbd/io/ObjectDispatchInterface.h
src/librbd/io/ObjectDispatchSpec.h
src/librbd/io/ObjectDispatcher.cc
src/librbd/io/SimpleSchedulerObjectDispatch.cc
src/librbd/io/SimpleSchedulerObjectDispatch.h
src/librbd/journal/ObjectDispatch.cc
src/librbd/journal/ObjectDispatch.h
src/test/librbd/io/test_mock_SimpleSchedulerObjectDispatch.cc
src/test/librbd/mock/io/MockObjectDispatch.h

index 25a05a2f50d973d3a567858c6347c17a7e1db95d..adf6b31d90b7aa058670b8a3871e2d07e522d76e 100644 (file)
@@ -347,8 +347,8 @@ bool ObjectCacherObjectDispatch<I>::compare_and_write(
 template <typename I>
 bool ObjectCacherObjectDispatch<I>::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;
 
index 19394e43f71164451230f26b2e9b13b0305a868f..e01c7f700550c6073ca97e40fcd6da5c2aba5f49 100644 (file)
@@ -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;
index 5a74fabf0e96c7d96fb3f53daead53b006db74b6..b4c4b794db541904c27744e3430455d88233a3d8 100644 (file)
@@ -614,30 +614,21 @@ void ImageFlushRequest<I>::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);
index 32e8272d739ef84a3e9d655d4d70cb3729e07973..5957b2766113befed123d64f3ac36edf31af9f97 100644 (file)
@@ -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;
   }
 
index fddf0db1475ae720114ab1d80f55b5060be883c3..a3d815c9c5f6a172aa9177f02b50c3e414db2944 100644 (file)
@@ -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;
index a26d89fe4560eae0d034acb6d1bf05241c594fed..8580796cfe112d4404bb4bcbbe8b5fbbd4d3bcad 100644 (file)
@@ -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 <typename ImageCtxT>
   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);
   }
 
index befc075062cac6e1caa4cbdadf1f16361013711d..6285737a81a9a4c68d259d29bf9595f546209115 100644 (file)
@@ -167,6 +167,7 @@ struct ObjectDispatcher<I>::SendVisitor : public boost::static_visitor<bool> {
   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);
index a76abf903729e982dbaede6f7cf0ba9732d08fc6..687f8670bd6f14c2355dd4d3111377b07bfb806c 100644 (file)
@@ -311,8 +311,8 @@ bool SimpleSchedulerObjectDispatch<I>::compare_and_write(
 template <typename I>
 bool SimpleSchedulerObjectDispatch<I>::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;
 
index 6cfd4f626850317de4741c7a338203be226355ba..f15966c308aee69a741392bbad25d94230dc3b78 100644 (file)
@@ -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;
index 737f5efe0f4ef58f74551125e9283ef14590c9a6..ebe09fe7e195fc227f4e883396be31e5217836bb 100644 (file)
@@ -174,6 +174,32 @@ bool ObjectDispatch<I>::compare_and_write(
   return true;
 }
 
+template <typename I>
+bool ObjectDispatch<I>::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 <typename I>
 void ObjectDispatch<I>::extent_overwritten(
     uint64_t object_no, uint64_t object_off, uint64_t object_len,
index b5ae747e2f4a59bdbd9af4a89c03fc875c16da6f..d58c3f9e53d806bec7c937f3ec69f7f8e375fd5a 100644 (file)
@@ -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;
index 071969c5f7fef62667fece070f3e364edb58e99c..860b2d676b00bff1daa44e52cc88197d43f2b893 100644 (file)
@@ -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);
index 5f308dab7bdc7a98ab3c9a655eb45b40ebb10050..ac09bcfa6e8d6dab37e89eed19e3685e311d2e6e 100644 (file)
@@ -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*));