| 1166 | } |
| 1167 | |
| 1168 | bool 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(); |
nothing calls this directly
no test coverage detected