]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/msg/msg_types.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / msg / msg_types.cc
index 330cfba5bc35a997aad4129473ef90198b418c63..0c28e915b7b0a85f76eb2842d621bffc28416fa0 100644 (file)
 
 #include "common/Formatter.h"
 
+bool entity_name_t::parse(std::string_view s)
+{
+  const char* start = s.data();
+  if (s.find("mon.") == 0) {
+    _type = TYPE_MON;
+    start += 4;
+  } else if (s.find("osd.") == 0) {
+    _type = TYPE_OSD;
+    start += 4;
+  } else if (s.find("mds.") == 0) {
+    _type = TYPE_MDS;
+    start += 4;
+  } else if (s.find("client.") == 0) {
+    _type = TYPE_CLIENT;
+    start += 7;
+  } else if (s.find("mgr.") == 0) {
+    _type = TYPE_MGR;
+    start += 4;
+  } else {
+    return false;
+  }
+  if (isspace(*start))
+    return false;
+  char *end = nullptr;
+  _num = strtoll(start, &end, 10);
+  if (end == nullptr || end == start) {
+    return false;
+  } else {
+    return end == s.data() + s.size();
+  }
+}
+
 void entity_name_t::dump(ceph::Formatter *f) const
 {
   f->dump_string("type", type_str());
@@ -64,11 +96,11 @@ void entity_inst_t::generate_test_instances(std::list<entity_inst_t*>& o)
   o.push_back(a);
 }
 
-bool entity_addr_t::parse(const std::string_view s)
+bool entity_addr_t::parse(const std::string_view s, int default_type)
 {
   const char* start = s.data();
   const char* end = nullptr;
-  bool got = parse(start, &end);
+  bool got = parse(start, &end, default_type);
   return got && end == start + s.size();
 }
 
@@ -81,7 +113,7 @@ bool entity_addr_t::parse(const char *s, const char **end, int default_type)
     *end = s;
   }
 
-  int newtype;
+  int newtype = default_type;
   if (strncmp("v1:", s, 3) == 0) {
     start += 3;
     newtype = TYPE_LEGACY;
@@ -97,8 +129,6 @@ bool entity_addr_t::parse(const char *s, const char **end, int default_type)
       *end = s + 1;
     }
     return true;
-  } else {
-    newtype = default_type ? default_type : TYPE_DEFAULT;
   }
 
   bool brackets = false;