From: Kefu Chai Date: Fri, 10 Aug 2018 10:19:01 +0000 (+0800) Subject: mon/MonMap: split build_from_host_list() into smaller pieces X-Git-Tag: v14.0.1~23^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b39a949b111eed30c69235e9f683e4bfbdef6531;p=ceph.git mon/MonMap: split build_from_host_list() into smaller pieces so we can reuse the non-blocking part in MonMap's seastar port. Signed-off-by: Kefu Chai --- diff --git a/src/mon/MonMap.cc b/src/mon/MonMap.cc index e579865e742..96854582d92 100644 --- a/src/mon/MonMap.cc +++ b/src/mon/MonMap.cc @@ -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 addrs; - if (parse_ip_port_vec(hostlist.c_str(), addrs)) { - if (addrs.empty()) - return -ENOENT; - for (unsigned i=0; i 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("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; } } diff --git a/src/mon/MonMap.h b/src/mon/MonMap.h index 2ecb2ebf062..4eeea332101 100644 --- a/src/mon/MonMap.h +++ b/src/mon/MonMap.h @@ -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& 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,