]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-mirror: support rename with group mirroring
authorPrasanna Kumar Kalever <prasanna.kalever@redhat.com>
Fri, 26 Apr 2024 15:33:28 +0000 (21:03 +0530)
committerPrasanna Kumar Kalever <prasanna.kalever@redhat.com>
Wed, 30 Jul 2025 16:56:23 +0000 (22:26 +0530)
Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
src/tools/rbd_mirror/GroupReplayer.cc
src/tools/rbd_mirror/GroupReplayer.h
src/tools/rbd_mirror/InstanceReplayer.cc
src/tools/rbd_mirror/group_replayer/BootstrapRequest.cc
src/tools/rbd_mirror/group_replayer/BootstrapRequest.h

index a68a5a96ca0b309f802af248b66e9fc961da9768..de18bfdc25d1b268ff04a99d39eb6186de99dff3 100644 (file)
@@ -237,6 +237,52 @@ bool GroupReplayer<I>::needs_restart() const {
   return false;
 }
 
+template <typename I>
+void GroupReplayer<I>::sync_group_names() {
+  dout(10) << dendl;
+
+  std::string local_group_name;
+  std::string remote_group_name;
+  int r = librbd::cls_client::dir_get_name(&m_local_io_ctx,
+                                           RBD_GROUP_DIRECTORY,
+                                           m_local_group_id,
+                                           &local_group_name);
+  if (r < 0) {
+    derr << "failed to retrieve local group name: "
+         << cpp_strerror(r) << dendl;
+    return;
+  }
+
+  r = librbd::cls_client::dir_get_name(&m_remote_group_peer.io_ctx,
+                                       RBD_GROUP_DIRECTORY,
+                                       m_remote_group_id,
+                                       &remote_group_name);
+  if (r < 0) {
+    derr << "failed to retrieve remote group name: "
+         << cpp_strerror(r) << dendl;
+    return;
+  }
+
+  if (local_group_name != remote_group_name) {
+    dout(5) << "group renamed. local group name: " << local_group_name
+            << ", remote group name: " << remote_group_name << dendl;
+
+    r = librbd::cls_client::group_dir_rename(&m_local_io_ctx,
+                                             RBD_GROUP_DIRECTORY,
+                                             local_group_name,
+                                             remote_group_name,
+                                             m_local_group_id);
+    if (r < 0) {
+      derr << "error renaming group from directory"
+           << cpp_strerror(r) << dendl;
+      return;
+    }
+
+    m_local_group_name = remote_group_name;
+    reregister_admin_socket_hook();
+  }
+}
+
 template <typename I>
 image_replayer::HealthState GroupReplayer<I>::get_health_state() const {
   // TODO: Implement something like m_mirror_image_status_state for group
@@ -489,8 +535,8 @@ void GroupReplayer<I>::bootstrap_group() {
     m_threads, m_local_io_ctx, m_remote_group_peer.io_ctx, m_global_group_id,
     m_local_mirror_uuid, m_instance_watcher, m_local_status_updater,
     m_remote_group_peer.mirror_status_updater, m_cache_manager_handler,
-    m_pool_meta_cache, &m_remote_group_id, &m_local_group_ctx,
-    &m_image_replayers, &m_image_replayer_index, ctx);
+    m_pool_meta_cache, &m_local_group_id, &m_remote_group_id,
+    &m_local_group_ctx, &m_image_replayers, &m_image_replayer_index, ctx);
 
   request->get();
   m_bootstrap_request = request;
index 06baf18cca3f1e58d498955493396067f581323b..08e4d89f15b2a630c3da410c3be0f258530f1997 100644 (file)
@@ -99,6 +99,7 @@ public:
   }
 
   bool needs_restart() const;
+  void sync_group_names();
 
   image_replayer::HealthState get_health_state() const;
 
@@ -217,6 +218,7 @@ private:
   GroupCtx m_local_group_ctx;
   Peers m_peers;
   Peer<ImageCtxT> m_remote_group_peer;
