From 241683e01c463650498254a2c002a73bb22a76bb Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 31 May 2017 12:56:51 -0400 Subject: [PATCH] librados: add rados_monitor_log2 that includes EntityName Signed-off-by: Sage Weil --- src/include/rados/librados.h | 32 ++++++++++++++++++++++++++++++++ src/librados/RadosClient.cc | 33 +++++++++++++++++++++++---------- src/librados/RadosClient.h | 4 +++- src/librados/librados.cc | 12 +++++++++++- src/tracing/librados.tp | 22 ++++++++++++++++++++++ 5 files changed, 91 insertions(+), 12 deletions(-) diff --git a/src/include/rados/librados.h b/src/include/rados/librados.h index ea9c0988aa3..8fa4b69f570 100644 --- a/src/include/rados/librados.h +++ b/src/include/rados/librados.h @@ -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 */ diff --git a/src/librados/RadosClient.cc b/src/librados/RadosClient.cc index 7cfa4d77b89..bf3a72f4de6 100644 --- a/src/librados/RadosClient.cc +++ b/src/librados/RadosClient.cc @@ -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& 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::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()); } } diff --git a/src/librados/RadosClient.h b/src/librados/RadosClient.h index 39e9a495707..b3f3016310d 100644 --- a/src/librados/RadosClient.h +++ b/src/librados/RadosClient.h @@ -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(); diff --git a/src/librados/librados.cc b/src/librados/librados.cc index 42be4c75724..1438952f886 100644 --- a/src/librados/librados.cc +++ b/src/librados/librados.cc @@ -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); diff --git a/src/tracing/librados.tp b/src/tracing/librados.tp index 451d04d4b69..f84e078a809 100644 --- a/src/tracing/librados.tp +++ b/src/tracing/librados.tp @@ -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, -- 2.39.5