]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
librados: add rados_monitor_log2 that includes EntityName
authorSage Weil <sage@redhat.com>
Wed, 31 May 2017 16:56:51 +0000 (12:56 -0400)
committerSage Weil <sage@redhat.com>
Wed, 31 May 2017 18:39:55 +0000 (14:39 -0400)
Signed-off-by: Sage Weil <sage@redhat.com>
src/include/rados/librados.h
src/librados/RadosClient.cc
src/librados/RadosClient.h
src/librados/librados.cc
src/tracing/librados.tp

index ea9c0988aa3481e76b70b1652d5bda649528b86b..8fa4b69f5709b468f3cdc112ae2042bbf06df1ba 100644 (file)
@@ -3653,8 +3653,40 @@ typedef void (*rados_log_callback_t)(void *arg,
                                     uint64_t seq, const char *level,
                                     const char *msg);
 
+/*
+ * This is not a doxygen comment leadin, because doxygen breaks on
+ * a typedef with function params and returns, and I can't figure out
+ * how to fix it.
+ *
+ * Monitor cluster log
+ *
+ * Monitor events logged to the cluster log.  The callback get each
+ * log entry both as a single formatted line and with each field in a
+ * separate arg.
+ *
+ * Calling with a cb argument of NULL will deregister any previously
+ * registered callback.
+ *
+ * @param cluster cluster handle
+ * @param level minimum log level (debug, info, warn|warning, err|error)
+ * @param cb callback to run for each log message. It MUST NOT block
+ * nor call back into librados.
+ * @param arg void argument to pass to cb
+ *
+ * @returns 0 on success, negative code on error
+ */
+typedef void (*rados_log_callback2_t)(void *arg,
+                                    const char *line,
+                                    const char *who,
+                                    const char *name,
+                                    uint64_t sec, uint64_t nsec,
+                                    uint64_t seq, const char *level,
+                                    const char *msg);
+
 CEPH_RADOS_API int rados_monitor_log(rados_t cluster, const char *level,
                                      rados_log_callback_t cb, void *arg);
+CEPH_RADOS_API int rados_monitor_log2(rados_t cluster, const char *level,
+                                     rados_log_callback2_t cb, void *arg);
 
 /** @} Mon/OSD/PG commands */
 
index 7cfa4d77b895adfc49a40de855c346f36ca8304d..bf3a72f4de6fcbed8700d371286db79f6c2eeb8a 100644 (file)
@@ -77,7 +77,7 @@ librados::RadosClient::RadosClient(CephContext *cct_)
     lock("librados::RadosClient::lock"),
     timer(cct, lock),
     refcnt(1),
-    log_last_version(0), log_cb(NULL), log_cb_arg(NULL),
+    log_last_version(0), log_cb(NULL), log_cb2(NULL), log_cb_arg(NULL),
     finisher(cct, "radosclient", "fn-radosclient")
 {
 }
@@ -920,7 +920,10 @@ int librados::RadosClient::pg_command(pg_t pgid, vector<string>& cmd,
   return ret;
 }
 
