| 16 | #include "include/types.h" |
| 17 | |
| 18 | bool entity_name_t::parse(std::string_view s) |
| 19 | { |
| 20 | const char* start = s.data(); |
| 21 | if (s.find("mon.") == 0) { |
| 22 | _type = TYPE_MON; |
| 23 | start += 4; |
| 24 | } else if (s.find("osd.") == 0) { |
| 25 | _type = TYPE_OSD; |
| 26 | start += 4; |
| 27 | } else if (s.find("mds.") == 0) { |
| 28 | _type = TYPE_MDS; |
| 29 | start += 4; |
| 30 | } else if (s.find("client.") == 0) { |
| 31 | _type = TYPE_CLIENT; |
| 32 | start += 7; |
| 33 | } else if (s.find("mgr.") == 0) { |
| 34 | _type = TYPE_MGR; |
| 35 | start += 4; |
| 36 | } else { |
| 37 | return false; |
| 38 | } |
| 39 | if (isspace(*start)) |
| 40 | return false; |
| 41 | char *end = nullptr; |
| 42 | _num = strtoll(start, &end, 10); |
| 43 | if (end == nullptr || end == start) { |
| 44 | return false; |
| 45 | } else { |
| 46 | return end == s.data() + s.size(); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | void entity_name_t::dump(ceph::Formatter *f) const |
| 51 | { |