if (r != -1) {
string rs;
getline(ss, rs);
- MMonCommandAck *reply = new MMonCommandAck(r, rs);
- reply->set_data(rdata);
- mon->messenger->send_message(reply, m->inst);
+ mon->reply_command(m, r, rs, rdata);
delete m;
return true;
} else
return true;
} else {
// reply immediately
- MMonCommandAck *reply = new MMonCommandAck(r, rs);
- reply->set_data(rdata);
- mon->messenger->send_message(reply, m->inst);
- delete m;
+ mon->reply_command(m, r, rs, rdata);
return false;
}
}
rs = "unrecognized subsystem";
} else
rs = "no command";
- MMonCommandAck *reply = new MMonCommandAck(-EINVAL, rs);
- messenger->send_message(reply, m->inst);
- delete m;
+
+ reply_command(m, -EINVAL, rs);
+}
+
+void Monitor::reply_command(MMonCommand *m, int rc, const string &rs)
+{
+ bufferlist rdata;
+ reply_command(m, rc, rs, rdata);
}
-void Monitor::finish_command(MMonCommand *m, int rc, const string &rs)
+void Monitor::reply_command(MMonCommand *m, int rc, const string &rs, bufferlist& rdata)
{
MMonCommandAck *reply = new MMonCommandAck(rc, rs);
+ reply->set_data(rdata);
messenger->send_message(reply, m->inst);
delete m;
}
void handle_ping_ack(class MPingAck *m);
void handle_command(class MMonCommand *m);
- void finish_command(MMonCommand *m, int rc, const string &rs);
+ void reply_command(MMonCommand *m, int rc, const string &rs);
+ void reply_command(MMonCommand *m, int rc, const string &rs, bufferlist& rdata);
public:
struct C_Command : public Context {
Monitor *mon;
C_Command(Monitor *_mm, MMonCommand *_m, int r, string& s) :
mon(_mm), m(_m), rc(r), rs(s) {}
void finish(int r) {
- mon->finish_command(m, rc, rs);
+ mon->reply_command(m, rc, rs);
}
};
bool OSDMonitor::prepare_command(MMonCommand *m)
{
+ stringstream ss;
+ string rs;
if (m->cmd.size() > 1) {
if (m->cmd[1] == "setcrushmap") {
dout(10) << "prepare_command setting new crush map" << dendl;
paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs));
return true;
}
- if (m->cmd[1] == "setmaxosd" &&
- m->cmd.size() > 2) {
+ else if (m->cmd[1] == "setmaxosd" && m->cmd.size() > 2) {
pending_inc.new_max_osd = atoi(m->cmd[2].c_str());
- string rs = "set new max_osd";
+ ss << "set new max_osd = " << pending_inc.new_max_osd;
+ getline(ss, rs);
paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs));
return true;
}
+ else if (m->cmd[1] == "down" && m->cmd.size() > 2) {
+ errno = 0;
+ long osd = strtol(m->cmd[2].c_str(), 0, 10);
+ if (osdmap.is_up(osd)) {
+ pending_inc.new_down[osd] = false;
+ ss << "marked down osd" << osd;
+ getline(ss, rs);
+ paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs));
+ return true;
+ } else {
+ ss << "osd" << osd << " is already down";
+ getline(ss, rs);
+ mon->reply_command(m, -EINVAL, rs);
+ }
+ }
+ else if (m->cmd[1] == "out" && m->cmd.size() > 2) {
+ errno = 0;
+ long osd = strtol(m->cmd[2].c_str(), 0, 10);
+ if (osdmap.is_in(osd)) {
+ pending_inc.new_offload[osd] = CEPH_OSD_OUT;
+ ss << "marked out osd" << osd;
+ getline(ss, rs);
+ paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs));
+ return true;
+ } else {
+ ss << "osd" << osd << " is already out";
+ getline(ss, rs);
+ mon->reply_command(m, -EINVAL, rs);
+ }
+ }
+ else if (m->cmd[1] == "in" && m->cmd.size() > 2) {
+ errno = 0;
+ long osd = strtol(m->cmd[2].c_str(), 0, 10);
+ if (osdmap.is_out(osd)) {
+ pending_inc.new_offload[osd] = CEPH_OSD_IN;
+ ss << "marked in osd" << osd;
+ getline(ss, rs);
+ paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs));
+ return true;
+ } else {
+ ss << "osd" << osd << " is already in";
+ getline(ss, rs);
+ mon->reply_command(m, -EINVAL, rs);
+ }
+ }
}
return false;
}