]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/MonMap: split build_from_host_list() into smaller pieces
authorKefu Chai <kchai@redhat.com>
Fri, 10 Aug 2018 10:19:01 +0000 (18:19 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 9 Oct 2018 09:39:39 +0000 (17:39 +0800)
so we can reuse the non-blocking part in MonMap's seastar port.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/mon/MonMap.cc
src/mon/MonMap.h

index e579865e74283bb97dfd5ebafa840703dd7fde75..96854582d92974d12a7efc06841098814c468030 100644 (file)
@@ -1,3 +1,4 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
 
 #include "MonMap.h"
 
@@ -320,30 +321,38 @@ void MonMap::dump(Formatter *f) const
 }
 
 
-int MonMap::build_from_host_list(std::string hostlist, const std::string &prefix)
+int MonMap::init_with_ips(const std::string& ips,
+                         const std::string &prefix)
 {
   vector<entity_addr_t> addrs;
-  if (parse_ip_port_vec(hostlist.c_str(), addrs)) {
-    if (addrs.empty())
-      return -ENOENT;
-    for (unsigned i=0; i<addrs.size(); i++) {
-      char n[2];
-      n[0] = 'a' + i;
-      n[1] = 0;
-      if (addrs[i].get_port() == 0)
-       addrs[i].set_port(CEPH_MON_PORT_LEGACY);
-      string name = prefix;
-      name += n;
-      if (!contains(addrs[i]))
-       add(name, addrs[i]);
-    }
-    return 0;
+  if (!parse_ip_port_vec(ips.c_str(), addrs)) {
+    return -EINVAL;
   }
+  if (addrs.empty())
+    return -ENOENT;
+  for (unsigned i=0; i<addrs.size(); i++) {
+    char n[2];
+    n[0] = 'a' + i;
+    n[1] = 0;
+    if (addrs[i].get_port() == 0)
+      addrs[i].set_port(CEPH_MON_PORT_LEGACY);
+    string name = prefix;
+    name += n;
+    if (!contains(addrs[i]))
+      add(name, addrs[i]);
+  }
+  return 0;
+}
 
+int MonMap::init_with_hosts(const std::string& hostlist,
+                           const std::string& prefix)
+{
   // maybe they passed us a DNS-resolvable name
   char *hosts = resolve_addrs(hostlist.c_str());
   if (!hosts)
     return -EINVAL;
+
+  vector<entity_addr_t> addrs;
   bool success = parse_ip_port_vec(hosts, addrs);
   free(hosts);
   if (!success)
@@ -429,21 +438,6 @@ int MonMap::init_with_monmap(const std::string& monmap, std::ostream& errout)
   return r;
 }
 
-int MonMap::init_with_mon_host(const std::string& mon_host,
-                               std::ostream& errout)
-{
-  int r = build_from_host_list(mon_host, "noname-");
-  if (r < 0) {
-    errout << "unable to parse addrs in '" << mon_host << "'"
-           << std::endl;
-    return r;
-  }
-  created = ceph_clock_now();
-  last_changed = created;
-  calc_legacy_ranks();
-  return 0;
-}
-
 int MonMap::init_with_config_file(const ConfigProxy& conf,
                                   std::ostream& errout)
 {
@@ -554,7 +548,13 @@ int MonMap::build_initial(CephContext *cct, ostream& errout)
   // -m foo?
   if (const auto mon_host = conf.get_val<std::string>("mon_host");
       !mon_host.empty()) {
-    if (auto ret = init_with_mon_host(mon_host, errout); ret < 0) {
+    auto ret = init_with_ips(mon_host, "noname-");
+    if (ret == -EINVAL) {
+      ret = init_with_hosts(mon_host, "noname-");
+    }
+    if (ret < 0) {
+      errout << "unable to parse addrs in '" << mon_host << "'"
+            << std::endl;
       return ret;
     }
   }
index 2ecb2ebf06206ccbe0900fef8a3d4b62ea4ea3cf..4eeea332101725d2c508505b1e91de10c06a47c5 100644 (file)
@@ -345,17 +345,6 @@ public:
    */
   int build_initial(CephContext *cct, ostream& errout);
 
-  /**
-   * build a monmap from a list of hosts or ips
-   *
-   * Resolve dns as needed.  Give mons dummy names.
-   *
-   * @param hosts  list of hosts, space or comma separated
-   * @param prefix prefix to prepend to generated mon names
-   * @return 0 for success, -errno on error
-   */
-  int build_from_host_list(std::string hosts, const std::string &prefix);
-
   /**
    * filter monmap given a set of initial members.
    *
@@ -381,6 +370,28 @@ public:
   static void generate_test_instances(list<MonMap*>& o);
 private:
   int init_with_monmap(const std::string& monmap, std::ostream& errout);
+  /**
+   * build a monmap from a list of ips
+   *
+   * Give mons dummy names.
+   *
+   * @param hosts  list of ips, space or comma separated
+   * @param prefix prefix to prepend to generated mon names
+   * @return 0 for success, -errno on error
+   */
+  int init_with_ips(const std::string& ips,
+                        const std::string &prefix);
+  /**
+   * build a monmap from a list of hostnames
+   *
+   * Give mons dummy names.
+   *
+   * @param hosts  list of ips, space or comma separated
+   * @param prefix prefix to prepend to generated mon names
+   * @return 0 for success, -errno on error
+   */
+  int init_with_hosts(const std::string& hostlist,
+                        const std::string& prefix);
   int init_with_mon_host(const std::string& mon_host, std::ostream& errout);
   int init_with_config_file(const ConfigProxy& conf, std::ostream& errout);
   int init_with_dns_srv(CephContext* cct, std::string srv_name,