]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc
import ceph quincy 17.2.4
[ceph.git] / ceph / src / tools / rbd_mirror / image_replayer / BootstrapRequest.cc
index a34f39c15b34a6770384589f3dfe2755d79af04b..bda5b5f9bd760c19a1938ff8d8bbf971205f7779 100644 (file)
@@ -135,7 +135,7 @@ void BootstrapRequest<I>::handle_prepare_local_image(int r) {
   if (r == -ENOENT) {
     dout(10) << "local image does not exist" << dendl;
   } else if (r < 0) {
-    derr << "error preparing local image for replay" << cpp_strerror(r)
+    derr << "error preparing local image for replay" << cpp_strerror(r)
          << dendl;
     finish(r);
     return;
@@ -177,10 +177,6 @@ void BootstrapRequest<I>::handle_prepare_remote_image(int r) {
     dout(5) << "local image is primary" << dendl;
     finish(-ENOMSG);
     return;
-  } else if (r == -EREMOTEIO) {
-    dout(10) << "remote-image is non-primary" << cpp_strerror(r) << dendl;
-    finish(r);
-    return;
   } else if (r == -ENOENT || state_builder == nullptr) {
     dout(10) << "remote image does not exist";
     if (state_builder != nullptr) {
@@ -204,11 +200,29 @@ void BootstrapRequest<I>::handle_prepare_remote_image(int r) {
     }
     return;
   } else if (r < 0) {
-    derr << "error retrieving remote image id" << cpp_strerror(r) << dendl;
+    derr << "error preparing remote image for replay: " << cpp_strerror(r)
+         << dendl;
     finish(r);
     return;
   }
 
+  if (!state_builder->is_remote_primary()) {
+    ceph_assert(!state_builder->remote_image_id.empty());
+    if (state_builder->local_image_id.empty()) {
+      dout(10) << "local image does not exist and remote image is not primary"
+               << dendl;
+      finish(-EREMOTEIO);
+      return;
+    } else if (!state_builder->is_linked()) {
+      dout(10) << "local image is unlinked and remote image is not primary"
+               << dendl;
+      finish(-EREMOTEIO);
+      return;
+    }
+    // if the local image is linked to the remote image, we ignore that
+    // the remote image is not primary so that we can replay demotion
+  }
+
   open_remote_image();
 }
 
@@ -314,9 +328,7 @@ void BootstrapRequest<I>::handle_prepare_replay(int r) {
   dout(10) << "r=" << r << dendl;
 
   if (r < 0) {
-    if (r != -EREMOTEIO) {
-      derr << "failed to prepare local replay: " << cpp_strerror(r) << dendl;
-    }
+    derr << "failed to prepare local replay: " << cpp_strerror(r) << dendl;
     m_ret_val = r;
     close_remote_image();
     return;