]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/librbd/mirror/snapshot/CreatePrimaryRequest.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / librbd / mirror / snapshot / CreatePrimaryRequest.cc
index 54da9ad610933d67d72e95588a143a22f99ca0cc..fd6f9b5023d2a4cdb866f9a520418d628c350695 100644 (file)
@@ -143,13 +143,8 @@ void CreatePrimaryRequest<I>::handle_create_snapshot(int r) {
 
 template <typename I>
 void CreatePrimaryRequest<I>::refresh_image() {
-  // if snapshot created via remote RPC, refresh is required to retrieve
-  // the snapshot id
-  if (m_snap_id == nullptr) {
-    unlink_peer();
-    return;
-  }
-
+  // refresh is required to retrieve the snapshot id (if snapshot
+  // created via remote RPC) and complete flag (regardless)
   CephContext *cct = m_image_ctx->cct;
   ldout(cct, 15) << dendl;
 
@@ -170,7 +165,7 @@ void CreatePrimaryRequest<I>::handle_refresh_image(int r) {
     return;
   }
 
-  {
+  if (m_snap_id != nullptr) {
     std::shared_lock image_locker{m_image_ctx->image_lock};
     *m_snap_id = m_image_ctx->get_snap_id(
       cls::rbd::MirrorSnapshotNamespace{}, m_snap_name);
@@ -194,7 +189,7 @@ void CreatePrimaryRequest<I>::unlink_peer() {
     size_t count = 0;
     uint64_t unlink_snap_id = 0;
     for (auto &snap_it : m_image_ctx->snap_info) {
-      auto info = boost::get<cls::rbd::MirrorSnapshotNamespace>(
+      auto info = std::get_if<cls::rbd::MirrorSnapshotNamespace>(
         &snap_it.second.snap_namespace);
       if (info == nullptr) {
         continue;
@@ -209,14 +204,15 @@ void CreatePrimaryRequest<I>::unlink_peer() {
       // or if it's not linked with any peer (happens if mirroring is enabled
       // on a pool with no peers configured or if UnlinkPeerRequest gets
       // interrupted)
-      if (info->mirror_peer_uuids.size() == 0) {
+      if (!info->mirror_peer_uuids.empty() &&
+          info->mirror_peer_uuids.count(peer) == 0) {
+        continue;
+      }
+      if (info->mirror_peer_uuids.empty() || !info->complete) {
         peer_uuid = peer;
         snap_id = snap_it.first;
         break;
       }
-      if (info->mirror_peer_uuids.count(peer) == 0) {
-        continue;
-      }
       count++;
       if (count == max_snapshots) {
         unlink_snap_id = snap_it.first;
@@ -243,7 +239,8 @@ void CreatePrimaryRequest<I>::unlink_peer() {
   auto ctx = create_context_callback<
     CreatePrimaryRequest<I>,
     &CreatePrimaryRequest<I>::handle_unlink_peer>(this);
-  auto req = UnlinkPeerRequest<I>::create(m_image_ctx, snap_id, peer_uuid, ctx);
+  auto req = UnlinkPeerRequest<I>::create(m_image_ctx, snap_id, peer_uuid, true,
+                                          ctx);
   req->send();
 }