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 <sage@redhat.com>
This commit is contained in:
Sage Weil 2018-12-10 21:32:39 -06:00
parent 5992a61c2c
commit 572311b614
9 changed files with 41 additions and 30 deletions

View File

@ -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) {

View File

@ -463,7 +463,7 @@ std::vector<unsigned> 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()

View File

@ -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;

View File

@ -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()

View File

@ -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<entity_addr_t> 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<entity_addr_t> 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<std::string>("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<std::string>("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<std::string>("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<std::string>("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;
}
}

View File

@ -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
};

View File

@ -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);

View File

@ -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;

View File

@ -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;
}