| 1002 | } |
| 1003 | |
| 1004 | bool MDSMonitor::preprocess_command(MonOpRequestRef op) |
| 1005 | { |
| 1006 | op->mark_mdsmon_event(__func__); |
| 1007 | auto m = op->get_req<MMonCommand>(); |
| 1008 | int r = -1; |
| 1009 | bufferlist rdata; |
| 1010 | stringstream ss, ds; |
| 1011 | |
| 1012 | cmdmap_t cmdmap; |
| 1013 | if (!cmdmap_from_json(m->cmd, &cmdmap, ss)) { |
| 1014 | // ss has reason for failure |
| 1015 | string rs = ss.str(); |
| 1016 | mon.reply_command(op, -EINVAL, rs, rdata, get_last_committed()); |
| 1017 | return true; |
| 1018 | } |
| 1019 | |
| 1020 | string prefix; |
| 1021 | cmd_getval(cmdmap, "prefix", prefix); |
| 1022 | string format = cmd_getval_or<string>(cmdmap, "format", "plain"); |
| 1023 | std::unique_ptr<Formatter> f(Formatter::create(format)); |
| 1024 | |
| 1025 | MonSession *session = op->get_session(); |
| 1026 | if (!session) { |
| 1027 | mon.reply_command(op, -EACCES, "access denied", rdata, get_last_committed()); |
| 1028 | return true; |
| 1029 | } |
| 1030 | |
| 1031 | // to use const qualifier filter fsmap beforehand |
| 1032 | FSMap _fsmap_copy = get_fsmap(); |
| 1033 | _fsmap_copy.filter(session->get_allowed_fs_names()); |
| 1034 | const auto& fsmap = _fsmap_copy; |
| 1035 | |
| 1036 | if (prefix == "mds stat") { |
| 1037 | if (f) { |
| 1038 | f->open_object_section("mds_stat"); |
| 1039 | dump_info(f.get()); |
| 1040 | f->close_section(); |
| 1041 | f->flush(ds); |
| 1042 | } else { |
| 1043 | ds << fsmap; |
| 1044 | } |
| 1045 | r = 0; |
| 1046 | } else if (prefix == "mds last-seen") { |
| 1047 | std::string id; |
| 1048 | cmd_getval(cmdmap, "id", id); |
| 1049 | |
| 1050 | dout(10) << "last seen check for " << id << dendl; |
| 1051 | |
| 1052 | auto& history = get_fsmap_history(); |
| 1053 | auto now = real_clock::now(); |
| 1054 | bool found = false; |
| 1055 | /* Special case: |
| 1056 | * If the mons consider the MDS "in" the latest FSMap, then the mds |
| 1057 | * is always "last seen" **now** (for the purposes of this API). We |
| 1058 | * don't look at past beacons because that is only managed by the |
| 1059 | * leader and the logic is fudged in places in the event of suspected |
| 1060 | * network partitions. |
| 1061 | */ |
nothing calls this directly
no test coverage detected