Skip to content

Commit

Permalink
tools/cephfs_mirror: only perform actions if init succeed
Browse files Browse the repository at this point in the history
address non-zero return code first and then perform further
actions.

Fixes: https://tracker.ceph.com/issues/62357
Signed-off-by: Dhairya Parmar <[email protected]>
  • Loading branch information
dparmar18 committed Aug 8, 2023
1 parent 4e5d800 commit 281c88b
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/tools/cephfs_mirror/Mirror.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
}

Expand Down

0 comments on commit 281c88b

Please sign in to comment.