]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: allow new arguments to be sent to running mon, mds, osd via cmonctl
authorSage Weil <sage@newdream.net>
Thu, 2 Oct 2008 18:15:08 +0000 (11:15 -0700)
committerSage Weil <sage@newdream.net>
Thu, 2 Oct 2008 18:15:27 +0000 (11:15 -0700)
src/config.cc
src/config.h
src/mds/MDS.cc
src/mon/MDSMonitor.cc
src/mon/Monitor.cc
src/mon/Monitor.h
src/mon/OSDMonitor.cc
src/osd/OSD.cc

index d342e5fc5a96d150c987843751b0e89a448ab1ee..2b5bf745df9cf5781423ad4394f5e607d62fa3a8 100644 (file)
@@ -572,7 +572,24 @@ bool parse_ip_port(const char *s, entity_addr_t& a)
 
 
 
-void parse_config_options(std::vector<const char*>& args)
+void parse_config_option_string(string& s)
+{
+  char b[s.length()+1];
+  strcpy(b, s.c_str());
+  vector<const char*> nargs;
+  char *p = b;
+  while (*p) {
+    nargs.push_back(p);
+    while (*p && *p != ' ') p++;
+    if (!*p)
+      break;
+    *p++ = 0;
+    while (*p && *p == ' ') p++;
+  }
+  parse_config_options(nargs, false);
+}
+
+void parse_config_options(std::vector<const char*>& args, bool open)
 {
   std::vector<const char*> nargs;
 
@@ -1129,7 +1146,7 @@ void parse_config_options(std::vector<const char*>& args)
       g_conf.dout_dir = 0;
   }
   */
