diff options
author | Sage Weil <sage@inktank.com> | 2013-06-20 11:11:50 -0700 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2013-06-20 11:11:50 -0700 |
commit | 4a038d6df531ac2e9b4268d9b730dca1e38c32a9 (patch) | |
tree | 786552f4c0a924cf4cb17b91d382c315af2eb8b2 | |
parent | 5de54f6a79ebee051033b28b3bcb7352d1da0e9b (diff) | |
download | ceph-4a038d6df531ac2e9b4268d9b730dca1e38c32a9.tar.gz |
mon: make 'log ...' command wait for commit before reply
Previously we would just dump the command argument to our local log client
and reply immediately, which could lose the message if we then restarted.
Instead, commit directly and wait before replying.
Also, log as the actual client, not as the monitor processing the message.
Fixes: #5409
Signed-off-by: Sage Weil <sage@inktank.com>
Reviewed-by: Dan Mick <dan.mick@inktank.com>
-rw-r--r-- | src/mon/LogMonitor.cc | 39 | ||||
-rw-r--r-- | src/mon/Monitor.cc | 19 |
2 files changed, 40 insertions, 18 deletions
diff --git a/src/mon/LogMonitor.cc b/src/mon/LogMonitor.cc index 0a62be8bbba..dec79176ae5 100644 --- a/src/mon/LogMonitor.cc +++ b/src/mon/LogMonitor.cc @@ -302,7 +302,6 @@ bool LogMonitor::prepare_log(MLog *m) if (!pending_summary.contains(p->key())) { pending_summary.add(*p); pending_log.insert(pair<utime_t,LogEntry>(p->stamp, *p)); - } } wait_for_finished_proposal(new C_Log(this, m)); @@ -351,8 +350,42 @@ bool LogMonitor::prepare_command(MMonCommand *m) string rs; int err = -EINVAL; - // nothing here yet - ss << "unrecognized command"; + map<string, cmd_vartype> cmdmap; + if (!cmdmap_from_json(m->cmd, &cmdmap, ss)) { + // ss has reason for failure + string rs = ss.str(); + mon->reply_command(m, -EINVAL, rs, get_version()); + return true; + } + + string prefix; + cmd_getval(g_ceph_context, cmdmap, "prefix", prefix); + + MonSession *session = m->get_session(); + if (!session || + (!session->is_capable("log", MON_CAP_W) && + !mon->_allowed_command(session, cmdmap))) { + mon->reply_command(m, -EACCES, "access denied", get_version()); + return true; + } + + if (prefix == "log") { + vector<string> logtext; + cmd_getval(g_ceph_context, cmdmap, "logtext", logtext); + ostringstream ds; + std::copy(logtext.begin(), logtext.end(), + ostream_iterator<string>(ds, " ")); + LogEntry le; + le.who = m->get_orig_source_inst(); + le.stamp = m->get_recv_stamp(); + le.seq = 0; + le.type = CLOG_INFO; + le.msg = ds.str(); + pending_summary.add(le); + pending_log.insert(pair<utime_t,LogEntry>(le.stamp, le)); + wait_for_finished_proposal(new Monitor::C_Command(mon, m, 0, string(), get_version())); + return true; + } getline(ss, rs); mon->reply_command(m, err, rs, get_version()); diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index d831708f398..7b8d95173f0 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -2632,6 +2632,10 @@ void Monitor::handle_command(MMonCommand *m) authmon()->dispatch(m); return; } + if (module == "log") { + logmon()->dispatch(m); + return; + } if (module == "config-key") { if (!access_all) { @@ -2649,21 +2653,6 @@ void Monitor::handle_command(MMonCommand *m) reply_command(m, 0, "", rdata, 0); return; } - if (prefix == "log") { - if (!access_r) { - r = -EACCES; - rs = "access denied"; - goto out; - } - vector<string> logtext; - cmd_getval(g_ceph_context, cmdmap, "logtext", logtext); - std::copy(logtext.begin(), logtext.end(), - ostream_iterator<string>(ds, " ")); - clog.info(ds); - rs = "ok"; - reply_command(m, 0, rs, 0); - return; - } if (prefix == "compact") { if (!access_all) { |