From db8ad462df47601b18d95a3d4dfbf041fc95f2ba Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 23 Aug 2011 12:31:35 -0700 Subject: [PATCH] mon: 'osd crush add [ [ ...]]' This is identical to the crushtool --add-item functionality, but does not require a racy and tedious - get crush map - update crush map - set new crush map Signed-off-by: Sage Weil --- src/mon/OSDMonitor.cc | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 68879c4e6e6eb..16cf78d7dbe2e 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -1409,6 +1409,53 @@ bool OSDMonitor::prepare_command(MMonCommand *m) paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs, paxos->get_version())); return true; } + else if (m->cmd[1] == "crush" && m->cmd[2] == "add" && m->cmd.size() >= 6) { + do { + // osd crush add [ [ ...]] + int id = atoi(m->cmd[3].c_str()); + string name = m->cmd[4]; + float weight = atof(m->cmd[5].c_str()); + map loc; + for (unsigned i = 6; i < m->cmd.size(); ++i) { + const char *s = m->cmd[i].c_str(); + const char *pos = strchr(s, '='); + if (!pos) + break; + string key(s, 0, pos-s); + string value(pos+1); + loc[key] = value; + } + + dout(0) << "adding crush item id " << id << " name '" << name << "' weight " << weight + << " at location " << loc << dendl; + bufferlist bl; + if (pending_inc.crush.length()) + bl = pending_inc.crush; + else + osdmap.crush.encode(bl); + + CrushWrapper newcrush; + bufferlist::iterator p = bl.begin(); + newcrush.decode(p); + + err = newcrush.insert_item(id, (int)(weight * (float)0x10000), name, loc); + if (err == 0) { + if (newcrush.get_max_devices() > osdmap.get_max_osd()) { + err = -ERANGE; + ss << "crushmap max_devices " << newcrush.get_max_devices() + << " > osdmap max_osd " << osdmap.get_max_osd(); + break; + } + pending_inc.crush.clear(); + newcrush.encode(pending_inc.crush); + ss << "added item id " << id << " name '" << name << "' weight " << weight + << " at location " << loc << " to crush map"; + getline(ss, rs); + paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs, paxos->get_version())); + return true; + } + } while (false); + } else if (m->cmd[1] == "setmaxosd" && m->cmd.size() > 2) { int newmax = atoi(m->cmd[2].c_str()); if (newmax < osdmap.crush.get_max_devices()) { -- 2.39.5