-  if (g_conf.dout_dir && g_conf.daemonize) {
+  if (g_conf.dout_dir && g_conf.daemonize && open) {
     char fn[80];
     char hostname[80];
     gethostname(hostname, 79);
index 44faf4362581b578d972c69fcb12298eae21bc74..49e27a9ea3483eee2ba061c5004a28f391455a38 100644 (file)
@@ -350,7 +350,8 @@ void argv_to_vec(int argc, const char **argv,
 void vec_to_argv(std::vector<const char*>& args,
                  int& argc, const char **&argv);
 
-void parse_config_options(std::vector<const char*>& args);
+void parse_config_options(std::vector<const char*>& args, bool open=true);
+void parse_config_option_string(string& s);
 
 extern bool parse_ip_port(const char *s, entity_addr_t& addr);
 
index 1413ef59f1f8e433b52ab0d65cd136ae6f84c0df..5389ba97ce5c3191e63a7df566d2454afbd333fa 100644 (file)
@@ -60,6 +60,8 @@
 
 #include "messages/MMDSTableRequest.h"
 
+#include "messages/MMonCommand.h"
+
 #include "config.h"
 
 #define  dout(l)    if (l<=g_conf.debug || l <= g_conf.debug_mds) *_dout << dbeginl << g_clock.now() << " mds" << whoami << " "
@@ -1174,6 +1176,12 @@ void MDS::_dispatch(Message *m)
       handle_mds_beacon((MMDSBeacon*)m);
       break;
       
+      // misc
+    case MSG_MON_COMMAND:
+      parse_config_option_string(((MMonCommand*)m)->cmd[0]);
+      delete m;
+      break;    
+
     default:
       dout(1) << "MDS unknown messge " << m->get_type() << dendl;
       assert(0);
index 5a668a12a93ca93e879d2bec85f9a566b7f9e62c..0132642f46d624064404d6d3d95a16300071f181 100644 (file)
@@ -523,6 +523,24 @@ bool MDSMonitor::preprocess_command(MMonCommand *m)
       ss << "got mdsmap epoch " << mdsmap.get_epoch();
       r = 0;
     }
+    else if (m->cmd[1] == "injectargs" && m->cmd.size() == 4) {
+      if (m->cmd[2] == "*") {
+       for (int i=0; i<mdsmap.get_max_mds(); i++)
+         if (mdsmap.is_active(i))
+           mon->inject_args(mdsmap.get_inst(i), m->cmd[3]);
+       r = 0;
+       ss << "ok bcast";
+      } else {
+       errno = 0;
+       int who = strtol(m->cmd[2].c_str(), 0, 10);
+       if (!errno && who >= 0 && mdsmap.is_active(who)) {
+         mon->inject_args(mdsmap.get_inst(who), m->cmd[3]);
+         r = 0;
+         ss << "ok";
+       } else 
+         ss << "specify mds number or *";
+      }
+    }
   }
 
   if (r != -1) {
index 2ddb9e1d3c2fb36e0aa08790023dc215e0c45b56..de08031c5ee8b16d2487098d93c3c7d05f813916 100644 (file)
@@ -210,6 +210,7 @@ void Monitor::handle_command(MMonCommand *m)
 
   dout(0) << "handle_command " << *m << dendl;
   string rs;
+  int r = -EINVAL;
   if (!m->cmd.empty()) {
     if (m->cmd[0] == "mds") {
       mdsmon->dispatch(m);
@@ -233,11 +234,39 @@ void Monitor::handle_command(MMonCommand *m)
       reply_command(m, 0, "initiating cluster shutdown");
       return;
     }
-    rs = "unrecognized subsystem";
+
+    if (m->cmd[0] == "_injectargs") {
+      parse_config_option_string(m->cmd[0]);
+      return;
+    } 
+    if (m->cmd[0] == "mon") {
+      if (m->cmd[1] == "injectargs" && m->cmd.size() == 4) {
+       vector<string> args(2);
+       args[0] = "_injectargs";
+       args[1] = m->cmd[3];
+       if (m->cmd[2] == "*") {
+         for (unsigned i=0; i<monmap->size(); i++)
+           inject_args(monmap->get_inst(i), args);
+         r = 0;
+         rs = "ok bcast";
+       } else {
+         errno = 0;
+         int who = strtol(m->cmd[2].c_str(), 0, 10);
+         if (!errno && who >= 0) {
+           inject_args(monmap->get_inst(who), args);
+           r = 0;
+           rs = "ok";
+         } else 
+           rs = "specify mon number or *";
+       }
+      } else
+       rs = "unrecognized mon command";
+    } else 
+      rs = "unrecognized subsystem";
   } else 
     rs = "no command";
 
-  reply_command(m, -EINVAL, rs);
+  reply_command(m, r, rs);
 }
 
 void Monitor::reply_command(MMonCommand *m, int rc, const string &rs)
@@ -254,6 +283,18 @@ void Monitor::reply_command(MMonCommand *m, int rc, const string &rs, bufferlist
   delete m;
 }
 
+
+void Monitor::inject_args(const entity_inst_t& inst, vector<string>& args)
+{
+  dout(10) << "inject_args " << inst << " " << args << dendl;
+  MMonCommand *c = new MMonCommand(monmap->fsid);
+  c->cmd = args;
+  messenger->send_message(c, inst);
+}
+
+
+
+
 void Monitor::stop_cluster()
 {
   dout(0) << "stop_cluster -- initiating shutdown" << dendl;
@@ -507,3 +548,4 @@ int Monitor::mkfs()
 }
 
 
+
index 434b12fa9a98cc7c4e1577fcd976e8c46121bce7..81b3742866142915d5820c79173734456df3953b 100644 (file)
@@ -127,6 +127,14 @@ public:
 
   void reply_command(MMonCommand *m, int rc, const string &rs);
   void reply_command(MMonCommand *m, int rc, const string &rs, bufferlist& rdata);
+
+  void inject_args(const entity_inst_t& inst, string& args) {
+    vector<string> a(1);
+    a[0] = args;
+    inject_args(inst, a);
+  }
+  void inject_args(const entity_inst_t& inst, vector<string>& args);  
+
 public:
   struct C_Command : public Context {
     Monitor *mon;
index 05ed17755f07115424a616b1095a7cb7748ba6da..a1a662c407b4beedc063346a1f10a5eaa2c68cc6 100644 (file)
@@ -868,6 +868,24 @@ bool OSDMonitor::preprocess_command(MMonCommand *m)
       ss << "max_osd = " << osdmap.get_max_osd() << " in epoch " << osdmap.get_epoch();
       r = 0;
     }
+    else if (m->cmd[1] == "injectargs" && m->cmd.size() == 4) {
+      if (m->cmd[2] == "*") {
+       for (int i=0; i<osdmap.get_max_osd(); i++)
+         if (osdmap.is_up(i))
+           mon->inject_args(osdmap.get_inst(i), m->cmd[3]);
+       r = 0;
+       ss << "ok bcast";
+      } else {
+       errno = 0;
+       int who = strtol(m->cmd[2].c_str(), 0, 10);
+       if (!errno && who >= 0 && osdmap.is_up(who)) {
+         mon->inject_args(osdmap.get_inst(who), m->cmd[3]);
+         r = 0;
+         ss << "ok";
+       } else 
+         ss << "specify osd number or *";
+      }
+    }
   }
   if (r != -1) {
     string rs;
index fde1da3e5cc114ae3bf24ace3956ac56f3504431..5732da9c796c3259f2f1a5233e9b088e5586decc 100644 (file)
@@ -59,6 +59,8 @@
 
 #include "messages/MOSDAlive.h"
 
+#include "messages/MMonCommand.h"
+
 #include "messages/MPGStats.h"
 #include "messages/MPGStatsAck.h"
 
@@ -1290,7 +1292,11 @@ void OSD::dispatch(Message *m)
   case MSG_PGSTATSACK:
     handle_pgstats_ack((MPGStatsAck*)m);
     break;
-    
+
+  case MSG_MON_COMMAND:
+    parse_config_option_string(((MMonCommand*)m)->cmd[0]);
+    delete m;
+    break;    
     
 
     // -- need OSDMap --