]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: make 'log ...' command wait for commit before reply
authorSage Weil <sage@inktank.com>
Thu, 20 Jun 2013 18:11:50 +0000 (11:11 -0700)
committerSage Weil <sage@inktank.com>
Thu, 20 Jun 2013 18:11:50 +0000 (11:11 -0700)
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>
src/mon/LogMonitor.cc
src/mon/Monitor.cc

index 0a62be8bbba8e7da0d9b07f822d20a700e4e8f57..dec79176ae57e0fb1065fb7efa13327bd0c0bf71 100644 (file)
@@ -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());
index d831708f398974f54f628258e4369935fb8980b8..7b8d95173f0e19dd809a5acde11e0973807a0eb4 100644 (file)
@@ -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) {