From: Colin Patrick McCabe Date: Fri, 20 May 2011 21:23:10 +0000 (-0700) Subject: dout: reopen log files on SIGHUP X-Git-Tag: v0.28.1~11 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=68021ce81e0299a183a0f5419decb7aba05d5ed3;p=ceph.git dout: reopen log files on SIGHUP Signed-off-by: Colin McCabe --- diff --git a/src/common/DoutStreambuf.cc b/src/common/DoutStreambuf.cc index 9ac48db348f..7c861737cf3 100644 --- a/src/common/DoutStreambuf.cc +++ b/src/common/DoutStreambuf.cc @@ -137,13 +137,15 @@ static int create_symlink(string oldpath, const string &newpath) ///////////////////////////// DoutStreambuf ///////////////////////////// template DoutStreambuf::DoutStreambuf() - : flags(0), ofd(-1) + : flags(0), ofd(-1), rlr(false) { // Initialize get pointer to zero so that underflow is called on the first read. this->setg(0, 0, 0); // Initialize output_buffer _clear_output_buffer(); + + pthread_spin_init(&rlr_lock, PTHREAD_PROCESS_PRIVATE); } template @@ -153,6 +155,7 @@ DoutStreambuf::~DoutStreambuf() TEMP_FAILURE_RETRY(::close(ofd)); ofd = -1; } + pthread_spin_destroy(&rlr_lock); } // This function is called when the output buffer is filled. @@ -383,6 +386,33 @@ DoutStreambuf::underflow() assert(0); } +template +void DoutStreambuf:: +request_log_reopen(void) +{ + pthread_spin_lock(&rlr_lock); + rlr = true; + pthread_spin_unlock(&rlr_lock); +} + +template +void DoutStreambuf:: +handle_log_reopen_requests(const md_config_t *conf) +{ + bool need; + pthread_spin_lock(&rlr_lock); + need = rlr; + pthread_spin_unlock(&rlr_lock); + if (!need) + return; + std::set changed; + const char **keys = get_tracked_conf_keys(); + for (const char **k = keys; *k; ++k) { + changed.insert(*k); + } + handle_conf_change(conf, changed); +} + template void DoutStreambuf::_clear_output_buffer() { diff --git a/src/common/DoutStreambuf.h b/src/common/DoutStreambuf.h index c272f7d7b74..146c482cf5e 100644 --- a/src/common/DoutStreambuf.h +++ b/src/common/DoutStreambuf.h @@ -75,6 +75,18 @@ public: // (if those sinks are active) void dout_emergency_to_file_and_syslog(const char * const str) const; + // The next two functions are used to implement the Ceph daemons' + // SIGHUP handling. + + // Set the request_log_reopen bit. + // Signal-safe. + void request_log_reopen(void); + + // Read the request_log_reopen bit. + // If it's set, reopen the log. + // This is meant to be called from an event loop. Not signal-safe. + void handle_log_reopen_requests(const md_config_t *conf); + protected: // Called when the buffer fills up virtual int_type overflow(int_type c); @@ -108,6 +120,9 @@ private: std::string opath; std::string symlink_dir; std::string isym_path; + + pthread_spinlock_t rlr_lock; + bool rlr; }; // Secret evil interfaces for writing logs without taking the lock. diff --git a/src/common/signal.cc b/src/common/signal.cc index fa479b701ff..e8d8323674d 100644 --- a/src/common/signal.cc +++ b/src/common/signal.cc @@ -13,6 +13,7 @@ */ #include "common/BackTrace.h" +#include "common/DoutStreambuf.h" #include "common/ProfLogger.h" #include "common/pidfile.h" #include "common/debug.h" @@ -51,10 +52,7 @@ void install_sighandler(int signum, signal_handler_t handler, int flags) void sighup_handler(int signum) { - /* In the past, users had to send a SIGHUP to the process after making a - * change to certain parts of the logging configuration. Now, this is no - * longer necessary. Now we want to ignore SIGHUP signals. - */ + g_conf._doss->request_log_reopen(); } static void reraise_fatal(int signum) diff --git a/src/mds/MDS.cc b/src/mds/MDS.cc index aaa3fc9097c..69359299d80 100644 --- a/src/mds/MDS.cc +++ b/src/mds/MDS.cc @@ -70,6 +70,7 @@ #include "auth/KeyRing.h" #include "common/config.h" +#include "common/DoutStreambuf.h" #include "perfglue/cpu_profiler.h" #include "perfglue/heap_profiler.h" @@ -584,6 +585,8 @@ void MDS::tick() if (snapserver) snapserver->check_osd_map(false); } + + g_conf._doss->handle_log_reopen_requests(&g_conf); } diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index eb16f9480de..3c526df8c14 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -42,6 +42,7 @@ #include "common/ceph_argparse.h" #include "common/Timer.h" #include "common/Clock.h" +#include "common/DoutStreambuf.h" #include "include/color.h" #include "OSDMonitor.h" @@ -964,6 +965,8 @@ void Monitor::tick() } } + g_conf._doss->handle_log_reopen_requests(&g_conf); + new_tick(); } diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 468d68e0e53..0840ddf9e76 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -69,6 +69,7 @@ #include "messages/MWatchNotify.h" +#include "common/DoutStreambuf.h" #include "common/ProfLogger.h" #include "common/ProfLogType.h" #include "common/Timer.h" @@ -1814,6 +1815,8 @@ void OSD::tick() dispatch_running = false; dispatch_cond.Signal(); } + + g_conf._doss->handle_log_reopen_requests(&g_conf); } // =========================================