From 572311b6142d1cc85bb2f8a493968fdd12593bf8 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 10 Dec 2018 21:32:39 -0600 Subject: [PATCH] mon/MonMap: adjust build_initial behavior for mkfs vs probe For the mkfs case, interpret an ambiguous port as a v2 address. For probe, try both. Signed-off-by: Sage Weil --- src/ceph_mon.cc | 4 ++-- src/crimson/mon/MonClient.cc | 2 +- src/krbd.cc | 2 +- src/mon/MonClient.cc | 2 +- src/mon/MonMap.cc | 35 +++++++++++++++++++++------------ src/mon/MonMap.h | 16 ++++++++------- src/test/mon/MonMap.cc | 6 +++--- src/tools/ceph_monstore_tool.cc | 2 +- src/tools/monmaptool.cc | 2 +- 9 files changed, 41 insertions(+), 30 deletions(-) diff --git a/src/ceph_mon.cc b/src/ceph_mon.cc index 0df665d5e62b0..e47cf22cc8c6d 100644 --- a/src/ceph_mon.cc +++ b/src/ceph_mon.cc @@ -372,7 +372,7 @@ int main(int argc, const char **argv) } } else { ostringstream oss; - int err = monmap.build_initial(g_ceph_context, oss); + int err = monmap.build_initial(g_ceph_context, true, oss); if (oss.tellp()) derr << oss.str() << dendl; if (err < 0) { @@ -673,7 +673,7 @@ int main(int argc, const char **argv) } else { MonMap tmpmap; ostringstream oss; - int err = tmpmap.build_initial(g_ceph_context, oss); + int err = tmpmap.build_initial(g_ceph_context, true, oss); if (oss.tellp()) derr << oss.str() << dendl; if (err < 0) { diff --git a/src/crimson/mon/MonClient.cc b/src/crimson/mon/MonClient.cc index 8817abc193dd6..0ba52e16f9e3b 100644 --- a/src/crimson/mon/MonClient.cc +++ b/src/crimson/mon/MonClient.cc @@ -463,7 +463,7 @@ std::vector Client::get_random_mons(unsigned n) const seastar::future<> Client::build_initial_map() { - return monmap.build_initial(ceph::common::local_conf()); + return monmap.build_initial(ceph::common::local_conf(), false); } seastar::future<> Client::authenticate() diff --git a/src/krbd.cc b/src/krbd.cc index d9fa1727d6db9..88da074664db1 100644 --- a/src/krbd.cc +++ b/src/krbd.cc @@ -162,7 +162,7 @@ static int build_map_buf(CephContext *cct, const krbd_spec& spec, int r; MonMap monmap; - r = monmap.build_initial(cct, cerr); + r = monmap.build_initial(cct, false, cerr); if (r < 0) return r; diff --git a/src/mon/MonClient.cc b/src/mon/MonClient.cc index f4587b777ef0d..2055ddbce8f6c 100644 --- a/src/mon/MonClient.cc +++ b/src/mon/MonClient.cc @@ -73,7 +73,7 @@ MonClient::~MonClient() int MonClient::build_initial_monmap() { ldout(cct, 10) << __func__ << dendl; - return monmap.build_initial(cct, cerr); + return monmap.build_initial(cct, false, cerr); } int MonClient::get_monmap() diff --git a/src/mon/MonMap.cc b/src/mon/MonMap.cc index 5ce5a93e41a4f..f5478e2612869 100644 --- a/src/mon/MonMap.cc +++ b/src/mon/MonMap.cc @@ -408,10 +408,13 @@ void MonMap::_add_ambiguous_addr(const string& name, } int MonMap::init_with_ips(const std::string& ips, + bool for_mkfs, const std::string &prefix) { vector addrs; - if (!parse_ip_port_vec(ips.c_str(), addrs, entity_addr_t::TYPE_ANY)) { + if (!parse_ip_port_vec( + ips.c_str(), addrs, + for_mkfs ? entity_addr_t::TYPE_MSGR2 : entity_addr_t::TYPE_ANY)) { return -EINVAL; } if (addrs.empty()) @@ -428,6 +431,7 @@ int MonMap::init_with_ips(const std::string& ips, } int MonMap::init_with_hosts(const std::string& hostlist, + bool for_mkfs, const std::string& prefix) { // maybe they passed us a DNS-resolvable name @@ -436,7 +440,9 @@ int MonMap::init_with_hosts(const std::string& hostlist, return -EINVAL; vector addrs; - bool success = parse_ip_port_vec(hosts, addrs, entity_addr_t::TYPE_ANY); + bool success = parse_ip_port_vec( + hosts, addrs, + for_mkfs ? entity_addr_t::TYPE_MSGR2 : entity_addr_t::TYPE_ANY); free(hosts); if (!success) return -EINVAL; @@ -593,7 +599,7 @@ future<> MonMap::read_monmap(const std::string& monmap) }); } -future<> MonMap::init_with_dns_srv(const std::string& name) +future<> MonMap::init_with_dns_srv(bool for_mkfs, const std::string& name) { string domain; string service = name; @@ -612,7 +618,7 @@ future<> MonMap::init_with_dns_srv(const std::string& name) // the resolved address does not contain ceph specific info like nonce // nonce or msgr proto (legacy, msgr2), so set entity_addr_t manually entity_addr_t addr; - addr.set_type(entity_addr_t::TYPE_LEGACY); + addr.set_type(entity_addr_t::TYPE_ANY); addr.set_family(int(a.in_family())); addr.set_port(record.port); switch (a.in_family()) { @@ -623,7 +629,7 @@ future<> MonMap::init_with_dns_srv(const std::string& name) addr.in6_addr().sin6_addr = a; break; } - add(mon_info_t{record.target, addr, record.priority}); + _add_ambiguous_addr(record.target, addr, record.priority); }); }); }).handle_exception_type([](const std::system_error& e) { @@ -632,7 +638,8 @@ future<> MonMap::init_with_dns_srv(const std::string& name) }); } -seastar::future<> MonMap::build_monmap(const ceph::common::ConfigProxy& conf) +seastar::future<> MonMap::build_monmap(const ceph::common::ConfigProxy& conf, + bool for_mkfs) { // -m foo? if (const auto mon_host = conf.get_val("mon_host"); @@ -665,7 +672,7 @@ seastar::future<> MonMap::build_monmap(const ceph::common::ConfigProxy& conf) }); } -future<> MonMap::build_initial(const ceph::common::ConfigProxy& conf) +future<> MonMap::build_initial(const ceph::common::ConfigProxy& conf, bool for_mkfs) { // file? if (const auto monmap = conf.get_val("monmap"); @@ -677,7 +684,7 @@ future<> MonMap::build_initial(const ceph::common::ConfigProxy& conf) !new_fsid.is_zero()) { fsid = new_fsid; } - return build_monmap(conf).then([this] { + return build_monmap(conf, for_mkfs).then([this] { created = ceph_clock_now(); last_changed = created; calc_legacy_ranks(); @@ -704,6 +711,7 @@ int MonMap::init_with_monmap(const std::string& monmap, std::ostream& errout) int MonMap::init_with_dns_srv(CephContext* cct, std::string srv_name, + bool for_mkfs, std::ostream& errout) { string domain; @@ -722,7 +730,8 @@ int MonMap::init_with_dns_srv(CephContext* cct, << "ceph-mon" << std::endl; return -1; } else { - for (const auto& record : records) { + for (auto& record : records) { + record.second.addr.set_type(entity_addr_t::TYPE_ANY); _add_ambiguous_addr(record.first, record.second.addr, record.second.priority); } @@ -730,7 +739,7 @@ int MonMap::init_with_dns_srv(CephContext* cct, } } -int MonMap::build_initial(CephContext *cct, ostream& errout) +int MonMap::build_initial(CephContext *cct, bool for_mkfs, ostream& errout) { const auto& conf = cct->_conf; // file? @@ -747,9 +756,9 @@ int MonMap::build_initial(CephContext *cct, ostream& errout) // -m foo? if (const auto mon_host = conf.get_val("mon_host"); !mon_host.empty()) { - auto ret = init_with_ips(mon_host, "noname-"); + auto ret = init_with_ips(mon_host, for_mkfs, "noname-"); if (ret == -EINVAL) { - ret = init_with_hosts(mon_host, "noname-"); + ret = init_with_hosts(mon_host, for_mkfs, "noname-"); } if (ret < 0) { errout << "unable to parse addrs in '" << mon_host << "'" @@ -766,7 +775,7 @@ int MonMap::build_initial(CephContext *cct, ostream& errout) if (size() == 0) { // no info found from conf options lets try use DNS SRV records string srv_name = conf.get_val("mon_dns_srv_name"); - if (auto ret = init_with_dns_srv(cct, srv_name, errout); ret < 0) { + if (auto ret = init_with_dns_srv(cct, srv_name, for_mkfs, errout); ret < 0) { return -ENOENT; } } diff --git a/src/mon/MonMap.h b/src/mon/MonMap.h index d214157d034bd..7ea959e673779 100644 --- a/src/mon/MonMap.h +++ b/src/mon/MonMap.h @@ -382,9 +382,9 @@ public: * @param errout ostream to send error messages too */ #ifdef WITH_SEASTAR - seastar::future<> build_initial(const ceph::common::ConfigProxy& conf); + seastar::future<> build_initial(const ceph::common::ConfigProxy& conf, bool for_mkfs); #else - int build_initial(CephContext *cct, ostream& errout); + int build_initial(CephContext *cct, bool for_mkfs, ostream& errout); #endif /** * filter monmap given a set of initial members. @@ -421,7 +421,8 @@ protected: * @return 0 for success, -errno on error */ int init_with_ips(const std::string& ips, - const std::string &prefix); + bool for_mkfs, + const std::string &prefix); /** * build a monmap from a list of hostnames * @@ -432,19 +433,20 @@ protected: * @return 0 for success, -errno on error */ int init_with_hosts(const std::string& hostlist, - const std::string& prefix); + bool for_mkfs, + const std::string& prefix); int init_with_config_file(const ConfigProxy& conf, std::ostream& errout); #if WITH_SEASTAR seastar::future<> read_monmap(const std::string& monmap); /// try to build monmap with different settings, like /// mon_host, mon* sections, and mon_dns_srv_name - seastar::future<> build_monmap(const ceph::common::ConfigProxy& conf); + seastar::future<> build_monmap(const ceph::common::ConfigProxy& conf, bool for_mkfs); /// initialize monmap by resolving given service name - seastar::future<> init_with_dns_srv(const std::string& name); + seastar::future<> init_with_dns_srv(bool for_mkfs, const std::string& name); #else /// read from encoded monmap file int init_with_monmap(const std::string& monmap, std::ostream& errout); - int init_with_dns_srv(CephContext* cct, std::string srv_name, + int init_with_dns_srv(CephContext* cct, std::string srv_name, bool for_mkfs, std::ostream& errout); #endif }; diff --git a/src/test/mon/MonMap.cc b/src/test/mon/MonMap.cc index 2b09f33e758dd..f3c00bfd79442 100644 --- a/src/test/mon/MonMap.cc +++ b/src/test/mon/MonMap.cc @@ -99,7 +99,7 @@ TEST_F(MonMapTest, build_initial_config_from_dns) { CephContext *cct = (new CephContext(CEPH_ENTITY_TYPE_MON))->get(); cct->_conf.set_val("mon_dns_srv_name", "cephmon"); MonMap monmap; - int r = monmap.build_initial(cct, std::cerr); + int r = monmap.build_initial(cct, false, std::cerr); ASSERT_EQ(r, 0); ASSERT_EQ(monmap.mon_addr.size(), (unsigned int)3); @@ -136,7 +136,7 @@ TEST_F(MonMapTest, build_initial_config_from_dns_fail) { CephContext *cct = (new CephContext(CEPH_ENTITY_TYPE_MON))->get(); // using default value of mon_dns_srv_name option MonMap monmap; - int r = monmap.build_initial(cct, std::cerr); + int r = monmap.build_initial(cct, false, std::cerr); ASSERT_EQ(r, -ENOENT); ASSERT_EQ(monmap.mon_addr.size(), (unsigned int)0); @@ -197,7 +197,7 @@ TEST_F(MonMapTest, build_initial_config_from_dns_with_domain) { CephContext *cct = (new CephContext(CEPH_ENTITY_TYPE_MON))->get(); cct->_conf.set_val("mon_dns_srv_name", "cephmon_ceph.com"); MonMap monmap; - int r = monmap.build_initial(cct, std::cerr); + int r = monmap.build_initial(cct, false, std::cerr); ASSERT_EQ(r, 0); ASSERT_EQ(monmap.mon_addr.size(), (unsigned int)3); diff --git a/src/tools/ceph_monstore_tool.cc b/src/tools/ceph_monstore_tool.cc index 97fcf03a8a4de..59ba1422137ff 100644 --- a/src/tools/ceph_monstore_tool.cc +++ b/src/tools/ceph_monstore_tool.cc @@ -499,7 +499,7 @@ static int update_auth(MonitorDBStore& st, const string& keyring_path) static int update_mkfs(MonitorDBStore& st) { MonMap monmap; - int r = monmap.build_initial(g_ceph_context, cerr); + int r = monmap.build_initial(g_ceph_context, true, cerr); if (r) { cerr << "no initial monitors" << std::endl; return -EINVAL; diff --git a/src/tools/monmaptool.cc b/src/tools/monmaptool.cc index 222d5b144d871..7c92282234906 100644 --- a/src/tools/monmaptool.cc +++ b/src/tools/monmaptool.cc @@ -335,7 +335,7 @@ int main(int argc, const char **argv) } if (generate) { - int r = monmap.build_initial(g_ceph_context, cerr); + int r = monmap.build_initial(g_ceph_context, true, cerr); if (r < 0) return r; } -- 2.39.5