From: Sage Weil Date: Mon, 23 May 2011 21:58:26 +0000 (-0700) Subject: mon: verify that crush max does not exceed osd max X-Git-Tag: v0.29~42^2~7 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6360154d7945353ad3281289a7b4205115de72f7;p=ceph.git mon: verify that crush max does not exceed osd max - when injecting a new crushmap - when adjusting osdmap max_osd Signed-off-by: Sage Weil --- diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 6b319073da0a9..651d93d6d1e22 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -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()));