diff options
author | Sage Weil <sage@newdream.net> | 2012-05-01 16:14:20 -0700 |
---|---|---|
committer | Sage Weil <sage@newdream.net> | 2012-05-01 16:14:20 -0700 |
commit | 779914ba5c4c306a3359a8b0fcf8959a00de9fa2 (patch) | |
tree | d08fba382142f10a82a9c5a17c8c107c3b4481bf | |
parent | 78b9ccd371d568b87ade56d8d7c311d7f61c0c5a (diff) | |
download | ceph-779914ba5c4c306a3359a8b0fcf8959a00de9fa2.tar.gz |
mon: 'osd create <uuid>'
Make the osd create command idempotent by providing a uuid. If you call it
multiple times with the same (or some other existing) uuid you'll get back
the osd id that is already using it.
Drop support for 'osd create <id>', which was mostly useless and
non-idempotent anyway.
Signed-off-by: Sage Weil <sage@newdream.net>
-rw-r--r-- | src/mon/OSDMonitor.cc | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 9558c818194..d0d0a7f4a51 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -2008,32 +2008,29 @@ bool OSDMonitor::prepare_command(MMonCommand *m) } } else if (m->cmd[1] == "create") { - int i; - if (m->cmd.size() > 2) { - i = atoi(m->cmd[2].c_str()); + int i = -1; + uuid_d uuid; + if (m->cmd.size() > 2 && + uuid.parse(m->cmd[2].c_str())) { + dout(10) << "got uuid " << uuid << dendl; + // see if osd already exists + i = osdmap.identify_osd(uuid); if (i < 0) { - ss << i << " is not a valid osd id"; - err = -ERANGE; - goto out; - } - if (osdmap.exists(i)) { - ss << i << " already exists"; - err = -EEXIST; - goto out; - } - if (i >= osdmap.get_max_osd()) { - if (i >= pending_inc.new_max_osd) - pending_inc.new_max_osd = i + 1; + i = pending_inc.identify_osd(uuid); + if (i >= 0) { + paxos->wait_for_commit(new C_RetryMessage(this, m)); + return true; + } } - if (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"; + if (i >= 0) { + ss << i; getline(ss, rs); - paxos->wait_for_commit(new Monitor::C_Command(mon, m, -EEXIST, rs, paxos->get_version())); + paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs, paxos->get_version())); return true; } - } else { + // fall-thru to create one below. + } + if (i < 0) { // allocate a new id for (i=0; i < osdmap.get_max_osd(); i++) { if (!osdmap.exists(i) && |