]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-mirror: initial integration with librbd lock/journal policies
authorJason Dillaman <dillaman@redhat.com>
Wed, 23 Mar 2016 21:46:43 +0000 (17:46 -0400)
committerJason Dillaman <dillaman@redhat.com>
Tue, 29 Mar 2016 19:12:29 +0000 (15:12 -0400)
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 <dillaman@redhat.com>
src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.cc

index 4e40c4efd50891352943ea651ba57fee0bc06455..846f9c4dfd21ce6f43230eaf61fcda0681d71975 100644 (file)
@@ -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 <typename I>
 OpenLocalImageRequest<I>::OpenLocalImageRequest(librados::IoCtx &local_io_ctx,
                                                 I **local_image_ctx,
@@ -45,6 +80,10 @@ void OpenLocalImageRequest<I>::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<I>, &OpenLocalImageRequest<I>::handle_open_image>(