summaryrefslogtreecommitdiffstats
path: root/src/mon/MonMap.cc
diff options
context:
space:
mode:
authorShyamsundar Ranganathan <srangana@redhat.com>2020-08-10 02:47:43 +0200
committerShyamsundar Ranganathan <srangana@redhat.com>2020-08-13 22:04:52 +0200
commit7a1f02acfe6b5d8a760efd16bb594a0656b39eac (patch)
treec1cbb1f8f8d0c4d9e41f7736af7df7f537c758c7 /src/mon/MonMap.cc
parentMerge pull request #36510 from athanatos/sjust/wip-tm-decref (diff)
downloadceph-7a1f02acfe6b5d8a760efd16bb594a0656b39eac.tar.xz
ceph-7a1f02acfe6b5d8a760efd16bb594a0656b39eac.zip
mon: store mon updates in ceph context for future MonMap instantiation
MonMap builds initial mon list using provided sources, like mon-host or monmap. For future instantiations of MonClient, if mon addresses are updated, stale information from the provided sources are used. This commit retains mon updates that are processed by the MonClient in CephContext, for use in MonMap instantiations and hence uses updated information as required. This is helpful in cases where librados or libcephfs instantiate MonClient in the ceph-mgr deamon as required. Fixes: https://tracker.ceph.com/issues/46645 Signed-off-by: Shyamsundar Ranganathan <srangana@redhat.com>
Diffstat (limited to 'src/mon/MonMap.cc')
-rw-r--r--src/mon/MonMap.cc64
1 files changed, 32 insertions, 32 deletions
diff --git a/src/mon/MonMap.cc b/src/mon/MonMap.cc
index dc9c4a8b1a5..01c4ab8fd8a 100644
--- a/src/mon/MonMap.cc
+++ b/src/mon/MonMap.cc
@@ -372,7 +372,6 @@ void MonMap::dump_summary(Formatter *f) const
f->dump_unsigned("num_mons", ranks.size());
}
-
// an ambiguous mon addr may be legacy or may be msgr2--we aren' sure.
// when that happens we need to try them both (unless we can
// reasonably infer from the port number which it is).
@@ -461,9 +460,29 @@ void MonMap::_add_ambiguous_addr(const string& name,
}
}
+int
+MonMap::init_with_addrs(const std::vector<entity_addrvec_t>& addrs,
+ bool for_mkfs,
+ std::string_view prefix)
+{
+ char id = 'a';
+ for (auto& addr : addrs) {
+ string name{prefix};
+ name += id++;
+ if (addr.v.size() == 1) {
+ _add_ambiguous_addr(name, addr.front(), 0, 0, for_mkfs);
+ } else {
+ // they specified an addrvec, so let's assume they also specified
+ // the addr *type* and *port*. (we could possibly improve this?)
+ add(name, addr, 0);
+ }
+ }
+ return 0;
+}
+
int MonMap::init_with_ips(const std::string& ips,
bool for_mkfs,
- const std::string &prefix)
+ std::string_view prefix)
{
vector<entity_addrvec_t> addrs;
if (!parse_ip_port_vec(
@@ -473,27 +492,12 @@ int MonMap::init_with_ips(const std::string& ips,
}
if (addrs.empty())
return -ENOENT;
- for (unsigned i=0; i<addrs.size(); i++) {
- char n[2];
- n[0] = 'a' + i;
- n[1] = 0;
- string name;
- name = prefix;
- name += n;
- if (addrs[i].v.size() == 1) {
- _add_ambiguous_addr(name, addrs[i].front(), 0, 0, for_mkfs);
- } else {
- // they specified an addrvec, so let's assume they also specified
- // the addr *type* and *port*. (we could possibly improve this?)
- add(name, addrs[i], 0);
- }
- }
- return 0;
+ return init_with_addrs(addrs, for_mkfs, prefix);
}
int MonMap::init_with_hosts(const std::string& hostlist,
bool for_mkfs,
- const std::string& prefix)
+ std::string_view prefix)
{
// maybe they passed us a DNS-resolvable name
char *hosts = resolve_addrs(hostlist.c_str());
@@ -509,19 +513,8 @@ int MonMap::init_with_hosts(const std::string& hostlist,
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;
- string name = prefix;
- name += n;
- if (addrs[i].v.size() == 1) {
- _add_ambiguous_addr(name, addrs[i].front(), 0, 0, for_mkfs);
- } else {
- // they specified an addrvec, so let's assume they also specified
- // the addr *type* and *port*. (we could possibly improve this?)
- add(name, addrs[i], 0);
- }
+ if (!init_with_addrs(addrs, for_mkfs, prefix)) {
+ return -EINVAL;
}
calc_legacy_ranks();
return 0;
@@ -826,6 +819,13 @@ int MonMap::init_with_dns_srv(CephContext* cct,
int MonMap::build_initial(CephContext *cct, bool for_mkfs, ostream& errout)
{
const auto& conf = cct->_conf;
+
+ // cct?
+ auto addrs = cct->get_mon_addrs();
+ if (addrs != nullptr && (addrs->size() > 0)) {
+ return init_with_addrs(*addrs, for_mkfs, "noname-");
+ }
+
// file?
if (const auto monmap = conf.get_val<std::string>("monmap");
!monmap.empty()) {