Skip to content

Commit

Permalink
mon: simplify 'osd create <uuid>' command
Browse files Browse the repository at this point in the history
Make the flow clearer for the three cases (exists, about to exist, new).

Signed-off-by: Sage Weil <[email protected]>
  • Loading branch information
liewegas authored and Sage Weil committed May 4, 2012
1 parent 5125daa commit 16461ac
Showing 1 changed file with 27 additions and 28 deletions.
55 changes: 27 additions & 28 deletions src/mon/OSDMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2009,44 +2009,43 @@ bool OSDMonitor::prepare_command(MMonCommand *m)
}
else if (m->cmd[1] == "create") {
int i = -1;

// optional uuid provided?
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
if (m->cmd.size() > 2 && uuid.parse(m->cmd[2].c_str())) {
dout(10) << " osd create got uuid " << uuid << dendl;
i = osdmap.identify_osd(uuid);
if (i < 0) {
i = pending_inc.identify_osd(uuid);
if (i >= 0) {
paxos->wait_for_commit(new C_RetryMessage(this, m));
return true;
}
}
if (i >= 0) {
// osd already exists
err = 0;
ss << i;
getline(ss, rs);
paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs, paxos->get_version()));
goto out;
}
i = pending_inc.identify_osd(uuid);
if (i >= 0) {
// osd is about to exist
paxos->wait_for_commit(new C_RetryMessage(this, m));
return true;
}
// 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) &&
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;

// 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;
}

// 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 | CEPH_OSD_NEW;
Expand Down

0 comments on commit 16461ac

Please sign in to comment.