summaryrefslogtreecommitdiff
path: root/src/mon
diff options
context:
space:
mode:
authorSage Weil <sage@inktank.com>2012-07-09 17:24:19 -0700
committerSage Weil <sage@inktank.com>2012-08-14 09:22:35 -0700
commitdc2a232bd37b7202c3d6e94396b3d85cec5225cd (patch)
tree526964afffcd0488cb44866894189524967c8f0e /src/mon
parenta7ad701b9bd479f20429f19e6fea7373ca6bba7c (diff)
downloadceph-dc2a232bd37b7202c3d6e94396b3d85cec5225cd.tar.gz
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 <sage@inktank.com>
Diffstat (limited to 'src/mon')
-rw-r--r--src/mon/LogMonitor.cc48
-rw-r--r--src/mon/LogMonitor.h9
-rw-r--r--src/mon/Monitor.cc4
3 files changed, 34 insertions, 27 deletions
diff --git a/src/mon/LogMonitor.cc b/src/mon/LogMonitor.cc
index 468c5fe9748..41b15b4ab62 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<string, xlist<Subscription*>*>::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<Subscription*> *subs_lst = subs_map_it->second;
- xlist<Subscription*>::iterator subs_lst_it = subs_lst->begin();
-
- for (; !subs_lst_it.end(); ++subs_lst_it)
- check_sub(*subs_lst_it);
+ for (map<string, xlist<Subscription*>*>::iterator i = mon->session_map.subs.begin();
+ i != mon->session_map.subs.end();
+ i++) {
+ for (xlist<Subscription*>::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<string, int> 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 a2ce987603f..884cd6b1f74 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 5903ac4f52d..1db0a257e4a 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]);
}
}