From 281c88bcc1516899a831fb083b230b69cd1a51aa Mon Sep 17 00:00:00 2001 From: Dhairya Parmar Date: Wed, 2 Aug 2023 13:12:19 +0530 Subject: [PATCH] tools/cephfs_mirror: only perform actions if init succeed address non-zero return code first and then perform further actions. Fixes: https://tracker.ceph.com/issues/62357 Signed-off-by: Dhairya Parmar --- src/tools/cephfs_mirror/Mirror.cc | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/tools/cephfs_mirror/Mirror.cc b/src/tools/cephfs_mirror/Mirror.cc index 890805764c048..3afcf6b9272b5 100644 --- a/src/tools/cephfs_mirror/Mirror.cc +++ b/src/tools/cephfs_mirror/Mirror.cc @@ -319,19 +319,24 @@ void Mirror::handle_enable_mirroring(const Filesystem &filesystem, std::scoped_lock locker(m_lock); auto &mirror_action = m_mirror_actions.at(filesystem); - ceph_assert(mirror_action.action_in_progress); - mirror_action.action_in_progress = false; - m_cond.notify_all(); if (r < 0) { derr << ": failed to initialize FSMirror for filesystem=" << filesystem << ": " << cpp_strerror(r) << dendl; + // since init failed, don't assert, just unset it directly + mirror_action.action_in_progress = false; + m_cond.notify_all(); m_service_daemon->add_or_update_fs_attribute(filesystem.fscid, SERVICE_DAEMON_MIRROR_ENABLE_FAILED_KEY, true); return; } + ceph_assert(mirror_action.action_in_progress); + + mirror_action.action_in_progress = false; + m_cond.notify_all(); + for (auto &peer : peers) { mirror_action.fs_mirror->add_peer(peer); } @@ -344,19 +349,24 @@ void Mirror::handle_enable_mirroring(const Filesystem &filesystem, int r) { std::scoped_lock locker(m_lock); auto &mirror_action = m_mirror_actions.at(filesystem); - ceph_assert(mirror_action.action_in_progress); - - mirror_action.action_in_progress = false; - m_cond.notify_all(); + if (r < 0) { derr << ": failed to initialize FSMirror for filesystem=" << filesystem << ": " << cpp_strerror(r) << dendl; + // since init failed, don't assert, just unset it directly + mirror_action.action_in_progress = false; + m_cond.notify_all(); m_service_daemon->add_or_update_fs_attribute(filesystem.fscid, SERVICE_DAEMON_MIRROR_ENABLE_FAILED_KEY, true); return; } + ceph_assert(mirror_action.action_in_progress); + + mirror_action.action_in_progress = false; + m_cond.notify_all(); + dout(10) << ": Initialized FSMirror for filesystem=" << filesystem << dendl; }