diff --git a/src/tools/rbd_mirror/Mirror.cc b/src/tools/rbd_mirror/Mirror.cc index 1a6604484f4..787c6980ecf 100644 --- a/src/tools/rbd_mirror/Mirror.cc +++ b/src/tools/rbd_mirror/Mirror.cc @@ -1,6 +1,8 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab +#include + #include #include "common/Formatter.h" @@ -498,10 +500,26 @@ Mirror::~Mirror() void Mirror::handle_signal(int signum) { - m_stopping = true; - { - std::lock_guard l{m_lock}; + dout(20) << signum << dendl; + + std::lock_guard l{m_lock}; + + switch (signum) { + case SIGHUP: + for (auto &it : m_pool_replayers) { + it.second->reopen_logs(); + } + g_ceph_context->reopen_logs(); + break; + + case SIGINT: + case SIGTERM: + m_stopping = true; m_cond.notify_all(); + break; + + default: + ceph_abort_msgf("unexpected signal %d", signum); } } diff --git a/src/tools/rbd_mirror/PoolReplayer.cc b/src/tools/rbd_mirror/PoolReplayer.cc index 0447289797f..30a312aad15 100644 --- a/src/tools/rbd_mirror/PoolReplayer.cc +++ b/src/tools/rbd_mirror/PoolReplayer.cc @@ -248,6 +248,8 @@ bool PoolReplayer::is_running() const { template void PoolReplayer::init(const std::string& site_name) { + std::lock_guard locker{m_lock}; + ceph_assert(!m_pool_replayer_thread.is_started()); // reset state @@ -697,6 +699,19 @@ int PoolReplayer::list_mirroring_namespaces( return 0; } +template +void PoolReplayer::reopen_logs() +{ + std::lock_guard locker{m_lock}; + + if (m_local_rados) { + reinterpret_cast(m_local_rados->cct())->reopen_logs(); + } + if (m_remote_rados) { + reinterpret_cast(m_remote_rados->cct())->reopen_logs(); + } +} + template void PoolReplayer::namespace_replayer_acquire_leader(const std::string &name, Context *on_finish) { diff --git a/src/tools/rbd_mirror/PoolReplayer.h b/src/tools/rbd_mirror/PoolReplayer.h index 312de1f4439..9f295f4788c 100644 --- a/src/tools/rbd_mirror/PoolReplayer.h +++ b/src/tools/rbd_mirror/PoolReplayer.h @@ -64,6 +64,7 @@ public: void restart(); void flush(); void release_leader(); + void reopen_logs(); private: /** diff --git a/src/tools/rbd_mirror/main.cc b/src/tools/rbd_mirror/main.cc index 8a5111e3aec..ab350a014cf 100644 --- a/src/tools/rbd_mirror/main.cc +++ b/src/tools/rbd_mirror/main.cc @@ -56,7 +56,7 @@ int main(int argc, const char **argv) common_init_finish(g_ceph_context); init_async_signal_handler(); - register_async_signal_handler(SIGHUP, sighup_handler); + register_async_signal_handler(SIGHUP, handle_signal); register_async_signal_handler_oneshot(SIGINT, handle_signal); register_async_signal_handler_oneshot(SIGTERM, handle_signal); @@ -90,7 +90,7 @@ int main(int argc, const char **argv) mirror->run(); cleanup: - unregister_async_signal_handler(SIGHUP, sighup_handler); + unregister_async_signal_handler(SIGHUP, handle_signal); unregister_async_signal_handler(SIGINT, handle_signal); unregister_async_signal_handler(SIGTERM, handle_signal); shutdown_async_signal_handler();