]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: allow to use journal replay externally
authorMykola Golub <mgolub@mirantis.com>
Sat, 13 Feb 2016 07:10:46 +0000 (09:10 +0200)
committerMykola Golub <mgolub@mirantis.com>
Sat, 20 Feb 2016 06:19:16 +0000 (08:19 +0200)
Signed-off-by: Mykola Golub <mgolub@mirantis.com>
src/librbd/Journal.cc
src/librbd/Journal.h

index 486ac53037df08c97a7f2de5b19058336ea489a7..c2d7f02b37fed6b05cf5c50bf13e9d9c18a5a23b 100644 (file)
@@ -502,6 +502,42 @@ typename Journal<I>::Future Journal<I>::wait_event(Mutex &lock, uint64_t tid,
   return event.future;
 }
 
+template <typename I>
+int Journal<I>::start_external_replay(journal::Replay<I> **journal_replay) {
+  CephContext *cct = m_image_ctx.cct;
+  ldout(cct, 20) << this << " " << __func__ << dendl;
+
+  C_SaferCond cond;
+  wait_for_journal_ready(&cond);
+  int r = cond.wait();
+  if (r < 0) {
+    lderr(cct) << "failed waiting for ready state: " << cpp_strerror(r)
+              << dendl;
+    return r;
+  }
+
+  Mutex::Locker locker(m_lock);
+  assert(m_state == STATE_READY);
+  assert(m_journal_replay == nullptr);
+
+  transition_state(STATE_REPLAYING, 0);
+  m_journal_replay = journal::Replay<I>::create(m_image_ctx);
+
+  *journal_replay = m_journal_replay;
+  return 0;
+}
+
+template <typename I>
+void Journal<I>::stop_external_replay() {
+  Mutex::Locker locker(m_lock);
+  assert(m_journal_replay != nullptr);
+  assert(m_state == STATE_REPLAYING);
+
+  delete m_journal_replay;
+  m_journal_replay = nullptr;
+  transition_state(STATE_READY, 0);
+}
+
 template <typename I>
 void Journal<I>::create_journaler() {
   CephContext *cct = m_image_ctx.cct;
index 673151dcb67f0768abdfd14a9e128798d52bb6c9..44a7932877f7ce522359e4dedfc16953de66c19d 100644 (file)
@@ -137,6 +137,9 @@ public:
     return op_tid;
   }
 
+  int start_external_replay(journal::Replay<ImageCtxT> **journal_replay);
+  void stop_external_replay();
+
 private:
   ImageCtxT &m_image_ctx;