From dfa23483aa2828004fe588f9c23f398a29b03323 Mon Sep 17 00:00:00 2001 From: Mykola Golub Date: Fri, 3 Oct 2025 15:40:54 +0300 Subject: [PATCH] rbd-mirror: add cluster fsid to remote meta cache key Using just pool id is not enough when mirroring several clusters. Fixes: https://tracker.ceph.com/issues/69492 Signed-off-by: Mykola Golub --- .../snapshot/test_mock_Replayer.cc | 74 ++++++++++--------- src/test/rbd_mirror/test_ImageReplayer.cc | 7 +- src/tools/rbd_mirror/PoolMetaCache.cc | 21 +++--- src/tools/rbd_mirror/PoolMetaCache.h | 8 +- src/tools/rbd_mirror/PoolReplayer.cc | 13 +++- src/tools/rbd_mirror/PoolReplayer.h | 1 + .../image_replayer/snapshot/Replayer.cc | 14 +++- 7 files changed, 84 insertions(+), 54 deletions(-) diff --git a/src/test/rbd_mirror/image_replayer/snapshot/test_mock_Replayer.cc b/src/test/rbd_mirror/image_replayer/snapshot/test_mock_Replayer.cc index 21afa6d52bb55..4a9b982bb4988 100644 --- a/src/test/rbd_mirror/image_replayer/snapshot/test_mock_Replayer.cc +++ b/src/test/rbd_mirror/image_replayer/snapshot/test_mock_Replayer.cc @@ -407,6 +407,9 @@ public: void SetUp() override { TestMockFixture::SetUp(); + librados::Rados remote_rados(m_remote_io_ctx); + EXPECT_EQ(0, remote_rados.cluster_fsid(&m_remote_fsid)); + librbd::RBD rbd; ASSERT_EQ(0, create_image(rbd, m_local_io_ctx, m_image_name, m_image_size)); ASSERT_EQ(0, open_image(m_local_io_ctx, m_image_name, &m_local_image_ctx)); @@ -704,6 +707,7 @@ public: librbd::ImageCtx* m_local_image_ctx = nullptr; librbd::ImageCtx* m_remote_image_ctx = nullptr; + std::string m_remote_fsid; PoolMetaCache m_pool_meta_cache{g_ceph_context}; ceph::mutex m_lock = ceph::make_mutex( @@ -733,7 +737,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, InitShutDown) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -787,7 +791,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, SyncSnapshot) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -965,7 +969,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, InterruptedSyncInitial) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -1050,7 +1054,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, InterruptedSyncDelta) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -1171,7 +1175,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, InterruptedSyncDeltaDemote) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -1280,7 +1284,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, InterruptedPendingSyncInitial) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -1364,7 +1368,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, InterruptedPendingSyncDelta) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -1504,7 +1508,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, InterruptedPendingSyncDeltaDemote) "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -1632,7 +1636,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, RemoteImageDemoted) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -1721,7 +1725,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, LocalImagePromoted) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -1777,7 +1781,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, ResyncRequested) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -1833,7 +1837,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, ResyncRequestedRemoteNotPrimary) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -1922,7 +1926,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, RegisterLocalUpdateWatcherError) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); // init @@ -1955,7 +1959,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, RegisterRemoteUpdateWatcherError) "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); // init @@ -1994,7 +1998,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, UnregisterRemoteUpdateWatcherError "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -2036,7 +2040,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, UnregisterLocalUpdateWatcherError) "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -2078,7 +2082,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, LoadImageMetaError) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -2126,7 +2130,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, RefreshLocalImageError) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -2177,7 +2181,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, RefreshRemoteImageError) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -2227,7 +2231,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, CopySnapshotsError) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -2287,7 +2291,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, GetImageStateError) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -2349,7 +2353,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, CreateNonPrimarySnapshotError) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -2415,7 +2419,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, UpdateMirrorImageStateError) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -2483,7 +2487,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, RequestSyncError) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -2553,7 +2557,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, CopyImageError) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -2626,7 +2630,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, UpdateNonPrimarySnapshotError) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -2703,7 +2707,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, UnlinkPeerError) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -2791,7 +2795,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, SplitBrain) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -2854,7 +2858,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, RemoteSnapshotMissingSplitBrain) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -2922,7 +2926,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, RemoteFailover) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -3064,7 +3068,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, UnlinkRemoteSnapshot) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -3142,7 +3146,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, SkipImageSync) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -3221,7 +3225,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, ImageNameUpdated) { "local mirror uuid", &m_pool_meta_cache, &mock_state_builder, &mock_replayer_listener}; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -3284,7 +3288,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, ApplyImageStatePendingShutdown) { &mock_state_builder, &mock_replayer_listener}; C_SaferCond shutdown_ctx; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; @@ -3371,7 +3375,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, ApplyImageStateErrorPendingShutdow &mock_state_builder, &mock_replayer_listener}; C_SaferCond shutdown_ctx; m_pool_meta_cache.set_remote_pool_meta( - m_remote_io_ctx.get_id(), + m_remote_fsid, m_remote_io_ctx.get_id(), {"remote mirror uuid", "remote mirror peer uuid"}); librbd::UpdateWatchCtx* update_watch_ctx = nullptr; diff --git a/src/test/rbd_mirror/test_ImageReplayer.cc b/src/test/rbd_mirror/test_ImageReplayer.cc index 6d79c9173ceab..bbd388a41f801 100644 --- a/src/test/rbd_mirror/test_ImageReplayer.cc +++ b/src/test/rbd_mirror/test_ImageReplayer.cc @@ -144,8 +144,13 @@ public: cls::rbd::MIRROR_PEER_DIRECTION_RX_TX, "siteA", "client", m_local_mirror_uuid})); + std::string remote_fsid; + librados::Rados remote_rados(m_remote_ioctx); + EXPECT_EQ(0, remote_rados.cluster_fsid(&remote_fsid)); + m_pool_meta_cache.set_remote_pool_meta( - m_remote_ioctx.get_id(), {m_remote_mirror_uuid, remote_peer_uuid}); + remote_fsid, m_remote_ioctx.get_id(), + {m_remote_mirror_uuid, remote_peer_uuid}); } EXPECT_EQ(0, librbd::api::Mirror<>::uuid_get(m_remote_ioctx, diff --git a/src/tools/rbd_mirror/PoolMetaCache.cc b/src/tools/rbd_mirror/PoolMetaCache.cc index 261802a55c534..c912e65b3b383 100644 --- a/src/tools/rbd_mirror/PoolMetaCache.cc +++ b/src/tools/rbd_mirror/PoolMetaCache.cc @@ -48,12 +48,12 @@ void PoolMetaCache::remove_local_pool_meta(int64_t pool_id) { } int PoolMetaCache::get_remote_pool_meta( - int64_t pool_id, + const std::string& fsid, int64_t pool_id, RemotePoolMeta* remote_pool_meta) const { - dout(15) << "pool_id=" << pool_id << dendl; + dout(15) << "fsid=" << fsid << ", pool_id=" << pool_id << dendl; std::shared_lock locker{m_lock}; - auto it = m_remote_pool_metas.find(pool_id); + auto it = m_remote_pool_metas.find({fsid, pool_id}); if (it == m_remote_pool_metas.end()) { return -ENOENT; } @@ -63,20 +63,21 @@ int PoolMetaCache::get_remote_pool_meta( } void PoolMetaCache::set_remote_pool_meta( - int64_t pool_id, + const std::string& fsid, int64_t pool_id, const RemotePoolMeta& remote_pool_meta) { - dout(15) << "pool_id=" << pool_id << ", " - << "remote_pool_meta=" << remote_pool_meta << dendl; + dout(15) << "fsid=" << fsid << ", pool_id=" << pool_id + << ", remote_pool_meta=" << remote_pool_meta << dendl; std::unique_lock locker(m_lock); - m_remote_pool_metas[pool_id] = remote_pool_meta; + m_remote_pool_metas[{fsid, pool_id}] = remote_pool_meta; } -void PoolMetaCache::remove_remote_pool_meta(int64_t pool_id) { - dout(15) << "pool_id=" << pool_id << dendl; +void PoolMetaCache::remove_remote_pool_meta( + const std::string& fsid, int64_t pool_id) { + dout(15) << "fsid=" << fsid << ", pool_id=" << pool_id << dendl; std::unique_lock locker(m_lock); - m_remote_pool_metas.erase(pool_id); + m_remote_pool_metas.erase({fsid, pool_id}); } } // namespace mirror diff --git a/src/tools/rbd_mirror/PoolMetaCache.h b/src/tools/rbd_mirror/PoolMetaCache.h index f0440120fee06..58fcf2b2e66a2 100644 --- a/src/tools/rbd_mirror/PoolMetaCache.h +++ b/src/tools/rbd_mirror/PoolMetaCache.h @@ -26,11 +26,11 @@ public: const LocalPoolMeta& local_pool_meta); void remove_local_pool_meta(int64_t pool_id); - int get_remote_pool_meta(int64_t pool_id, + int get_remote_pool_meta(const std::string& fsid, int64_t pool_id, RemotePoolMeta* remote_pool_meta) const; - void set_remote_pool_meta(int64_t pool_id, + void set_remote_pool_meta(const std::string& fsid, int64_t pool_id, const RemotePoolMeta& remote_pool_meta); - void remove_remote_pool_meta(int64_t pool_id); + void remove_remote_pool_meta(const std::string& fsid, int64_t pool_id); private: CephContext* m_cct; @@ -38,7 +38,7 @@ private: mutable ceph::shared_mutex m_lock = ceph::make_shared_mutex("rbd::mirror::PoolMetaCache::m_lock"); std::map m_local_pool_metas; - std::map m_remote_pool_metas; + std::map, RemotePoolMeta> m_remote_pool_metas; }; } // namespace mirror diff --git a/src/tools/rbd_mirror/PoolReplayer.cc b/src/tools/rbd_mirror/PoolReplayer.cc index 19bc52fd86475..3534bb62aa950 100644 --- a/src/tools/rbd_mirror/PoolReplayer.cc +++ b/src/tools/rbd_mirror/PoolReplayer.cc @@ -326,6 +326,13 @@ void PoolReplayer::init(const std::string& site_name) { return; } + r = m_remote_rados->cluster_fsid(&m_remote_fsid); + if (r < 0) { + derr << "failed to retrieve remote cluster fsid: " << cpp_strerror(r) + << dendl; + return; + } + r = m_remote_rados->ioctx_create(m_local_io_ctx.get_pool_name().c_str(), m_remote_io_ctx); if (r < 0) { @@ -362,9 +369,10 @@ void PoolReplayer::init(const std::string& site_name) { m_remote_pool_poller.reset(); return; } + ceph_assert(!m_remote_pool_meta.mirror_uuid.empty()); m_pool_meta_cache->set_remote_pool_meta( - m_remote_io_ctx.get_id(), m_remote_pool_meta); + m_remote_fsid, m_remote_io_ctx.get_id(), m_remote_pool_meta); m_pool_meta_cache->set_local_pool_meta( m_local_io_ctx.get_id(), {m_local_mirror_uuid}); @@ -414,7 +422,8 @@ void PoolReplayer::shut_down() { m_remote_pool_poller->shut_down(&ctx); ctx.wait(); - m_pool_meta_cache->remove_remote_pool_meta(m_remote_io_ctx.get_id()); + m_pool_meta_cache->remove_remote_pool_meta(m_remote_fsid, + m_remote_io_ctx.get_id()); m_pool_meta_cache->remove_local_pool_meta(m_local_io_ctx.get_id()); } m_remote_pool_poller.reset(); diff --git a/src/tools/rbd_mirror/PoolReplayer.h b/src/tools/rbd_mirror/PoolReplayer.h index 7e673e5d5e5a0..0679b5654d5fc 100644 --- a/src/tools/rbd_mirror/PoolReplayer.h +++ b/src/tools/rbd_mirror/PoolReplayer.h @@ -214,6 +214,7 @@ private: librados::IoCtx m_remote_io_ctx; std::string m_local_mirror_uuid; + std::string m_remote_fsid; RemotePoolMeta m_remote_pool_meta; std::unique_ptr m_remote_pool_poller_listener; diff --git a/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc b/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc index 20fe59ebdf7d5..f8322a25ae6dc 100644 --- a/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc +++ b/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc @@ -150,9 +150,19 @@ void Replayer::init(Context* on_finish) { ceph_assert(m_state == STATE_INIT); + std::string remote_fsid; + librados::Rados remote_rados(m_state_builder->remote_image_ctx->md_ctx); + int r = remote_rados.cluster_fsid(&remote_fsid); + if (r < 0) { + derr << "failed to retrieve remote cluster fsid: " << cpp_strerror(r) + << dendl; + return; + } + RemotePoolMeta remote_pool_meta; - int r = m_pool_meta_cache->get_remote_pool_meta( - m_state_builder->remote_image_ctx->md_ctx.get_id(), &remote_pool_meta); + r = m_pool_meta_cache->get_remote_pool_meta( + remote_fsid, m_state_builder->remote_image_ctx->md_ctx.get_id(), + &remote_pool_meta); if (r < 0 || remote_pool_meta.mirror_peer_uuid.empty()) { derr << "failed to retrieve mirror peer uuid from remote pool" << dendl; m_state = STATE_COMPLETE; -- 2.39.5