From: Sage Weil Date: Tue, 8 Jan 2019 19:38:53 +0000 (-0600) Subject: ceph-mon: make membership check with public_addr more robust X-Git-Tag: v14.1.0~420^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=cee2cf62abc3dc3f2d606ed28a5a2c94f6248ba8;p=ceph.git ceph-mon: make membership check with public_addr more robust If the public_addr has no port, we will check v1 and v2 addresses. MonMap::contains() checks for *any* overlap/match, so we should find ourselves. Signed-off-by: Sage Weil --- diff --git a/src/ceph_mon.cc b/src/ceph_mon.cc index ac6380dcbce8..9a9d33e61e4e 100644 --- a/src/ceph_mon.cc +++ b/src/ceph_mon.cc @@ -384,14 +384,11 @@ int main(int argc, const char **argv) // hmm, make sure the ip listed exists on the current host? // maybe later. } else if (!g_conf()->public_addr.is_blank_ip()) { - entity_addr_t a = g_conf()->public_addr; - if (a.get_port() == 0) - a.set_port(CEPH_MON_PORT_LEGACY); - if (monmap.contains(a)) { - string name; - monmap.get_addr_name(a, name); + entity_addrvec_t av = make_mon_addrs(g_conf()->public_addr); + string name; + if (monmap.contains(av, &name)) { monmap.rename(name, g_conf()->name.get_id()); - dout(0) << argv[0] << ": renaming mon." << name << " " << a + dout(0) << argv[0] << ": renaming mon." << name << " " << av << " to mon." << g_conf()->name.get_id() << dendl; } } else { diff --git a/src/mon/MonMap.h b/src/mon/MonMap.h index 62f313e7b957..addd7a1c4fbc 100644 --- a/src/mon/MonMap.h +++ b/src/mon/MonMap.h @@ -274,21 +274,27 @@ public: * @returns true if monmap contains a monitor with address @p; * false otherwise. */ - bool contains(const entity_addr_t &a) const { + bool contains(const entity_addr_t &a, string *name=nullptr) const { for (auto& i : mon_info) { for (auto& j : i.second.public_addrs.v) { if (j == a) { + if (name) { + *name = i.first; + } return true; } } } return false; } - bool contains(const entity_addrvec_t &av) const { + bool contains(const entity_addrvec_t &av, string *name=nullptr) const { for (auto& i : mon_info) { for (auto& j : i.second.public_addrs.v) { for (auto& k : av.v) { if (j == k) { + if (name) { + *name = i.first; + } return true; } }