]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: helper method for flushing journal commit positions 7698/head
authorJason Dillaman <dillaman@redhat.com>
Fri, 19 Feb 2016 01:56:08 +0000 (20:56 -0500)
committerJason Dillaman <dillaman@redhat.com>
Fri, 19 Feb 2016 03:53:11 +0000 (22:53 -0500)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/Journal.cc
src/librbd/Journal.h
src/test/librbd/test_mock_Journal.cc

index 5bd1759864e0cf17cee1768f097cb576c3483598..486ac53037df08c97a7f2de5b19058336ea489a7 100644 (file)
@@ -288,6 +288,16 @@ void Journal<I>::close(Context *on_finish) {
   wait_for_steady_state(on_finish);
 }
 
+template <typename I>
+void Journal<I>::flush_commit_position(Context *on_finish) {
+  CephContext *cct = m_image_ctx.cct;
+  ldout(cct, 20) << this << " " << __func__ << dendl;
+
+  Mutex::Locker locker(m_lock);
+  assert(m_journaler != nullptr);
+  m_journaler->flush_commit_position(on_finish);
+}
+
 template <typename I>
 uint64_t Journal<I>::append_io_event(AioCompletion *aio_comp,
                                      journal::EventEntry &&event_entry,
index 2a03907afca972e0c3350a96030752a98c762ee1..673151dcb67f0768abdfd14a9e128798d52bb6c9 100644 (file)
@@ -112,6 +112,8 @@ public:
   void open(Context *on_finish);
   void close(Context *on_finish);
 
+  void flush_commit_position(Context *on_finish);
+
   uint64_t append_io_event(AioCompletion *aio_comp,
                            journal::EventEntry &&event_entry,
                            const AioObjectRequests &requests,
index 483b0a05db29e6ca23442452e8470e1a9476ef70..b797ac838d5f4bc128912969a47c2798f3040bef 100644 (file)
@@ -85,6 +85,7 @@ struct MockJournaler {
   MOCK_METHOD3(get_metadata, void(uint8_t *order, uint8_t *splay_width,
                                   int64_t *pool_id));
   MOCK_METHOD1(init, void(Context*));
+  MOCK_METHOD1(flush_commit_position, void(Context*));
 
   MOCK_METHOD1(start_replay, void(::journal::ReplayHandler *replay_handler));
   MOCK_METHOD1(try_pop_front, bool(MockReplayEntryProxy *replay_entry));
@@ -133,6 +134,10 @@ struct MockJournalerProxy {
     MockJournaler::get_instance().init(on_finish);
   }
 
+  void flush_commit_position(Context *on_finish) {
+    MockJournaler::get_instance().flush_commit_position(on_finish);
+  }
+
   void start_replay(::journal::ReplayHandler *replay_handler) {
     MockJournaler::get_instance().start_replay(replay_handler);
   }
@@ -371,6 +376,11 @@ public:
     EXPECT_CALL(mock_future, is_valid()).WillOnce(Return(false));
   }
 
+  void expect_flush_commit_position(::journal::MockJournaler &mock_journaler) {
+    EXPECT_CALL(mock_journaler, flush_commit_position(_))
+                  .WillOnce(CompleteContext(0, NULL));
+  }
+
   int when_open(MockJournal &mock_journal) {
     C_SaferCond ctx;
     mock_journal.open(&ctx);
@@ -914,4 +924,24 @@ TEST_F(TestMockJournal, IOCommitError) {
   mock_journal.commit_io_event(1U, -EINVAL);
 }
 
+TEST_F(TestMockJournal, FlushCommitPosition) {
+  REQUIRE_FEATURE(RBD_FEATURE_JOURNALING);
+
+  librbd::ImageCtx *ictx;
+  ASSERT_EQ(0, open_image(m_image_name, &ictx));
+
+  MockImageCtx mock_image_ctx(*ictx);
+  MockJournal mock_journal(mock_image_ctx);
+  ::journal::MockJournaler mock_journaler;
+  open_journal(mock_image_ctx, mock_journal, mock_journaler);
+  BOOST_SCOPE_EXIT_ALL(&) {
+    close_journal(mock_journal, mock_journaler);
+  };
+
+  expect_flush_commit_position(mock_journaler);
+  C_SaferCond ctx;
+  mock_journal.flush_commit_position(&ctx);
+  ASSERT_EQ(0, ctx.wait());
+}
+
 } // namespace librbd