From: John Spray Date: Wed, 9 Aug 2017 11:09:55 +0000 (-0400) Subject: osd: include front_iface+back_iface in metadata X-Git-Tag: v13.0.0~149^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=79491c15473310b2ac315f8698b11bdde588b20d;p=ceph-ci.git osd: include front_iface+back_iface in metadata Fixes: http://tracker.ceph.com/issues/20956 Signed-off-by: John Spray --- diff --git a/src/common/pick_address.cc b/src/common/pick_address.cc index e1d3f20a29d..dfea843e9cb 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 eb2c104fc6e..c7c813d640a 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 58245ecb49d..d759d78e4aa 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 @@ -5899,6 +5900,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; }