]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: accept tell commands via MCommand and send them to asok handler
authorSage Weil <sage@redhat.com>
Fri, 6 Sep 2019 20:06:37 +0000 (15:06 -0500)
committerSage Weil <sage@redhat.com>
Tue, 1 Oct 2019 21:30:53 +0000 (16:30 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/mon/Monitor.cc
src/mon/Monitor.h

index 01d945a4667875a5424ec7af89d3622185903ca1..80b57bc1b984ff2bf67e43318475dc3000b72db5 100644 (file)
@@ -56,6 +56,9 @@
 #include "messages/MMonSubscribe.h"
 #include "messages/MMonSubscribeAck.h"
 
+#include "messages/MCommand.h"
+#include "messages/MCommandReply.h"
+
 #include "messages/MAuthReply.h"
 
 #include "messages/MTimeCheck2.h"
@@ -3099,12 +3102,34 @@ struct C_MgrProxyCommand : public Context {
   }
 };
 
+void Monitor::handle_tell_command(MonOpRequestRef op)
+{
+  ceph_assert(op->is_type_command());
+  MCommand *m = static_cast<MCommand*>(op->get_req());
+  if (m->fsid != monmap->fsid) {
+    dout(0) << "handle_command on fsid " << m->fsid << " != " << monmap->fsid << dendl;
+    reply_command(op, -EPERM, "wrong fsid", 0);
+    return;
+  }
+  MonSession *session = op->get_session();
+  if (!session) {
+    dout(5) << __func__ << " dropping stray message " << *m << dendl;
+    return;
+  }
+  if (!session->caps.is_allow_all()) {
+    reply_tell_command(op, -EPERM, "insufficient caps");
+  }
+  // pass it to asok
+  cct->get_admin_socket()->queue_tell_command(m);
+}
+
 void Monitor::handle_command(MonOpRequestRef op)
 {
   ceph_assert(op->is_type_command());
   auto m = op->get_req<MMonCommand>();
   if (m->fsid != monmap->fsid) {
-    dout(0) << "handle_command on fsid " << m->fsid << " != " << monmap->fsid << dendl;
+    dout(0) << "handle_command on fsid " << m->fsid << " != " << monmap->fsid
+           << dendl;
     reply_command(op, -EPERM, "wrong fsid", 0);
     return;
   }
@@ -3116,8 +3141,7 @@ void Monitor::handle_command(MonOpRequestRef op)
   }
 
   if (m->cmd.empty()) {
-    string rs = "No command supplied";
-    reply_command(op, -EINVAL, rs, 0);
+    reply_command(op, -EINVAL, "no command specified", 0);
     return;
   }
 
@@ -3909,6 +3933,16 @@ void Monitor::reply_command(MonOpRequestRef op, int rc, const string &rs,
   send_reply(op, reply);
 }
 
+void Monitor::reply_tell_command(
+  MonOpRequestRef op, int rc, const string &rs)
+{
+  MCommand *m = static_cast<MCommand*>(op->get_req());
+  ceph_assert(m->get_type() == MSG_COMMAND);
+  MCommandReply *reply = new MCommandReply(rc, rs);
+  reply->set_tid(m->get_tid());
+  m->get_connection()->send_message(reply);
+}
+
 
 // ------------------------
 // request/reply routing
@@ -4400,6 +4434,10 @@ void Monitor::dispatch_op(MonOpRequestRef op)
     case CEPH_MSG_PING:
       handle_ping(op);
       return;
+    case MSG_COMMAND:
+      op->set_type_command();
+      handle_tell_command(op);
+      return;
   }
 
   if (!op->get_session()->authenticated) {
index aa5f0612be983b27e4d35b65b56c808e36f34c61..fed943548391a8ef1611c76c6f0b01770366a04a 100644 (file)
@@ -688,6 +688,7 @@ public:
   void _quorum_status(Formatter *f, ostream& ss);
   bool _add_bootstrap_peer_hint(std::string_view cmd, const cmdmap_t& cmdmap,
                                std::ostream& ss);
+  void handle_tell_command(MonOpRequestRef op);
   void handle_command(MonOpRequestRef op);
   void handle_route(MonOpRequestRef op);
 
@@ -758,6 +759,9 @@ public:
   void reply_command(MonOpRequestRef op, int rc, const string &rs, version_t version);
   void reply_command(MonOpRequestRef op, int rc, const string &rs, bufferlist& rdata, version_t version);
 
+  void reply_tell_command(MonOpRequestRef op, int rc, const string &rs);
+
+
 
   void handle_probe(MonOpRequestRef op);
   /**