MCPcopy Create free account
hub / github.com/ceph/ceph / prepare_command

Method prepare_command

src/mon/MgrMonitor.cc:1168–1423  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1166}
1167
1168bool MgrMonitor::prepare_command(MonOpRequestRef op)
1169{
1170 auto m = op->get_req<MMonCommand>();
1171
1172 std::stringstream ss;
1173 bufferlist rdata;
1174
1175 cmdmap_t cmdmap;
1176 if (!cmdmap_from_json(m->cmd, &cmdmap, ss)) {
1177 string rs = ss.str();
1178 mon.reply_command(op, -EINVAL, rs, rdata, get_last_committed());
1179 return true;
1180 }
1181
1182 MonSession *session = op->get_session();
1183 if (!session) {
1184 mon.reply_command(op, -EACCES, "access denied", rdata, get_last_committed());
1185 return true;
1186 }
1187
1188 string format = cmd_getval_or<string>(cmdmap, "format", "plain");
1189 boost::scoped_ptr<Formatter> f(Formatter::create(format));
1190
1191 const auto prefix = cmd_getval_or<string>(cmdmap, "prefix", string{});
1192 int r = 0;
1193 bool plugged = false;
1194
1195 if (prefix == "mgr set") {
1196 std::string var;
1197 if (!cmd_getval(cmdmap, "var", var) || var.empty()) {
1198 ss << "Invalid variable";
1199 return -EINVAL;
1200 }
1201 string val;
1202 if (!cmd_getval(cmdmap, "val", val)) {
1203 return -EINVAL;
1204 }
1205
1206 if (var == "down") {
1207 bool enable_down = false;
1208 int r = parse_bool(val, &enable_down, ss);
1209 if (r != 0) {
1210 return r;
1211 }
1212 if (enable_down) {
1213 bool has_active = !!pending_map.active_gid;
1214 if (has_active && !mon.osdmon()->is_writeable()) {
1215 mon.osdmon()->wait_for_writeable(op, new C_RetryMessage(this, op));
1216 return false;
1217 }
1218 pending_map.flags |= MgrMap::FLAG_DOWN;
1219 if (has_active) {
1220 plugged |= drop_active();
1221 }
1222 } else {
1223 pending_map.flags &= ~(MgrMap::FLAG_DOWN);
1224 if (pending_map.active_gid == 0) {
1225 promote_standby();

Callers

nothing calls this directly

Calls 15

cmdmap_from_jsonFunction · 0.85
parse_boolFunction · 0.85
strict_strtolFunction · 0.85
reply_commandMethod · 0.80
osdmonMethod · 0.80
get_always_on_modulesMethod · 0.80
all_support_moduleMethod · 0.80
can_run_moduleMethod · 0.80
module_enabledMethod · 0.80
unplugMethod · 0.80
cmd_getvalFunction · 0.70

Tested by

no test coverage detected