From 710217f31e691607977ce98ee46d3dbb5302a95a Mon Sep 17 00:00:00 2001 From: John Spray Date: Wed, 9 Aug 2017 07:09:55 -0400 Subject: [PATCH] osd: include front_iface+back_iface in metadata Fixes: http://tracker.ceph.com/issues/20956 Signed-off-by: John Spray (cherry picked from commit 79491c15473310b2ac315f8698b11bdde588b20d) --- src/common/pick_address.cc | 31 +++++++++++++++++++++++++++++-- src/common/pick_address.h | 6 ++++++ src/osd/OSD.cc | 12 ++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/common/pick_address.cc b/src/common/pick_address.cc index e1d3f20a29de..dfea843e9cb1 100644 --- a/src/common/pick_address.cc +++ b/src/common/pick_address.cc @@ -38,9 +38,10 @@ static const struct sockaddr *find_ip_in_subnet_list(CephContext *cct, exit(1); } - const struct sockaddr *found = find_ip_in_subnet(ifa, (struct sockaddr *) &net, prefix_len); + const struct ifaddrs *found = find_ip_in_subnet(ifa, + (struct sockaddr *) &net, prefix_len); if (found) - return found; + return found->ifa_addr; } return NULL; @@ -133,6 +134,32 @@ void pick_addresses(CephContext *cct, int needs) freeifaddrs(ifa); } + +std::string pick_iface(CephContext *cct, const struct sockaddr_storage &network) +{ + struct ifaddrs *ifa; + int r = getifaddrs(&ifa); + if (r < 0) { + string err = cpp_strerror(errno); + lderr(cct) << "unable to fetch interfaces and addresses: " << err << dendl; + return {}; + } + + unsigned int prefix_len = 0; + const struct ifaddrs *found = find_ip_in_subnet(ifa, + (const struct sockaddr *) &network, prefix_len); + + std::string result; + if (found) { + result = found->ifa_name; + } + + freeifaddrs(ifa); + + return result; +} + + bool have_local_addr(CephContext *cct, const list& ls, entity_addr_t *match) { struct ifaddrs *ifa; diff --git a/src/common/pick_address.h b/src/common/pick_address.h index eb2c104fc6ea..c7c813d640a1 100644 --- a/src/common/pick_address.h +++ b/src/common/pick_address.h @@ -30,6 +30,12 @@ class CephContext; */ void pick_addresses(CephContext *cct, int needs); +/** + * Find a network interface whose address matches the address/netmask + * in `network`. + */ +std::string pick_iface(CephContext *cct, const struct sockaddr_storage &network); + /** * check for a locally configured address * diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index afbfe68a22e2..6f1f50eada8a 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -45,6 +45,7 @@ #include "common/ceph_time.h" #include "common/version.h" #include "common/io_priority.h" +#include "common/pick_address.h" #include "os/ObjectStore.h" #ifdef HAVE_LIBFUSE @@ -5901,6 +5902,17 @@ void OSD::_collect_metadata(map *pm) collect_sys_info(pm, cct); + std::string front_iface, back_iface; + /* + pick_iface(cct, + CEPH_PICK_ADDRESS_PUBLIC | CEPH_PICK_ADDRESS_CLUSTER, + &front_iface, &back_iface); + */ + (*pm)["front_iface"] = pick_iface(cct, + client_messenger->get_myaddr().get_sockaddr_storage()); + (*pm)["back_iface"] = pick_iface(cct, + cluster_messenger->get_myaddr().get_sockaddr_storage()); + dout(10) << __func__ << " " << *pm << dendl; } -- 2.47.3