]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Make a more flexible 'tell' command to replace injectargs
authorGreg Farnum <gregf@hq.newdream.net>
Tue, 15 Dec 2009 23:50:00 +0000 (15:50 -0800)
committerGreg Farnum <gregf@hq.newdream.net>
Wed, 16 Dec 2009 00:17:29 +0000 (16:17 -0800)
osd/mds: make a handle_command function; don't parse all MMonCommands as config

mon: Send injectargs to osd/mds in new format;
accept tells for mds and osd

src/mds/MDS.cc
src/mds/MDS.h
src/mon/MDSMonitor.cc
src/mon/Monitor.cc
src/mon/Monitor.h
src/mon/OSDMonitor.cc
src/osd/OSD.cc
src/osd/OSD.h

index ebc39a4c5c15dd84d754e548905aac2751661d09..78ba9eb8ae1fc545f01f396d6165b72f0e9fd2be 100644 (file)
@@ -569,6 +569,15 @@ void MDS::beacon_kill(utime_t lab)
 }
 
 
+void MDS::handle_command(MMonCommand *m)
+{
+  dout(20) << "handle_command args: " << m->cmd << dendl;
+  if (m->cmd[0] == "injectargs")
+    parse_config_option_string(m->cmd[1]);
+  else 
+    dout(0) << "unrecognized command! " << m->cmd << dendl;
+  delete m;
+}
 
 void MDS::handle_mds_map(MMDSMap *m)
 {
@@ -1239,8 +1248,7 @@ do { \
     // misc
   case MSG_MON_COMMAND:
     ALLOW_MESSAGES_FROM(CEPH_ENTITY_TYPE_MON);
-    parse_config_option_string(((MMonCommand*)m)->cmd[0]);
-    delete m;
+    handle_command((MMonCommand*)m);
     break;    
     
   default:
index 5c296417162c3c2816524f929c30974d25f37773..cf77a34fde26c1797b7138cdd08ae01d0c9b82e9 100644 (file)
@@ -375,6 +375,7 @@ class MDS : public Dispatcher {
   void ms_handle_remote_reset(Connection *con);
 
   // special message types
+  void handle_command(class MMonCommand *m);
   void handle_mds_map(class MMDSMap *m);
 };
 
index 43763a5a6e8d9615e61a27412ce0b1f56795ebc9..248ca5d2208c02f42e3027dd01e5e43ea6fa94f6 100644 (file)
@@ -449,6 +449,31 @@ bool MDSMonitor::preprocess_command(MMonCommand *m)
          ss << "specify mds number or *";
       }
     }
+    else if (m->cmd[1] == "tell") {
+      m->cmd.erase(m->cmd.begin()); //take out first two args; don't need them
+      m->cmd.erase(m->cmd.begin());
+      if (m->cmd[0] == "*") {
+       m->cmd.erase(m->cmd.begin()); //and now we're done with the target num
+       for (unsigned i = 0; i < mdsmap.get_max_mds(); ++i) {
+         if (mdsmap.is_active(i))
+           mon->send_command(mdsmap.get_inst(i), m->cmd, paxos->get_version());
+       }
+      } else {
+       errno = 0;
+       int who = strtol(m->cmd[0].c_str(), 0, 10);
+       m->cmd.erase(m->cmd.begin()); //done with target num now
+       if (!errno && who >= 0) {
+         if (mdsmap.is_up(who)) {
+           mon->send_command(mdsmap.get_inst(who), m->cmd, paxos->get_version());
+           r = 0;
+           ss << "ok";
+         } else {
+           ss << "mds" << who << " no up";
+           r = -ENOENT;
+         }
+       } else ss << "specify mds number or *";
+      }
+    }
   }
 
   if (r != -1) {
index caac0fc49f2dc6a1f176119625ec58e927859b54..5ac53ccd26a89b9e657a4ab19674e6d046483315 100644 (file)
@@ -454,14 +454,21 @@ void Monitor::handle_observe(MMonObserve *m)
 void Monitor::inject_args(const entity_inst_t& inst, vector<string>& args, version_t version)
 {
   dout(10) << "inject_args " << inst << " " << args << dendl;
+  vector<string> new_args = args;
+  new_args.insert(new_args.begin(), "injectargs");
+  send_command(inst, new_args, version);
+}
+
+void Monitor::send_command(const entity_inst_t& inst,
+                          const vector<string>& com, version_t version)
+{
+  dout(10) << "send_command " << inst << "" << com << dendl;
   MMonCommand *c = new MMonCommand(monmap->fsid, version);
-  c->cmd = args;
+  c->cmd = com;
   try_send_message(c, inst);
 }
 
 
-
-
 void Monitor::stop_cluster()
 {
   dout(0) << "stop_cluster -- initiating shutdown" << dendl;
index 073aa0de13e278ca401d1951cb2e215a7d48dd59..6f161caed1b4abef1735801eb3fc63e9abf562d1 100644 (file)
@@ -185,6 +185,8 @@ public:
     inject_args(inst, a, version);
   }
   void inject_args(const entity_inst_t& inst, vector<string>& args, version_t version);  
+void send_command(const entity_inst_t& inst,
+                          const vector<string>& com, version_t version);
 
 public:
   struct C_Command : public Context {
index af6c3378f097ffe468e2708195c7c5811555cf33..92cb41df23fb2638fe745e871f46012d72b29de3 100644 (file)
@@ -937,6 +937,30 @@ bool OSDMonitor::preprocess_command(MMonCommand *m)
          ss << "specify osd number or *";
       }
     }
