]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: include front_iface+back_iface in metadata 16941/head
authorJohn Spray <john.spray@redhat.com>
Wed, 9 Aug 2017 11:09:55 +0000 (07:09 -0400)
committerJohn Spray <john.spray@redhat.com>
Wed, 9 Aug 2017 11:53:26 +0000 (07:53 -0400)
Fixes: http://tracker.ceph.com/issues/20956
Signed-off-by: John Spray <john.spray@redhat.com>
src/common/pick_address.cc
src/common/pick_address.h
src/osd/OSD.cc

index e1d3f20a29dea8558e7eafe01fa0d20a7577d8bb..dfea843e9cb13c34dcb63cd17f84664d66e3c0d2 100644 (file)
@@ -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<entity_addr_t>& ls, entity_addr_t *match)
 {
   struct ifaddrs *ifa;
index eb2c104fc6ea801e23dc91ad997ecbddfd91e28f..c7c813d640a1b258543fbc42fdfdb937de8daeaf 100644 (file)
@@ -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
  *
index 58245ecb49de3eb2ad53bcef1a0c7e8e8d77a933..d759d78e4aac353fb0d39c4b6cd69be1f5c397b4 100644 (file)
@@ -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<string,string> *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;
 }