-int librados::RadosClient::monitor_log(const string& level, rados_log_callback_t cb, void *arg)
+int librados::RadosClient::monitor_log(const string& level,
+                                      rados_log_callback_t cb,
+                                      rados_log_callback2_t cb2,
+                                      void *arg)
 {
   Mutex::Locker l(lock);
 
@@ -928,12 +931,14 @@ int librados::RadosClient::monitor_log(const string& level, rados_log_callback_t
     return -ENOTCONN;
   }
 
-  if (cb == NULL) {
+  if (cb == NULL && cb2 == NULL) {
     // stop watch
-    ldout(cct, 10) << __func__ << " removing cb " << (void*)log_cb << dendl;
+    ldout(cct, 10) << __func__ << " removing cb " << (void*)log_cb
+                  << " " << (void*)log_cb2 << dendl;
     monclient.sub_unwant(log_watch);
     log_watch.clear();
     log_cb = NULL;
+    log_cb2 = NULL;
     log_cb_arg = NULL;
     return 0;
   }
@@ -954,15 +959,17 @@ int librados::RadosClient::monitor_log(const string& level, rados_log_callback_t
     return -EINVAL;
   }
 
-  if (log_cb)
+  if (log_cb || log_cb2)
     monclient.sub_unwant(log_watch);
 
   // (re)start watch
-  ldout(cct, 10) << __func__ << " add cb " << (void*)cb << " level " << level << dendl;
+  ldout(cct, 10) << __func__ << " add cb " << (void*)cb << " " << (void*)cb2
+                << " level " << level << dendl;
   monclient.sub_want(watch_level, 0, 0);
 
   monclient.renew_subs();
   log_cb = cb;
+  log_cb2 = cb2;
   log_cb_arg = arg;
   log_watch = watch_level;
   return 0;
@@ -976,21 +983,27 @@ void librados::RadosClient::handle_log(MLog *m)
   if (log_last_version < m->version) {
     log_last_version = m->version;
 
-    if (log_cb) {
+    if (log_cb || log_cb2) {
       for (std::deque<LogEntry>::iterator it = m->entries.begin(); it != m->entries.end(); ++it) {
         LogEntry e = *it;
         ostringstream ss;
         ss << e.stamp << " " << e.name << " " << e.prio << " " << e.msg;
         string line = ss.str();
         string who = stringify(e.who);
+       string name = stringify(e.name);
         string level = stringify(e.prio);
         struct timespec stamp;
         e.stamp.to_timespec(&stamp);
 
         ldout(cct, 20) << __func__ << " delivering " << ss.str() << dendl;
-        log_cb(log_cb_arg, line.c_str(), who.c_str(),
-               stamp.tv_sec, stamp.tv_nsec,
-               e.seq, level.c_str(), e.msg.c_str());
+       if (log_cb)
+         log_cb(log_cb_arg, line.c_str(), who.c_str(),
+                stamp.tv_sec, stamp.tv_nsec,
+                e.seq, level.c_str(), e.msg.c_str());
+       if (log_cb2)
+         log_cb2(log_cb_arg, line.c_str(), who.c_str(), name.c_str(),
+                 stamp.tv_sec, stamp.tv_nsec,
+                 e.seq, level.c_str(), e.msg.c_str());
       }
     }
 
index 39e9a49570762c5ab47a2e6f572ed9752ff1a732..b3f3016310d4a789e17fc6feedf119da06404a55 100644 (file)
@@ -74,6 +74,7 @@ private:
 
   version_t log_last_version;
   rados_log_callback_t log_cb;
+  rados_log_callback2_t log_cb2;
   void *log_cb_arg;
   string log_watch;
 
@@ -144,7 +145,8 @@ public:
                 bufferlist *poutbl, string *prs);
 
   void handle_log(MLog *m);
-  int monitor_log(const string& level, rados_log_callback_t cb, void *arg);
+  int monitor_log(const string& level, rados_log_callback_t cb,
+                 rados_log_callback2_t cb2, void *arg);
 
   void get();
   bool put();
index 42be4c7572410fd4d29051781038a176676ca8a8..1438952f8864cf950cadfa9bacf14c13c6083a97 100644 (file)
@@ -3375,11 +3375,21 @@ extern "C" int rados_monitor_log(rados_t cluster, const char *level, rados_log_c
 {
   tracepoint(librados, rados_monitor_log_enter, cluster, level, cb, arg);
   librados::RadosClient *client = (librados::RadosClient *)cluster;
-  int retval = client->monitor_log(level, cb, arg);
+  int retval = client->monitor_log(level, cb, nullptr, arg);
   tracepoint(librados, rados_monitor_log_exit, retval);
   return retval;
 }
 
+extern "C" int rados_monitor_log2(rados_t cluster, const char *level,
+                                 rados_log_callback2_t cb, void *arg)
+{
+  tracepoint(librados, rados_monitor_log2_enter, cluster, level, cb, arg);
+  librados::RadosClient *client = (librados::RadosClient *)cluster;
+  int retval = client->monitor_log(level, nullptr, cb, arg);
+  tracepoint(librados, rados_monitor_log2_exit, retval);
+  return retval;
+}
+
 extern "C" int rados_ioctx_create(rados_t cluster, const char *name, rados_ioctx_t *io)
 {
   tracepoint(librados, rados_ioctx_create_enter, cluster, name);
index 451d04d4b6910eb2e9b6083a1d1defe4b325a798..f84e078a8098247e20d293c2ebbd1b880042da9e 100644 (file)
@@ -651,6 +651,28 @@ TRACEPOINT_EVENT(librados, rados_monitor_log_exit,
     )
 )
 
+TRACEPOINT_EVENT(librados, rados_monitor_log2_enter,
+    TP_ARGS(
+        rados_t, cluster,
+        const char*, level,
+        rados_log_callback2_t, callback,
+        void*, arg),
+    TP_FIELDS(
+        ctf_integer_hex(rados_t, cluster, cluster)
+        ceph_ctf_string(level, level)
+        ctf_integer_hex(rados_log_callback2_t, callback, callback)
+        ctf_integer_hex(void*, arg, arg)
+    )
+)
+
+TRACEPOINT_EVENT(librados, rados_monitor_log2_exit,
+    TP_ARGS(
+        int, retval),
+    TP_FIELDS(
+        ctf_integer(int, retval, retval)
+    )
+)
+
 TRACEPOINT_EVENT(librados, rados_ioctx_create_enter,
     TP_ARGS(
         rados_t, cluster,