From 0e6de71580fa583c19af85464535ee1ec9d69973 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 30 Jun 2011 23:17:39 -0700 Subject: [PATCH] mon: add 'osd create [id]' command If the id is specified, mark a non-existant osd rank as existant. The id must fall within the current [0,max) range. This is the counterpart of 'osd rm '. If the id is not specified, allocate an unused osd id and set the EXISTS flag. Increase max_osd as needed. Closes: #1244 Signed-off-by: Sage Weil --- src/mon/OSDMonitor.cc | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index d62377139e996..60377fcd4efd0 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -1561,6 +1561,48 @@ bool OSDMonitor::prepare_command(MMonCommand *m) return true; } } + else if (m->cmd[1] == "create") { + int i; + if (m->cmd.size() > 2) { + i = atoi(m->cmd[2].c_str()); + if (i < 0 || i >= osdmap.get_max_osd()) { + ss << i << " is not a valid osd id"; + getline(ss, rs); + return -ERANGE; + } + if (osdmap.exists(i) || + pending_inc.new_up_client.count(i) || + (pending_inc.new_state.count(i) && + (pending_inc.new_state[i] & CEPH_OSD_EXISTS))) { + ss << i << " already exists"; + getline(ss, rs); + return -EEXIST; + } + } else { + // allocate a new id + for (i=0; i < osdmap.get_max_osd(); i++) { + if (!osdmap.exists(i) && + pending_inc.new_up_client.count(i) == 0 && + (pending_inc.new_state.count(i) == 0 || + (pending_inc.new_state[i] & CEPH_OSD_EXISTS) == 0)) + goto done; + } + // hrm. raise max_osd + if (pending_inc.new_max_osd < 0) + pending_inc.new_max_osd = osdmap.get_max_osd() + 1; + else + pending_inc.new_max_osd++; + i = pending_inc.new_max_osd - 1; + } + + done: + dout(10) << " creating osd" << i << dendl; + pending_inc.new_state[i] |= CEPH_OSD_EXISTS; + ss << i; + getline(ss, rs); + paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs, paxos->get_version())); + return true; + } else if (m->cmd[1] == "rm" && m->cmd.size() >= 3) { bool any = false; for (unsigned j = 2; j < m->cmd.size(); j++) { -- 2.39.5