}
} 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) {
} 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) {
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()
int r;
MonMap monmap;
- r = monmap.build_initial(cct, cerr);
+ r = monmap.build_initial(cct, false, cerr);
if (r < 0)
return r;
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()
}
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())
}
int MonMap::init_with_hosts(const std::string& hostlist,
+ bool for_mkfs,
const std::string& prefix)
{
// maybe they passed us a DNS-resolvable name
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;
});
}
-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;
// 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()) {
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) {
});
}
-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");
});
}
-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");
!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();
int MonMap::init_with_dns_srv(CephContext* cct,
std::string srv_name,
+ bool for_mkfs,
std::ostream& errout)
{
string domain;
<< "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);
}
}
}
-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?
// -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 << "'"
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;
}
}
* @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.
* @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
*
* @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
};
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);
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);
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);
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;
}
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;
}