From: Mykola Golub Date: Sat, 13 Feb 2016 07:10:46 +0000 (+0200) Subject: librbd: allow to use journal replay externally X-Git-Tag: v10.1.0~343^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0aaaf3676c07a06b5e9fae3ea38d30bead94125d;p=ceph.git librbd: allow to use journal replay externally Signed-off-by: Mykola Golub --- diff --git a/src/librbd/Journal.cc b/src/librbd/Journal.cc index 486ac53037df..c2d7f02b37fe 100644 --- a/src/librbd/Journal.cc +++ b/src/librbd/Journal.cc @@ -502,6 +502,42 @@ typename Journal::Future Journal::wait_event(Mutex &lock, uint64_t tid, return event.future; } +template +int Journal::start_external_replay(journal::Replay **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::create(m_image_ctx); + + *journal_replay = m_journal_replay; + return 0; +} + +template +void Journal::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 void Journal::create_journaler() { CephContext *cct = m_image_ctx.cct; diff --git a/src/librbd/Journal.h b/src/librbd/Journal.h index 673151dcb67f..44a7932877f7 100644 --- a/src/librbd/Journal.h +++ b/src/librbd/Journal.h @@ -137,6 +137,9 @@ public: return op_tid; } + int start_external_replay(journal::Replay **journal_replay); + void stop_external_replay(); + private: ImageCtxT &m_image_ctx;