From 7adc6c08f1474806c83ef6c89e8752d6cfd35bfd Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 9 Jul 2012 17:24:19 -0700 Subject: [PATCH] mon: simplify logmonitor check_subs; less noise * simple helper to translate name to id * verify sub type is valid in caller * assert sub type is valid in method * simplify iterator usage Among other things, this gets rid of this noise in the logs: 2012-07-10 20:51:42.617152 7facb23f1700 1 mon.a@1(peon).log v310 check_sub sub monmap not log type Signed-off-by: Sage Weil --- src/mon/LogMonitor.cc | 48 +++++++++++++++++++++---------------------- src/mon/LogMonitor.h | 9 ++++++++ src/mon/Monitor.cc | 4 +--- 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/mon/LogMonitor.cc b/src/mon/LogMonitor.cc index 468c5fe974862..41b15b4ab623f 100644 --- a/src/mon/LogMonitor.cc +++ b/src/mon/LogMonitor.cc @@ -320,20 +320,31 @@ bool LogMonitor::prepare_command(MMonCommand *m) } +int LogMonitor::sub_name_to_id(const string& n) +{ + if (n == "log-debug") + return CLOG_DEBUG; + if (n == "log-info") + return CLOG_INFO; + if (n == "log-sec") + return CLOG_SEC; + if (n == "log-warn") + return CLOG_WARN; + if (n == "log-error") + return CLOG_ERROR; + return -1; +} + void LogMonitor::check_subs() { dout(10) << __func__ << dendl; - - map*>::iterator subs_map_it; - subs_map_it = mon->session_map.subs.begin(); - - for (; subs_map_it != mon->session_map.subs.end(); subs_map_it++) { - - xlist *subs_lst = subs_map_it->second; - xlist::iterator subs_lst_it = subs_lst->begin(); - - for (; !subs_lst_it.end(); ++subs_lst_it) - check_sub(*subs_lst_it); + for (map*>::iterator i = mon->session_map.subs.begin(); + i != mon->session_map.subs.end(); + i++) { + for (xlist::iterator j = i->second->begin(); !j.end(); ++j) { + if (sub_name_to_id((*j)->type) >= 0) + check_sub(*j); + } } } @@ -341,20 +352,10 @@ void LogMonitor::check_sub(Subscription *s) { dout(10) << __func__ << " client wants " << s->type << " ver " << s->next << dendl; - map types; - types["log-debug"] = CLOG_DEBUG; - types["log-info"] = CLOG_INFO; - types["log-sec"] = CLOG_SEC; - types["log-warn"] = CLOG_WARN; - types["log-error"] = CLOG_ERROR; - - if (!types.count(s->type)) { - dout(1) << __func__ << " sub " << s->type << " not log type " << dendl; - return; - } + int sub_level = sub_name_to_id(s->type); + assert(sub_level >= 0); version_t summary_version = summary.version; - if (s->next > summary_version) { dout(10) << __func__ << " client " << s->session->inst << " requested version (" << s->next << ") is greater than ours (" @@ -363,7 +364,6 @@ void LogMonitor::check_sub(Subscription *s) return; } - int sub_level = types[s->type]; MLog *mlog = new MLog(mon->monmap->fsid); if (s->next == 0) { diff --git a/src/mon/LogMonitor.h b/src/mon/LogMonitor.h index a2ce987603fe8..884cd6b1f7402 100644 --- a/src/mon/LogMonitor.h +++ b/src/mon/LogMonitor.h @@ -69,6 +69,15 @@ private: void check_subs(); void check_sub(Subscription *s); + + /** + * translate log sub name ('log-info') to integer id + * + * @param n name + * @return id, or -1 if unrecognized + */ + int sub_name_to_id(const string& n); + }; #endif diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 5903ac4f52daf..1db0a257e4ab3 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -1819,9 +1819,7 @@ void Monitor::handle_subscribe(MMonSubscribe *m) } } else if (p->first == "monmap") { check_sub(s->sub_map["monmap"]); - } else if ((p->first == "log-error") || (p->first == "log-warn") - || (p->first == "log-sec") || (p->first == "log-info") - || (p->first == "log-debug")) { + } else if (logmon()->sub_name_to_id(p->first) >= 0) { logmon()->check_sub(s->sub_map[p->first]); } } -- 2.39.5