]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
dout: reopen log files on SIGHUP
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Fri, 20 May 2011 21:23:10 +0000 (14:23 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Fri, 20 May 2011 21:23:10 +0000 (14:23 -0700)
Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/common/DoutStreambuf.cc
src/common/DoutStreambuf.h
src/common/signal.cc
src/mds/MDS.cc
src/mon/Monitor.cc
src/osd/OSD.cc

index 9ac48db348fb5c5f128a9234524dcce31dd283f6..7c861737cf386ffc95e557eb3cbb3687902a2fe1 100644 (file)
@@ -137,13 +137,15 @@ static int create_symlink(string oldpath, const string &newpath)
 ///////////////////////////// DoutStreambuf /////////////////////////////
 template <typename charT, typename traits>
 DoutStreambuf<charT, traits>::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 <typename charT, typename traits>
@@ -153,6 +155,7 @@ DoutStreambuf<charT, traits>::~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<charT, traits>::underflow()
   assert(0);
 }
 
+template <typename charT, typename traits>
+void DoutStreambuf<charT, traits>::
+request_log_reopen(void)
+{
+  pthread_spin_lock(&rlr_lock);
+  rlr = true;
+  pthread_spin_unlock(&rlr_lock);
+}
+
+template <typename charT, typename traits>
+void DoutStreambuf<charT, traits>::
+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 <std::string> changed;
+  const char **keys = get_tracked_conf_keys();
+  for (const char **k = keys; *k; ++k) {
+    changed.insert(*k);
+  }
+  handle_conf_change(conf, changed);
+}
+
 template <typename charT, typename traits>
 void DoutStreambuf<charT, traits>::_clear_output_buffer()
 {
index c272f7d7b746d0008c4f360c1a565ba217736c58..146c482cf5e73cff8925a2b3a43572844abdf5ed 100644 (file)
@@ -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.
index fa479b701ffdc7fa9e0d06e3a9898a7d7ebd538a..e8d8323674dcd72b13e0b40e738145caea58860c 100644 (file)
@@ -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)
index fa7784fe729f9590ba17b4dbafd2c2cf7fa1a8ff..f3761bcd90be148e873611d695bd1bb4d1ffa2a9 100644 (file)
@@ -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"
@@ -585,6 +586,8 @@ void MDS::tick()
     if (snapserver)
       snapserver->check_osd_map(false);
   }
+
+  g_conf._doss->handle_log_reopen_requests(&g_conf);
 }
 
 
index ff60c8a0ef78e396a841b700559bdda40e3715f3..127f13574dfda8c1a30a83b2e576919d406a2f8c 100644 (file)
@@ -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();
 }
 
index dc863bb49dee9d176573c0146c8597794ce19d49..27317585c78e2f38a2397603a21077a6930887cd 100644 (file)
@@ -69,6 +69,7 @@
 
 #include "messages/MWatchNotify.h"
 
+#include "common/DoutStreambuf.h"
 #include "common/ProfLogger.h"
 #include "common/ProfLogType.h"
 #include "common/Timer.h"
@@ -1791,6 +1792,8 @@ void OSD::tick()
     dispatch_running = false;
     dispatch_cond.Signal();
   }
+
+  g_conf._doss->handle_log_reopen_requests(&g_conf);
 }
 
 // =========================================