diff options
author | Sage Weil <sage@newdream.net> | 2012-05-02 14:17:26 -0700 |
---|---|---|
committer | Sage Weil <sage@newdream.net> | 2012-05-02 14:55:54 -0700 |
commit | 79edba2f1ba9e3e4b67fc9f4704e54b93a377f9b (patch) | |
tree | 32f6d6a0ab60e1f8ba4eb2bf575c03a8dc646c38 | |
parent | ee00095abb2f55a211ccd278ae87f4ceb9900ed2 (diff) | |
download | ceph-79edba2f1ba9e3e4b67fc9f4704e54b93a377f9b.tar.gz |
mon: 'osd crush set ...' do an add or update
This operation will add/update/move the item to the specified location.
It is idempotent and much more useful than 'osd crush add ...'.
Signed-off-by: Sage Weil <sage@newdream.net>
-rw-r--r-- | src/mon/OSDMonitor.cc | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index d0d0a7f4a51..57a47b38f14 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -1783,6 +1783,52 @@ bool OSDMonitor::prepare_command(MMonCommand *m) } } while (false); } + else if (m->cmd.size() >= 6 && m->cmd[1] == "crush" && m->cmd[2] == "set") { + do { + // osd crush update <id> <name> <weight> [<loc1> [<loc2> ...]] + int id = atoi(m->cmd[3].c_str()); + string name = m->cmd[4]; + float weight = atof(m->cmd[5].c_str()); + map<string,string> 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/updating 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.update_item(g_ceph_context, id, weight, name, loc); + if (err == 0) { + ss << "updated item id " << id << " name '" << name << "' weight " << weight + << " at location " << loc << " to crush map"; + break; + } + if (err > 0) { + pending_inc.crush.clear(); + newcrush.encode(pending_inc.crush); + ss << "updated 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.size() > 3 && m->cmd[1] == "crush" && (m->cmd[2] == "rm" || m->cmd[2] == "remove")) { do { // osd crush rm <id> |