Whamcloud - gitweb
LU-11299 lnet: net aliveness
[fs/lustre-release.git] / lnet / lnet / config.c
index 9469a11..15f80bd 100644 (file)
@@ -23,7 +23,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2016, Intel Corporation.
+ * Copyright (c) 2012, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -31,6 +31,9 @@
  */
 
 #define DEBUG_SUBSYSTEM S_LNET
+
+#include <linux/ctype.h>
+#include <linux/inetdevice.h>
 #include <linux/nsproxy.h>
 #include <net/net_namespace.h>
 #include <lnet/lib-lnet.h>
@@ -121,10 +124,10 @@ lnet_ni_unique_net(struct list_head *nilist, char *iface)
 /* check that the NI is unique to the interfaces with in the same NI.
  * This is only a consideration if use_tcp_bonding is set */
 static bool
-lnet_ni_unique_ni(char *iface_list[LNET_MAX_INTERFACES], char *iface)
+lnet_ni_unique_ni(char *iface_list[LNET_INTERFACES_NUM], char *iface)
 {
        int i;
-       for (i = 0; i < LNET_MAX_INTERFACES; i++) {
+       for (i = 0; i < LNET_INTERFACES_NUM; i++) {
                if (iface_list[i] != NULL &&
                    strncmp(iface_list[i], iface, strlen(iface)) == 0)
                        return false;
@@ -173,7 +176,7 @@ lnet_net_append_cpts(__u32 *cpts, __u32 ncpts, struct lnet_net *net)
                LIBCFS_ALLOC(net->net_cpts, sizeof(*net->net_cpts) * ncpts);
                if (net->net_cpts == NULL)
                        return -ENOMEM;
-               memcpy(net->net_cpts, cpts, ncpts);
+               memcpy(net->net_cpts, cpts, ncpts * sizeof(*net->net_cpts));
                net->net_ncpts = ncpts;
                return 0;
        }
@@ -307,7 +310,7 @@ lnet_ni_free(struct lnet_ni *ni)
        if (ni->ni_cpts != NULL)
                cfs_expr_list_values_free(ni->ni_cpts, ni->ni_ncpts);
 
-       for (i = 0; i < LNET_MAX_INTERFACES &&
+       for (i = 0; i < LNET_INTERFACES_NUM &&
                    ni->ni_interfaces[i] != NULL; i++) {
                LIBCFS_FREE(ni->ni_interfaces[i],
                            strlen(ni->ni_interfaces[i]) + 1);
@@ -374,8 +377,10 @@ lnet_net_alloc(__u32 net_id, struct list_head *net_list)
        INIT_LIST_HEAD(&net->net_ni_list);
        INIT_LIST_HEAD(&net->net_ni_added);
        INIT_LIST_HEAD(&net->net_ni_zombie);
+       spin_lock_init(&net->net_lock);
 
        net->net_id = net_id;
+       net->net_last_alive = ktime_get_real_seconds();
        net->net_state = LNET_NET_STATE_INIT;
 
        /* initialize global paramters to undefiend */
@@ -407,11 +412,11 @@ lnet_ni_add_interface(struct lnet_ni *ni, char *iface)
         * can free the tokens at the end of the function.
         * The newly allocated ni_interfaces[] can be
         * freed when freeing the NI */
-       while (niface < LNET_MAX_INTERFACES &&
+       while (niface < LNET_INTERFACES_NUM &&
               ni->ni_interfaces[niface] != NULL)
                niface++;
 
-       if (niface >= LNET_MAX_INTERFACES) {
+       if (niface >= LNET_INTERFACES_NUM) {
                LCONSOLE_ERROR_MSG(0x115, "Too many interfaces "
                                   "for net %s\n",
                                   libcfs_net2str(LNET_NIDNET(ni->ni_nid)));
@@ -454,8 +459,9 @@ lnet_ni_alloc_common(struct lnet_net *net, char *iface)
        }
 
        spin_lock_init(&ni->ni_lock);
-       INIT_LIST_HEAD(&ni->ni_cptlist);
        INIT_LIST_HEAD(&ni->ni_netlist);
+       INIT_LIST_HEAD(&ni->ni_recovery);
+       LNetInvalidateMDHandle(&ni->ni_ping_mdh);
        ni->ni_refs = cfs_percpt_alloc(lnet_cpt_table(),
                                       sizeof(*ni->ni_refs[0]));
        if (ni->ni_refs == NULL)
@@ -479,7 +485,6 @@ lnet_ni_alloc_common(struct lnet_net *net, char *iface)
        else
                ni->ni_net_ns = NULL;
 
-       ni->ni_last_alive = ktime_get_real_seconds();
        ni->ni_state = LNET_NI_STATE_INIT;
        list_add_tail(&ni->ni_netlist, &net->net_ni_added);
 
@@ -1242,7 +1247,7 @@ lnet_parse_route (char *str, int *im_a_router)
                                continue;
                        }
 
-                       rc = lnet_add_route(net, hops, nid, priority);
+                       rc = lnet_add_route(net, hops, nid, priority, 1);
                        if (rc != 0 && rc != -EEXIST && rc != -EHOSTUNREACH) {
                                CERROR("Can't create route "
                                       "to %s via %s\n",
@@ -1607,68 +1612,61 @@ lnet_ipaddr_free_enumeration(__u32 *ipaddrs, int nip)
 }
 
 static int
-lnet_ipaddr_enumerate (__u32 **ipaddrsp)
+lnet_ipaddr_enumerate(u32 **ipaddrsp)
 {
-       int        up;
-       __u32      netmask;
-       __u32     *ipaddrs;
-       __u32     *ipaddrs2;
-       int        nip;
-       char     **ifnames;
-       int        nif = lnet_ipif_enumerate(&ifnames);
-       int        i;
-       int        rc;
-
-       if (nif <= 0)
-               return nif;
-
-       LIBCFS_ALLOC(ipaddrs, nif * sizeof(*ipaddrs));
-       if (ipaddrs == NULL) {
-               CERROR("Can't allocate ipaddrs[%d]\n", nif);
-               lnet_ipif_free_enumeration(ifnames, nif);
+       struct net_device *dev;
+       u32 *ipaddrs;
+       int nalloc = 64;
+       int nip = 0;
+
+       LIBCFS_ALLOC(ipaddrs, nalloc * sizeof(*ipaddrs));
+       if (!ipaddrs) {
+               CERROR("Can't allocate ipaddrs[%d]\n", nalloc);
                return -ENOMEM;
        }
 
-       for (i = nip = 0; i < nif; i++) {
-               if (!strcmp(ifnames[i], "lo"))
+       rtnl_lock();
+       for_each_netdev(&init_net, dev) {
+               struct in_device *in_dev;
+
+               if (strcmp(dev->name, "lo") == 0)
                        continue;
 
-               rc = lnet_ipif_query(ifnames[i], &up,
-                                      &ipaddrs[nip], &netmask);
-               if (rc != 0) {
-                       CWARN("Can't query interface %s: %d\n",
-                             ifnames[i], rc);
+               if (!(dev_get_flags(dev) & IFF_UP)) {
+                       CWARN("Ignoring interface %s: it's down\n", dev->name);
                        continue;
                }
 
-               if (!up) {
-                       CWARN("Ignoring interface %s: it's down\n",
-                             ifnames[i]);
+               in_dev = __in_dev_get_rtnl(dev);
+               if (!in_dev) {
+                       CWARN("Interface %s has no IPv4 status.\n", dev->name);
                        continue;
                }
 
-               nip++;
-       }
-
-       lnet_ipif_free_enumeration(ifnames, nif);
+               if (nip >= nalloc) {
+                       u32 *ipaddrs2;
 
-       if (nip == nif) {
-               *ipaddrsp = ipaddrs;
-       } else {
-               if (nip > 0) {
-                       LIBCFS_ALLOC(ipaddrs2, nip * sizeof(*ipaddrs2));
-                       if (ipaddrs2 == NULL) {
+                       nalloc += nalloc;
+                       ipaddrs2 = krealloc(ipaddrs, nalloc * sizeof(*ipaddrs2),
+                                           GFP_KERNEL);
+                       if (!ipaddrs2) {
+                               kfree(ipaddrs);
                                CERROR("Can't allocate ipaddrs[%d]\n", nip);
-                               nip = -ENOMEM;
-                       } else {
-                               memcpy(ipaddrs2, ipaddrs,
-                                       nip * sizeof(*ipaddrs));
-                               *ipaddrsp = ipaddrs2;
-                               rc = nip;
+                               return -ENOMEM;
                        }
+                       ipaddrs = ipaddrs2;
                }
-               lnet_ipaddr_free_enumeration(ipaddrs, nif);
+
+               for_primary_ifa(in_dev)
+                       if (strcmp(ifa->ifa_label, dev->name) == 0) {
+                               ipaddrs[nip++] = ifa->ifa_local;
+                               break;
+                       }
+               endfor_ifa(in_dev);
        }
+       rtnl_unlock();
+
+       *ipaddrsp = ipaddrs;
        return nip;
 }