]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: verify that crush max does not exceed osd max
authorSage Weil <sage.weil@dreamhost.com>
Mon, 23 May 2011 21:58:26 +0000 (14:58 -0700)
committerSage Weil <sage.weil@dreamhost.com>
Mon, 23 May 2011 21:58:26 +0000 (14:58 -0700)
- when injecting a new crushmap
- when adjusting osdmap max_osd

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

index 6b319073da0a9e6fb688451bad229ce668a3fc3c..651d93d6d1e2289c829288fa8a2159d96b51faab 100644 (file)
@@ -1376,9 +1376,9 @@ bool OSDMonitor::prepare_command(MMonCommand *m)
     if (m->cmd[1] == "setcrushmap") {
       dout(10) << "prepare_command setting new crush map" << dendl;
       bufferlist data(m->get_data());
+      CrushWrapper crush;
       try {
        bufferlist::iterator bl(data.begin());
-       CrushWrapper crush;
        crush.decode(bl);
       }
       catch (const std::exception &e) {
@@ -1386,6 +1386,14 @@ bool OSDMonitor::prepare_command(MMonCommand *m)
        ss << "Failed to parse crushmap: " << e.what();
        goto out;
       }
+
+      if (crush.get_max_devices() > osdmap.get_max_osd()) {
+       err = -ERANGE;
+       ss << "crushmap max_devices " << crush.get_max_devices()
+          << " > osdmap max_osd " << osdmap.get_max_osd();
+       goto out;
+      }
+
       pending_inc.crush = data;
       string rs = "set crush map";
       paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs, paxos->get_version()));
@@ -1410,7 +1418,15 @@ bool OSDMonitor::prepare_command(MMonCommand *m)
     }
     */
     else if (m->cmd[1] == "setmaxosd" && m->cmd.size() > 2) {
-      pending_inc.new_max_osd = atoi(m->cmd[2].c_str());
+      int newmax = atoi(m->cmd[2].c_str());
+      if (newmax < osdmap.crush.get_max_devices()) {
+       err = -ERANGE;
+       ss << "cannot set max_osd to " << newmax << " which is < crush max_devices "
+          << osdmap.crush.get_max_devices();
+       goto out;
+      }
+
+      pending_inc.new_max_osd = newmax;
       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, paxos->get_version()));