+  std::string m_local_group_id;
   std::string m_remote_group_id;
 
   mutable ceph::mutex m_lock;
index 5600a890c8178069ffd48ab7e1eb405fae3d4868..e85521f8d054918f80f8dbece26346e6b27049cb 100644 (file)
@@ -658,6 +658,8 @@ void InstanceReplayer<I>::start_group_replayer(
     if (group_replayer->needs_restart()) {
       stop_group_replayer(group_replayer, new C_TrackedOp(m_async_op_tracker,
                                                           nullptr));
+    } else {
+      group_replayer->sync_group_names();
     }
     return;
   } else if (group_replayer->is_blocklisted()) {
index 578995a7324a8f1aa639869b1f794acab6e3af54..035e736672e7525d15e3b1fa8c0f0338d2a5dacc 100644 (file)
@@ -78,6 +78,7 @@ BootstrapRequest<I>::BootstrapRequest(
     MirrorStatusUpdater<I> *remote_status_updater,
     journal::CacheManagerHandler *cache_manager_handler,
     PoolMetaCache *pool_meta_cache,
+    std::string *local_group_id,
     std::string *remote_group_id,
     GroupCtx *local_group_ctx,
     std::list<std::pair<librados::IoCtx, ImageReplayer<I> *>> *image_replayers,
@@ -96,6 +97,7 @@ BootstrapRequest<I>::BootstrapRequest(
     m_remote_status_updater(remote_status_updater),
     m_cache_manager_handler(cache_manager_handler),
     m_pool_meta_cache(pool_meta_cache),
+    m_local_group_id(local_group_id),
     m_remote_group_id(remote_group_id),
     m_local_group_ctx(local_group_ctx),
     m_image_replayers(image_replayers),
@@ -503,7 +505,7 @@ void BootstrapRequest<I>::handle_get_local_group_id(int r) {
   if (r == 0) {
     auto iter = m_out_bl.cbegin();
     r = librbd::cls_client::mirror_group_get_group_id_finish(
-        &iter, &m_local_group_id);
+        &iter, m_local_group_id);
   }
 
   if (r < 0) {
@@ -525,7 +527,7 @@ void BootstrapRequest<I>::get_local_group_name() {
   dout(10) << dendl;
 
   librados::ObjectReadOperation op;
-  librbd::cls_client::dir_get_name_start(&op, m_local_group_id);
+  librbd::cls_client::dir_get_name_start(&op, *m_local_group_id);
   m_out_bl.clear();
   auto comp = create_rados_callback<
       BootstrapRequest<I>,
@@ -607,7 +609,7 @@ void BootstrapRequest<I>::handle_get_local_group_id_by_name(int r) {
 
   if (r == 0) {
     auto iter = m_out_bl.cbegin();
-    r = librbd::cls_client::dir_get_id_finish(&iter, &m_local_group_id);
+    r = librbd::cls_client::dir_get_id_finish(&iter, m_local_group_id);
   }
 
   if (r < 0) {
@@ -625,7 +627,7 @@ void BootstrapRequest<I>::get_local_mirror_group() {
   dout(10) << dendl;
 
   librados::ObjectReadOperation op;
-  librbd::cls_client::mirror_group_get_start(&op, m_local_group_id);
+  librbd::cls_client::mirror_group_get_start(&op, *m_local_group_id);
   m_out_bl.clear();
   auto comp = create_rados_callback<
       BootstrapRequest<I>,
@@ -686,7 +688,7 @@ void BootstrapRequest<I>::list_local_group_snapshots() {
       &BootstrapRequest<I>::handle_list_local_group_snapshots>(this);
 
   auto req = librbd::group::ListSnapshotsRequest<I>::create(m_local_io_ctx,
-      m_local_group_id, true, true, &m_local_group_snaps, ctx);
+      *m_local_group_id, true, true, &m_local_group_snaps, ctx);
   req->send();
 }
 
@@ -760,7 +762,7 @@ void BootstrapRequest<I>::list_local_group() {
       &BootstrapRequest<I>::handle_list_local_group>(this);
   m_out_bl.clear();
   int r = m_local_io_ctx.aio_operate(
-      librbd::util::group_header_name(m_local_group_id), comp, &op, &m_out_bl);
+      librbd::util::group_header_name(*m_local_group_id), comp, &op, &m_out_bl);
   ceph_assert(r == 0);
   comp->release();
 }
@@ -907,7 +909,7 @@ void BootstrapRequest<I>::remove_local_image_from_group() {
       &BootstrapRequest<I>::handle_remove_local_image_from_group>(this);
 
   auto req = librbd::group::RemoveImageRequest<I>::create(
-      m_local_io_ctx, m_local_group_id, m_image_io_ctx, image_id, ctx);
+      m_local_io_ctx, *m_local_group_id, m_image_io_ctx, image_id, ctx);
   req->send();
 }
 
@@ -982,7 +984,7 @@ void BootstrapRequest<I>::disable_local_mirror_group() {
 
   librados::ObjectWriteOperation op;
   m_local_mirror_group.state = cls::rbd::MIRROR_GROUP_STATE_DISABLING;
-  librbd::cls_client::mirror_group_set(&op, m_local_group_id,
+  librbd::cls_client::mirror_group_set(&op, *m_local_group_id,
                                        m_local_mirror_group);
 
   auto comp = create_rados_callback<
@@ -1018,7 +1020,7 @@ void BootstrapRequest<I>::remove_local_mirror_group() {
   dout(10) << dendl;
 
   librados::ObjectWriteOperation op;
-  librbd::cls_client::mirror_group_remove(&op, m_local_group_id);
+  librbd::cls_client::mirror_group_remove(&op, *m_local_group_id);
 
   auto comp = create_rados_callback<
       BootstrapRequest<I>,
@@ -1050,9 +1052,9 @@ void BootstrapRequest<I>::handle_remove_local_mirror_group(int r) {
 
 template <typename I>
 void BootstrapRequest<I>::remove_local_group() {
-  dout(10) << m_group_name << " " << m_local_group_id << dendl;
+  dout(10) << m_group_name << " " << *m_local_group_id << dendl;
 
-  ceph_assert(!m_local_group_id.empty());
+  ceph_assert(!m_local_group_id->empty());
   ceph_assert(!m_group_name.empty());
 
   librados::ObjectWriteOperation op;
@@ -1062,7 +1064,7 @@ void BootstrapRequest<I>::remove_local_group() {
       &BootstrapRequest<I>::handle_remove_local_group>(this);
 
   int r = m_local_io_ctx.aio_operate(
-      librbd::util::group_header_name(m_local_group_id), comp, &op);
+      librbd::util::group_header_name(*m_local_group_id), comp, &op);
   ceph_assert(r == 0);
   comp->release();
 }
@@ -1085,7 +1087,7 @@ void BootstrapRequest<I>::remove_local_group_id() {
   dout(10) << dendl;
 
   librados::ObjectWriteOperation op;
-  librbd::cls_client::group_dir_remove(&op, m_group_name, m_local_group_id);
+  librbd::cls_client::group_dir_remove(&op, m_group_name, *m_local_group_id);
 
   auto comp = create_rados_callback<
       BootstrapRequest<I>,
@@ -1109,15 +1111,14 @@ void BootstrapRequest<I>::handle_remove_local_group_id(int r) {
   finish(0);
 }
 
-
 template <typename I>
 void BootstrapRequest<I>::create_local_group_id() {
   dout(10) << dendl;
 
-  m_local_group_id = librbd::util::generate_uuid(m_local_io_ctx);
+  *m_local_group_id = librbd::util::generate_image_id(m_local_io_ctx);
 
   librados::ObjectWriteOperation op;
-  librbd::cls_client::group_dir_add(&op, m_group_name, m_local_group_id);
+  librbd::cls_client::group_dir_add(&op, m_group_name, *m_local_group_id);
 
   auto comp = create_rados_callback<
       BootstrapRequest<I>,
@@ -1152,7 +1153,7 @@ void BootstrapRequest<I>::create_local_group() {
       &BootstrapRequest<I>::handle_create_local_group>(this);
 
   int r = m_local_io_ctx.aio_operate(
-      librbd::util::group_header_name(m_local_group_id), comp, &op);
+      librbd::util::group_header_name(*m_local_group_id), comp, &op);
   ceph_assert(r == 0);
   comp->release();
 }
@@ -1182,7 +1183,7 @@ void BootstrapRequest<I>::create_local_mirror_group() {
   m_local_mirror_group = {m_global_group_id,
                           m_remote_mirror_group.mirror_image_mode,
                           cls::rbd::MIRROR_GROUP_STATE_ENABLED};
-  librbd::cls_client::mirror_group_set(&op, m_local_group_id,
+  librbd::cls_client::mirror_group_set(&op, *m_local_group_id,
                                        m_local_mirror_group);
   auto comp = create_rados_callback<
       BootstrapRequest<I>,
@@ -1266,7 +1267,7 @@ void BootstrapRequest<I>::finish(int r) {
     if (m_local_mirror_group.state == cls::rbd::MIRROR_GROUP_STATE_DISABLED) {
       r = -ENOENT;
     } else {
-      *m_local_group_ctx = {m_group_name, m_local_group_id, m_global_group_id,
+      *m_local_group_ctx = {m_group_name, *m_local_group_id, m_global_group_id,
                             m_local_mirror_group_primary, m_local_io_ctx};
       r = create_replayers();
     }
index 368a83b911e6da90487f4f1e99fce92f31ddfd90..2b0085e7df1f96474eb2dfc297febcd133d657c0 100644 (file)
@@ -45,6 +45,7 @@ public:
       MirrorStatusUpdater<ImageCtxT> *remote_status_updater,
       journal::CacheManagerHandler *cache_manager_handler,
       PoolMetaCache *pool_meta_cache,
+      std::string *local_group_id,
       std::string *remote_group_id,
       GroupCtx *local_group_ctx,
       std::list<std::pair<librados::IoCtx, ImageReplayer<ImageCtxT> *>> *image_replayers,
@@ -53,8 +54,8 @@ public:
     return new BootstrapRequest(
       threads, local_io_ctx, remote_io_ctx, global_group_id, local_mirror_uuid,
       instance_watcher, local_status_updater, remote_status_updater,
-      cache_manager_handler, pool_meta_cache, remote_group_id, local_group_ctx,
-      image_replayers, image_replayer_index, on_finish);
+      cache_manager_handler, pool_meta_cache, local_group_id, remote_group_id,
+      local_group_ctx, image_replayers, image_replayer_index, on_finish);
   }
 
   BootstrapRequest(
@@ -68,6 +69,7 @@ public:
       MirrorStatusUpdater<ImageCtxT> *remote_status_updater,
       journal::CacheManagerHandler *cache_manager_handler,
       PoolMetaCache *pool_meta_cache,
+      std::string *local_group_id,
       std::string *remote_group_id,
       GroupCtx *local_group_ctx,
       std::list<std::pair<librados::IoCtx, ImageReplayer<ImageCtxT> *>> *image_replayers,
@@ -162,6 +164,7 @@ private:
   MirrorStatusUpdater<ImageCtxT> *m_remote_status_updater;
   journal::CacheManagerHandler *m_cache_manager_handler;
   PoolMetaCache *m_pool_meta_cache;
+  std::string *m_local_group_id;
   std::string *m_remote_group_id;
   GroupCtx *m_local_group_ctx;
   std::list<std::pair<librados::IoCtx, ImageReplayer<ImageCtxT> *>> *m_image_replayers;
@@ -171,7 +174,6 @@ private:
   std::atomic<bool> m_canceled = false;
 
   std::string m_group_name;
-  std::string m_local_group_id;
   bool m_local_group_id_by_name = false;
   cls::rbd::MirrorGroup m_remote_mirror_group;
   cls::rbd::MirrorGroup m_local_mirror_group;