From: Jason Dillaman Date: Wed, 23 Mar 2016 21:46:43 +0000 (-0400) Subject: rbd-mirror: initial integration with librbd lock/journal policies X-Git-Tag: v10.1.1~64^2~30 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0f99d88dc9acc653cfc968ff2a159c36aacb95fe;p=ceph.git rbd-mirror: initial integration with librbd lock/journal policies For the first stage, acquiring the exclusive-lock will no longer automatically result in the allocation of a journal tag. Signed-off-by: Jason Dillaman --- diff --git a/src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.cc b/src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.cc index 4e40c4efd508..846f9c4dfd21 100644 --- a/src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.cc +++ b/src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.cc @@ -9,6 +9,8 @@ #include "librbd/ImageCtx.h" #include "librbd/ImageState.h" #include "librbd/Utils.h" +#include "librbd/exclusive_lock/Policy.h" +#include "librbd/journal/Policy.h" #define dout_subsys ceph_subsys_rbd_mirror #undef dout_prefix @@ -21,6 +23,39 @@ namespace image_replayer { using librbd::util::create_context_callback; +namespace { + +struct MirrorExclusiveLockPolicy : public librbd::exclusive_lock::Policy { + + virtual void lock_requested(bool force) { + // TODO: interlock is being requested (e.g. local promotion) + // Wait for demote event from peer or abort replay on forced + // promotion. + } + +}; + +struct MirrorJournalPolicy : public librbd::journal::Policy { + ContextWQ *work_queue; + + MirrorJournalPolicy(ContextWQ *work_queue) : work_queue(work_queue) { + } + + virtual void allocate_tag_on_lock(Context *on_finish) { + // rbd-mirror will manually create tags by copying them from the peer + work_queue->queue(on_finish, 0); + } + + virtual void cancel_external_replay(Context *on_finish) { + // TODO: journal is being closed due to a comms error. This means + // the journal is being closed and the exclusive lock is being released. + // ImageReplayer needs to restart. + } + +}; + +} // anonymous namespace + template OpenLocalImageRequest::OpenLocalImageRequest(librados::IoCtx &local_io_ctx, I **local_image_ctx, @@ -45,6 +80,10 @@ void OpenLocalImageRequest::send_open_image() { *m_local_image_ctx = new librbd::ImageCtx(m_local_image_name, m_local_image_id, nullptr, m_local_io_ctx, false); + (*m_local_image_ctx)->set_exclusive_lock_policy( + new MirrorExclusiveLockPolicy()); + (*m_local_image_ctx)->set_journal_policy( + new MirrorJournalPolicy(m_work_queue)); Context *ctx = create_context_callback< OpenLocalImageRequest, &OpenLocalImageRequest::handle_open_image>(