]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: osd commands to mark osds in/out/down
authorSage Weil <sage@newdream.net>
Sun, 2 Mar 2008 22:39:00 +0000 (14:39 -0800)
committerSage Weil <sage@newdream.net>
Sun, 2 Mar 2008 22:39:00 +0000 (14:39 -0800)
src/mon/MDSMonitor.cc
src/mon/Monitor.cc
src/mon/Monitor.h
src/mon/OSDMonitor.cc

index ee684eb3d41da1a03eb7fccdb498990de88baaf6..313ecb8fd6652ff6bfbfc02c971db2a9b80bb443 100644 (file)
@@ -487,9 +487,7 @@ bool MDSMonitor::preprocess_command(MMonCommand *m)
   if (r != -1) {
     string rs;
     getline(ss, rs);
-    MMonCommandAck *reply = new MMonCommandAck(r, rs);
-    reply->set_data(rdata);
-    mon->messenger->send_message(reply, m->inst);
+    mon->reply_command(m, r, rs, rdata);
     delete m;
     return true;
   } else
@@ -531,10 +529,7 @@ bool MDSMonitor::prepare_command(MMonCommand *m)
     return true;
   } else {
     // reply immediately
-    MMonCommandAck *reply = new MMonCommandAck(r, rs);
-    reply->set_data(rdata);
-    mon->messenger->send_message(reply, m->inst);
-    delete m;
+    mon->reply_command(m, r, rs, rdata);
     return false;
   }
 }
index 4d2bebcab17b3934b0db05aadba4311f0107f596..3dcec26e33e633fb10e393a1ff6ada65d1a3711a 100644 (file)
@@ -216,14 +216,20 @@ void Monitor::handle_command(MMonCommand *m)
     rs = "unrecognized subsystem";
   } else 
     rs = "no command";
-  MMonCommandAck *reply = new MMonCommandAck(-EINVAL, rs);
-  messenger->send_message(reply, m->inst);
-  delete m;
+
+  reply_command(m, -EINVAL, rs);
+}
+
+void Monitor::reply_command(MMonCommand *m, int rc, const string &rs)
+{
+  bufferlist rdata;
+  reply_command(m, rc, rs, rdata);
 }
 
-void Monitor::finish_command(MMonCommand *m, int rc, const string &rs)
+void Monitor::reply_command(MMonCommand *m, int rc, const string &rs, bufferlist& rdata)
 {
   MMonCommandAck *reply = new MMonCommandAck(rc, rs);
+  reply->set_data(rdata);
   messenger->send_message(reply, m->inst);
   delete m;
 }
index 3534ef7ef0ffadbb02d7ad7225a1303fbcb44d66..1292ce8db082fcb30e6a9f1c1c6358d5165fb55b 100644 (file)
@@ -119,7 +119,8 @@ public:
   void handle_ping_ack(class MPingAck *m);
   void handle_command(class MMonCommand *m);
 
-  void finish_command(MMonCommand *m, int rc, const string &rs);
+  void reply_command(MMonCommand *m, int rc, const string &rs);
+  void reply_command(MMonCommand *m, int rc, const string &rs, bufferlist& rdata);
 public:
   struct C_Command : public Context {
     Monitor *mon;
@@ -129,7 +130,7 @@ public:
     C_Command(Monitor *_mm, MMonCommand *_m, int r, string& s) :
       mon(_mm), m(_m), rc(r), rs(s) {}
     void finish(int r) {
-      mon->finish_command(m, rc, rs);
+      mon->reply_command(m, rc, rs);
     }
   };
 
index 3dad77d772b0db154ff50fc9eeaa4bcf57104efc..124f04182b15dbc93dcf225ec0eb9f6038ebecdc 100644 (file)
@@ -905,6 +905,8 @@ bool OSDMonitor::preprocess_command(MMonCommand *m)
 
 bool OSDMonitor::prepare_command(MMonCommand *m)
 {
+  stringstream ss;
+  string rs;
   if (m->cmd.size() > 1) {
     if (m->cmd[1] == "setcrushmap") {
       dout(10) << "prepare_command setting new crush map" << dendl;
@@ -913,13 +915,58 @@ bool OSDMonitor::prepare_command(MMonCommand *m)
       paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs));
       return true;
     }
-    if (m->cmd[1] == "setmaxosd" &&
-       m->cmd.size() > 2) {
+    else if (m->cmd[1] == "setmaxosd" && m->cmd.size() > 2) {
       pending_inc.new_max_osd = atoi(m->cmd[2].c_str());
-      string rs = "set new max_osd";
+      ss << "set new max_osd = " << pending_inc.new_max_osd;
+      getline(ss, rs);
       paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs));
       return true;
     }
+    else if (m->cmd[1] == "down" && m->cmd.size() > 2) {
+      errno = 0;
+      long osd = strtol(m->cmd[2].c_str(), 0, 10);
+      if (osdmap.is_up(osd)) {
+       pending_inc.new_down[osd] = false;
+       ss << "marked down osd" << osd;
+       getline(ss, rs);
+       paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs));
+       return true;
+      } else {
+       ss << "osd" << osd << " is already down";
+       getline(ss, rs);
+       mon->reply_command(m, -EINVAL, rs);
+      }
+    }
+    else if (m->cmd[1] == "out" && m->cmd.size() > 2) {
+      errno = 0;
+      long osd = strtol(m->cmd[2].c_str(), 0, 10);
+      if (osdmap.is_in(osd)) {
+       pending_inc.new_offload[osd] = CEPH_OSD_OUT;
+       ss << "marked out osd" << osd;
+       getline(ss, rs);
+       paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs));
+       return true;
+      } else {
+       ss << "osd" << osd << " is already out";
+       getline(ss, rs);
+       mon->reply_command(m, -EINVAL, rs);
+      }
+    }
+    else if (m->cmd[1] == "in" && m->cmd.size() > 2) {
+      errno = 0;
+      long osd = strtol(m->cmd[2].c_str(), 0, 10);
+      if (osdmap.is_out(osd)) {
+       pending_inc.new_offload[osd] = CEPH_OSD_IN;
+       ss << "marked in osd" << osd;
+       getline(ss, rs);
+       paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs));
+       return true;
+      } else {
+       ss << "osd" << osd << " is already in";
+       getline(ss, rs);
+       mon->reply_command(m, -EINVAL, rs);
+      }
+    }
   }
   return false;
 }