]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
admin_socket: pass args separately
authorSage Weil <sage@inktank.com>
Thu, 31 May 2012 03:28:51 +0000 (20:28 -0700)
committerSage Weil <sage@inktank.com>
Thu, 31 May 2012 04:58:17 +0000 (21:58 -0700)
This avoids making the callback parse off the command portion on their own.
It also lets them assert that the command portion is in the set of
registered commands.

Signed-off-by: Sage Weil <sage@inktank.com>
src/common/admin_socket.cc
src/common/admin_socket.h
src/common/ceph_context.cc
src/common/ceph_context.h
src/mon/Monitor.cc
src/mon/Monitor.h
src/osd/OSD.cc
src/osdc/Objecter.cc
src/osdc/Objecter.h

index 750abaddc137b8961d367c35d289171ab5656822..283eec7b3086394a81cbadf4766d98c1c39ccc23 100644 (file)
@@ -327,14 +327,17 @@ bool AdminSocket::do_accept()
   if (match.size() == 0) {
     lderr(m_cct) << "AdminSocket: request '" << c << "' not defined" << dendl;
   } else {
-    bool success = p->second->call(c, out);
+    string args;
+    if (match != c)
+      args = c.substr(match.length() + 1);
+    bool success = p->second->call(match, args, out);
     if (!success) {
-      ldout(m_cct, 0) << "AdminSocket: request '" << c << "' (" << match
-                     << ") to " << p->second << " failed" << dendl;
+      ldout(m_cct, 0) << "AdminSocket: request '" << match << "' args '" << args
+                     << "' to " << p->second << " failed" << dendl;
       out.append("failed");
     } else {
-      ldout(m_cct, 20) << "AdminSocket: request '" << c << "' (" << match
-                      << ") to " << p->second
+      ldout(m_cct, 20) << "AdminSocket: request '" << match << "' '" << args
+                      << "' to " << p->second
                       << " returned " << out.length() << " bytes" << dendl;
     }
     uint32_t len = htonl(out.length());
@@ -391,7 +394,7 @@ int AdminSocket::unregister_command(std::string command)
 
 class VersionHook : public AdminSocketHook {
 public:
-  virtual bool call(std::string command, bufferlist& out) {
+  virtual bool call(std::string command, std::string args, bufferlist& out) {
     if (command == "version")
       out.append(ceph_version_to_str());
     else if (command == "git_version")
@@ -406,7 +409,7 @@ class HelpHook : public AdminSocketHook {
   AdminSocket *m_as;
 public:
   HelpHook(AdminSocket *as) : m_as(as) {}
-  bool call(string command, bufferlist& out) {
+  bool call(string command, string args, bufferlist& out) {
     unsigned max = 0;
     for (map<string,string>::iterator p = m_as->m_help.begin();
         p != m_as->m_help.end();
index 00828ad2df9267452bebc8b9e33f336c48b86679..6154f50cabe619c3505fcaf43f4bcbdf601c7276 100644 (file)
@@ -29,7 +29,7 @@ class CephContext;
 
 class AdminSocketHook {
 public:
-  virtual bool call(std::string command, bufferlist& out) = 0;
+  virtual bool call(std::string command, std::string args, bufferlist& out) = 0;
   virtual ~AdminSocketHook() {};
 };
 
index 7d2bea9ba445fdf0b6ad4f0cbb4ceb820d61da0d..1f0fcac8b838d10f1f7687fe72e51644df037f52 100644 (file)
@@ -153,15 +153,15 @@ class CephContextHook : public AdminSocketHook {
 public:
   CephContextHook(CephContext *cct) : m_cct(cct) {}
 
-  bool call(std::string command, bufferlist& out) {
-    m_cct->do_command(command, &out);
+  bool call(std::string command, std::string args, bufferlist& out) {
+    m_cct->do_command(command, args, &out);
     return true;
   }
 };
 
-void CephContext::do_command(std::string command, bufferlist *out)
+void CephContext::do_command(std::string command, std::string args, bufferlist *out)
 {
-  lgeneric_dout(this, 1) << "do_command '" << command << "'" << dendl;
+  lgeneric_dout(this, 1) << "do_command '" << command << "' '" << args << "'" << dendl;
   if (command == "perfcounters_dump" || command == "1" ||
       command == "perf dump") {
     std::vector<char> v;
@@ -179,8 +179,8 @@ void CephContext::do_command(std::string command, bufferlist *out)
     _conf->show_config(ss);
     out->append(ss.str());
   }
-  else if (command.find("config set ") == 0) {
-    std::string var = command.substr(11);
+  else if (command == "config set ") {
+    std::string var = args;
     size_t pos = var.find(' ');
     if (pos == string::npos) {
       out->append("set_config syntax is 'set_config <var> <value>'");
@@ -210,7 +210,7 @@ void CephContext::do_command(std::string command, bufferlist *out)
   else {
     assert(0 == "registered under wrong command?");    
   }
-  lgeneric_dout(this, 1) << "do_command '" << command << "' result is " << out->length() << " bytes" << dendl;
+  lgeneric_dout(this, 1) << "do_command '" << command << "' '" << args << "' result is " << out->length() << " bytes" << dendl;
 };
 
 
index fb5dc5bccdca252e20cdad1cc7fef7c369bf46ed..ba7f02d93cf8aee3f6149b453f3e62d678458c3c 100644 (file)
@@ -80,7 +80,7 @@ public:
   /**
    * process an admin socket command
    */
-  void do_command(std::string command, bufferlist *out);
+  void do_command(std::string command, std::string args, bufferlist *out);
 
 private:
   CephContext(const CephContext &rhs);
index 46f0126521d4251760d2d23a71a327f2da0a5bc2..a6dba5949268dccb85d5fca066019638bff2ba0f 100644 (file)
@@ -197,15 +197,15 @@ class AdminHook : public AdminSocketHook {
   Monitor *mon;
 public:
   AdminHook(Monitor *m) : mon(m) {}
-  bool call(std::string command, bufferlist& out) {
+  bool call(std::string command, std::string args, bufferlist& out) {
     stringstream ss;
-    mon->do_admin_command(command, ss);
+    mon->do_admin_command(command, args, ss);
     out.append(ss);
     return true;
   }
 };
 
-void Monitor::do_admin_command(string command, ostream& ss)
+void Monitor::do_admin_command(string command, string args, ostream& ss)
 {
   Mutex::Locker l(lock);
   if (command == "mon_status")
@@ -213,7 +213,7 @@ void Monitor::do_admin_command(string command, ostream& ss)
   else if (command == "quorum_status")
     _quorum_status(ss);
   else if (command.find("add_bootstrap_peer_hint") == 0)
-    _add_bootstrap_peer_hint(command, ss);
+    _add_bootstrap_peer_hint(command, args, ss);
   else
     assert(0 == "bad AdminSocket command binding");
 }
@@ -494,25 +494,24 @@ void Monitor::bootstrap()
   }
 }
 
-void Monitor::_add_bootstrap_peer_hint(string cmd, ostream& ss)
+void Monitor::_add_bootstrap_peer_hint(string cmd, string args, ostream& ss)
 {
-  dout(10) << "_add_bootstrap_peer_hint '" << cmd << "'" << dendl;
+  dout(10) << "_add_bootstrap_peer_hint '" << cmd << "' '" << args << "'" << dendl;
 
   if (is_leader() || is_peon()) {
     ss << "mon already active; ignoring bootstrap hint";
     return;
   }
 
-  size_t off = cmd.find(" ");
-  if (off == std::string::npos) {
+  if (args.length() == 0) {
     ss << "syntax is 'add_bootstrap_peer_hint ip[:port]'";
     return;
   }
 
   entity_addr_t addr;
   const char *end = 0;
-  if (!addr.parse(cmd.c_str() + off + 1, &end)) {
-    ss << "failed to parse addr '" << (cmd.c_str() + off + 1) << "'";
+  if (!addr.parse(args.c_str(), &end)) {
+    ss << "failed to parse addr '" << args << "'";
     return;
   }
 
index 381138a97a183937bca206e7abbc3bc2b5ed731a..6a6c748b7c718b8b36112aa1a2a48f8696791a14 100644 (file)
@@ -279,7 +279,7 @@ public:
   bool _allowed_command(MonSession *s, const vector<std::string>& cmd);
   void _mon_status(ostream& ss);
   void _quorum_status(ostream& ss);
-  void _add_bootstrap_peer_hint(string cmd, ostream& ss);
+  void _add_bootstrap_peer_hint(string cmd, string args, ostream& ss);
   void handle_command(class MMonCommand *m);
   void handle_route(MRoute *m);
 
@@ -398,7 +398,7 @@ public:
 
   int mkfs(bufferlist& osdmapbl);
 
-  void do_admin_command(std::string command, ostream& ss);
+  void do_admin_command(std::string command, std::string args, ostream& ss);
 
 private:
   // don't allow copying
index 794549c7ecc54d49f569a65a56290ee6cbf4b740..9feec158c6b05feac11fc8936bcc5ebba38ab0e3 100644 (file)
@@ -694,7 +694,7 @@ class OpsFlightSocketHook : public AdminSocketHook {
   OSD *osd;
 public:
   OpsFlightSocketHook(OSD *o) : osd(o) {}
-  bool call(std::string command, bufferlist& out) {
+  bool call(std::string command, std::string args, bufferlist& out) {
     stringstream ss;
     osd->dump_ops_in_flight(ss);
     out.append(ss);
index 047e1be0f4f4b694fad6b6e7d63d06309903e47b..eae34d3b062001664668257c5984215ec329fd5b 100644 (file)
@@ -2047,7 +2047,7 @@ Objecter::RequestStateHook::RequestStateHook(Objecter *objecter) :
 {
 }
 
-bool Objecter::RequestStateHook::call(std::string command, bufferlist& out)
+bool Objecter::RequestStateHook::call(std::string command, std::string args, bufferlist& out)
 {
   stringstream ss;
   JSONFormatter formatter(true);
index 558fc46c9cd0a6a03232de6e80426f7e8970288b..d0c69ee67b6ed349ebeba1f52f13964115c3b2a2 100644 (file)
@@ -547,7 +547,7 @@ class Objecter {
     Objecter *m_objecter;
   public:
     RequestStateHook(Objecter *objecter);
-    bool call(std::string command, bufferlist& out);
+    bool call(std::string command, std::string args, bufferlist& out);
   };
 
   RequestStateHook *m_request_state_hook;