]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-mirror: check for resync request during snapshot prepare state machine
authorJason Dillaman <dillaman@redhat.com>
Sat, 22 Feb 2020 17:42:28 +0000 (12:42 -0500)
committerJason Dillaman <dillaman@redhat.com>
Wed, 26 Feb 2020 13:18:29 +0000 (08:18 -0500)
Before attempting to start the image replayer for snapshot-based mirroring,
check to ensure that a resync hasn't already been requested.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/tools/rbd_mirror/image_replayer/snapshot/PrepareReplayRequest.cc
src/tools/rbd_mirror/image_replayer/snapshot/PrepareReplayRequest.h
src/tools/rbd_mirror/image_replayer/snapshot/StateBuilder.cc
src/tools/rbd_mirror/image_replayer/snapshot/StateBuilder.h

index 38340de228437c10e5194e9418fe6e095b3fd2a7..575eb8534fa38965b8270a1ac9bca5eb7de29446 100644 (file)
@@ -7,6 +7,7 @@
 #include "common/errno.h"
 #include "librbd/ImageCtx.h"
 #include "librbd/Utils.h"
+#include "librbd/mirror/snapshot/ImageMeta.h"
 #include "tools/rbd_mirror/ProgressContext.h"
 #include "tools/rbd_mirror/image_replayer/snapshot/StateBuilder.h"
 
@@ -22,12 +23,42 @@ namespace mirror {
 namespace image_replayer {
 namespace snapshot {
 
+using librbd::util::create_context_callback;
+
 template <typename I>
 void PrepareReplayRequest<I>::send() {
-  // TODO
   *m_resync_requested = false;
   *m_syncing = false;
 
+  load_local_image_meta();
+}
+
+template <typename I>
+void PrepareReplayRequest<I>::load_local_image_meta() {
+  dout(15) << dendl;
+
+  ceph_assert(m_state_builder->local_image_meta == nullptr);
+  m_state_builder->local_image_meta =
+    librbd::mirror::snapshot::ImageMeta<I>::create(
+      m_state_builder->local_image_ctx, m_local_mirror_uuid);
+
+  auto ctx = create_context_callback<
+    PrepareReplayRequest<I>,
+    &PrepareReplayRequest<I>::handle_load_local_image_meta>(this);
+  m_state_builder->local_image_meta->load(ctx);
+}
+
+template <typename I>
+void PrepareReplayRequest<I>::handle_load_local_image_meta(int r) {
+  dout(15) << "r=" << r << dendl;
+
+  if (r < 0 && r != -ENOENT) {
+    derr << "failed to load local image-meta: " << cpp_strerror(r) << dendl;
+    finish(r);
+    return;
+  }
+
+  *m_resync_requested = m_state_builder->local_image_meta->resync_requested;
   finish(0);
 }
 
index 4cd1f9b0d35862f5d0def6eb10681384829e5561..315080238f7dcabce9000da3e8a59800695c1ab0 100644 (file)
@@ -66,6 +66,9 @@ private:
    * <start>
    *    |
    *    v
+   * LOAD_LOCAL_IMAGE_META
+   *    |
+   *    v
    * <finish>
    *
    * @endverbatim
@@ -77,6 +80,10 @@ private:
   StateBuilder<ImageCtxT>* m_state_builder;
   bool* m_resync_requested;
   bool* m_syncing;
+
+  void load_local_image_meta();
+  void handle_load_local_image_meta(int r);
+
 };
 
 } // namespace snapshot
index 0b573439118f5f7e98552d4614199098be5cba5a..27225707f55324a7a5ecbb39601c01c607f7990f 100644 (file)
@@ -7,6 +7,7 @@
 #include "common/debug.h"
 #include "common/errno.h"
 #include "librbd/ImageCtx.h"
+#include "librbd/mirror/snapshot/ImageMeta.h"
 #include "tools/rbd_mirror/image_replayer/snapshot/CreateLocalImageRequest.h"
 #include "tools/rbd_mirror/image_replayer/snapshot/PrepareReplayRequest.h"
 #include "tools/rbd_mirror/image_replayer/snapshot/Replayer.h"
@@ -30,12 +31,16 @@ StateBuilder<I>::StateBuilder(const std::string& global_image_id)
 
 template <typename I>
 StateBuilder<I>::~StateBuilder() {
+  ceph_assert(local_image_meta == nullptr);
 }
 
 template <typename I>
 void StateBuilder<I>::close(Context* on_finish) {
   dout(10) << dendl;
 
+  delete local_image_meta;
+  local_image_meta = nullptr;
+
   // close the remote image after closing the local
   // image in case the remote cluster is unreachable and
   // we cannot close it.
index 7222f864ab41af69612471216e3b1af7f894e3f7..83c55ebafdccfc65264c81287697d068505e2899 100644 (file)
@@ -9,7 +9,18 @@
 
 struct Context;
 
-namespace librbd { struct ImageCtx; }
+namespace librbd {
+
+struct ImageCtx;
+
+namespace mirror {
+namespace snapshot {
+
+template <typename> class ImageMeta;
+
+} // namespace snapshot
+} // namespace mirror
+} // namespace librbd
 
 namespace rbd {
 namespace mirror {
@@ -66,6 +77,7 @@ public:
 
   std::string remote_mirror_peer_uuid;
 
+  librbd::mirror::snapshot::ImageMeta<ImageCtxT>* local_image_meta = nullptr;
 };
 
 } // namespace snapshot