+    else if (m->cmd[1] == "tell") {
+      m->cmd.erase(m->cmd.begin()); //take out first two args; don't need them
+      m->cmd.erase(m->cmd.begin());
+      if (m->cmd[0] == "*") {
+       m->cmd.erase(m->cmd.begin()); //and now we're done with the target num
+       for (int i = 0; i < osdmap.get_max_osd(); ++i) {
+         mon->send_command(osdmap.get_inst(i), m->cmd, paxos->get_version());
+       }
+      } else {
+       errno = 0;
+       int who = strtol(m->cmd[0].c_str(), 0, 10);
+       m->cmd.erase(m->cmd.begin()); //done with target num now
+       if (!errno && who >= 0) {
+         if (osdmap.is_up(who)) {
+           mon->send_command(osdmap.get_inst(who), m->cmd, paxos->get_version());
+           r = 0;
+           ss << "ok";
+         } else {
+           ss << "osd" << who << " no up";
+           r = -ENOENT;
+         }
+       } else ss << "specify osd number or *";
+      }
+    }
     else if ((m->cmd[1] == "scrub" || m->cmd[1] == "repair") && m->cmd.size() > 2) {
       if (m->cmd[2] == "*") {
        ss << "osds ";
index c7d256087c71dd5dca22b750359032ea6e87728a..c28c63804bfd379cfb1870c8cb035e89b1b97352 100644 (file)
@@ -1415,6 +1415,16 @@ void OSD::handle_pg_stats_ack(MPGStatsAck *ack)
   delete ack;
 }
 
+void OSD::handle_command(MMonCommand *m)
+{
+  dout(20) << "handle_command args: " << m->cmd << dendl;
+  if (m->cmd[0] == "injectargs")
+    parse_config_option_string(m->cmd[1]);
+  else 
+    dout(0) << "unrecognized command! " << m->cmd << dendl;
+  delete m;
+}
+
 
 
 
@@ -1657,8 +1667,7 @@ do { \
 
   case MSG_MON_COMMAND:
     ALLOW_MESSAGES_FROM(CEPH_ENTITY_TYPE_MON);
-    parse_config_option_string(((MMonCommand*)m)->cmd[0]);
-    delete m;
+    handle_command((MMonCommand*) m);
     break;
 
   case MSG_OSD_SCRUB:
index 9b1ab2041f39df36db7afc322b1f9b5e57ff0070..93a9942ec4a46a57162189b9d0cd36c186176dbd 100644 (file)
@@ -537,6 +537,8 @@ protected:
   void send_pg_stats();
   void handle_pg_stats_ack(class MPGStatsAck *ack);
 
+  void handle_command(class MMonCommand *m);
+
   void pg_stat_queue_enqueue(PG *pg) {
     pg_stat_queue_lock.Lock();
     if (pg->is_primary() && !pg->stat_queue_item.is_on_xlist()) {