]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: 'osd {set,unset} {noin,noout,noup,nodown}'
authorSage Weil <sage.weil@dreamhost.com>
Tue, 24 Apr 2012 03:33:48 +0000 (20:33 -0700)
committerSage Weil <sage@newdream.net>
Tue, 24 Apr 2012 21:10:47 +0000 (14:10 -0700)
Move the set/unset flag code into a helper, and also use that for the
pause/unpause commands.

Signed-off-by: Sage Weil <sage.weil@dreamhost.com>
src/mon/Monitor.h
src/mon/OSDMonitor.cc
src/mon/OSDMonitor.h

index d16207b46d0c31963221629d40e47b4fcb512ed3..4497190dc04951798bab0a0d85aba8d15c548d09 100644 (file)
@@ -301,7 +301,7 @@ public:
     int rc;
     string rs;
     version_t version;
-    C_Command(Monitor *_mm, MMonCommand *_m, int r, string& s, version_t v) :
+    C_Command(Monitor *_mm, MMonCommand *_m, int r, string s, version_t v) :
       mon(_mm), m(_m), rc(r), rs(s), version(v){}
     void finish(int r) {
       mon->reply_command(m, rc, rs, version);
index 0cbdcf90580abe527c5837aa75370fa0f0797adf..f036bfaab33a226755c34faa2e1c20b6b3509aa0 100644 (file)
@@ -1502,6 +1502,28 @@ int OSDMonitor::prepare_new_pool(string& name, uint64_t auid, int crush_rule,
   return 0;
 }
 
+bool OSDMonitor::prepare_set_flag(MMonCommand *m, int flag)
+{
+  ostringstream ss;
+  if (pending_inc.new_flags < 0)
+    pending_inc.new_flags = osdmap.get_flags();
+  pending_inc.new_flags |= flag;
+  ss << "set " << OSDMap::get_flag_string(flag);
+  paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, ss.str(), paxos->get_version()));
+  return true;
+}
+
+bool OSDMonitor::prepare_unset_flag(MMonCommand *m, int flag)
+{
+  ostringstream ss;
+  if (pending_inc.new_flags < 0)
+    pending_inc.new_flags = osdmap.get_flags();
+  pending_inc.new_flags &= ~flag;
+  ss << "unset " << OSDMap::get_flag_string(flag);
+  paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, ss.str(), paxos->get_version()));
+  return true;
+}
+
 bool OSDMonitor::prepare_command(MMonCommand *m)
 {
   stringstream ss;
@@ -1666,22 +1688,34 @@ bool OSDMonitor::prepare_command(MMonCommand *m)
       return true;
     }
     else if (m->cmd[1] == "pause") {
-      if (pending_inc.new_flags < 0)
-       pending_inc.new_flags = osdmap.get_flags();
-      pending_inc.new_flags |= CEPH_OSDMAP_PAUSERD | CEPH_OSDMAP_PAUSEWR;
-      ss << "pause rd+wr";
-      getline(ss, rs);
-      paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs, paxos->get_version()));
-      return true;
+      return prepare_set_flag(m, CEPH_OSDMAP_PAUSERD | CEPH_OSDMAP_PAUSEWR);
     }
     else if (m->cmd[1] == "unpause") {
-      if (pending_inc.new_flags < 0)
-       pending_inc.new_flags = osdmap.get_flags();
-      pending_inc.new_flags &= ~(CEPH_OSDMAP_PAUSERD | CEPH_OSDMAP_PAUSEWR);
-      ss << "unpause rd+wr";
-      getline(ss, rs);
-      paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs, paxos->get_version()));
-      return true;
+      return prepare_unset_flag(m, CEPH_OSDMAP_PAUSERD | CEPH_OSDMAP_PAUSEWR);
+    }
+    else if (m->cmd.size() == 3 && m->cmd[1] == "set" && m->cmd[2] == "pause") {
+      return prepare_set_flag(m, CEPH_OSDMAP_PAUSERD | CEPH_OSDMAP_PAUSEWR);
+    }
+    else if (m->cmd.size() == 3 && m->cmd[1] == "unset" && m->cmd[2] == "pause") {
+      return prepare_unset_flag(m, CEPH_OSDMAP_PAUSERD | CEPH_OSDMAP_PAUSEWR);
+    }
+    else if (m->cmd.size() == 3 && m->cmd[1] == "set" && m->cmd[2] == "noup") {
+      return prepare_set_flag(m, CEPH_OSDMAP_NOUP);
+    }
+    else if (m->cmd.size() == 3 && m->cmd[1] == "unset" && m->cmd[2] == "noup") {
+      return prepare_unset_flag(m, CEPH_OSDMAP_NOUP);
+    }
+    else if (m->cmd.size() == 3 && m->cmd[1] == "set" && m->cmd[2] == "nodown") {
+      return prepare_set_flag(m, CEPH_OSDMAP_NODOWN);
+    }
+    else if (m->cmd.size() == 3 && m->cmd[1] == "unset" && m->cmd[2] == "nodown") {
+      return prepare_unset_flag(m, CEPH_OSDMAP_NODOWN);
+    }
+    else if (m->cmd.size() == 3 && m->cmd[1] == "set" && m->cmd[2] == "noout") {
+      return prepare_set_flag(m, CEPH_OSDMAP_NOOUT);
+    }
+    else if (m->cmd.size() == 3 && m->cmd[1] == "unset" && m->cmd[2] == "noout") {
+      return prepare_unset_flag(m, CEPH_OSDMAP_NOOUT);
     }
     else if (m->cmd[1] == "cluster_snap" && m->cmd.size() == 3) {
       pending_inc.cluster_snapshot = m->cmd[2];
index 0194e6eb1b6cd0fdbd6864c0976a905f5186ff13..4e3a3ac16727856f1a630528f4a81f1d0b401ae5 100644 (file)
@@ -104,6 +104,9 @@ private:
   int prepare_new_pool(string& name, uint64_t auid, int crush_rule,
                        unsigned pg_num, unsigned pgp_num);
   int prepare_new_pool(MPoolOp *m);
+  
+  bool prepare_set_flag(MMonCommand *m, int flag);
+  bool prepare_unset_flag(MMonCommand *m, int flag);
 
   void _pool_op_reply(MPoolOp *m, int ret, epoch_t epoch, bufferlist *blp=NULL);