From 4a038d6df531ac2e9b4268d9b730dca1e38c32a9 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 20 Jun 2013 11:11:50 -0700 Subject: [PATCH] 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 Reviewed-by: Dan Mick --- src/mon/LogMonitor.cc | 39 ++++++++++++++++++++++++++++++++++++--- 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 0a62be8bbba8e..dec79176ae57e 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(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 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 logtext; + cmd_getval(g_ceph_context, cmdmap, "logtext", logtext); + ostringstream ds; + std::copy(logtext.begin(), logtext.end(), + ostream_iterator(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(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 d831708f39897..7b8d95173f0e1 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 logtext; - cmd_getval(g_ceph_context, cmdmap, "logtext", logtext); - std::copy(logtext.begin(), logtext.end(), - ostream_iterator(ds, " ")); - clog.info(ds); - rs = "ok"; - reply_command(m, 0, rs, 0); - return; - } if (prefix == "compact") { if (!access_all) { -- 2.39.5