]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd/api/Mirror: set the boolean field 'primary' in group_info and group_list
authorRamana Raja <rraja@redhat.com>
Tue, 29 Oct 2024 13:51:38 +0000 (09:51 -0400)
committerPrasanna Kumar Kalever <prasanna.kalever@redhat.com>
Thu, 24 Apr 2025 15:56:26 +0000 (21:26 +0530)
outputs to identify whether a mirror group is primary or not.

Signed-off-by: Ramana Raja <rraja@redhat.com>
src/librbd/api/Mirror.cc

index 4a04ae7a9d4969e924dc3dc68bdbaee8afab3c45..b669ca5843de9b4ec5304b158ce2c674ec624b77 100644 (file)
@@ -4004,6 +4004,18 @@ int Mirror<I>::group_info_list(librados::IoCtx& io_ctx,
       info.mirror_image_mode = mode;
       info.state = static_cast<rbd_mirror_group_state_t>(group.state);
 
+      cls::rbd::MirrorSnapshotState promotion_state;
+      r = get_last_mirror_snapshot_state(io_ctx, group_id, &promotion_state);
+      if (r == -ENOENT) {
+       promotion_state = cls::rbd::MIRROR_SNAPSHOT_STATE_NON_PRIMARY;
+      } else if (r < 0) {
+       lderr(cct) << "failed to get last mirror snapshot state: "
+                   << cpp_strerror(r) << dendl;
+       return r;
+      }
+      info.primary =
+       (promotion_state == cls::rbd::MIRROR_SNAPSHOT_STATE_PRIMARY);
+
       if (entries->size() == max) {
         break;
       }
@@ -4043,11 +4055,24 @@ int Mirror<I>::group_get_info(librados::IoCtx& io_ctx,
     return r;
   }
 
+  cls::rbd::MirrorSnapshotState promotion_state;
+  r = get_last_mirror_snapshot_state(io_ctx, group_id, &promotion_state);
+  if (r == -ENOENT) {
+    promotion_state = cls::rbd::MIRROR_SNAPSHOT_STATE_NON_PRIMARY;
+  } else if (r < 0) {
+    lderr(cct) << "failed to get last mirror snapshot state: "
+               << cpp_strerror(r) << dendl;
+    return r;
+  }
+
+
   mirror_group_info->global_id = mirror_group.global_group_id;
   mirror_group_info->mirror_image_mode =
       static_cast<rbd_mirror_image_mode_t>(mirror_group.mirror_image_mode);
   mirror_group_info->state =
       static_cast<rbd_mirror_group_state_t>(mirror_group.state);
+  mirror_group_info->primary =
+    (promotion_state == cls::rbd::MIRROR_SNAPSHOT_STATE_PRIMARY);
 
   return 0;
 }