Whamcloud - gitweb
LU-6245 libcfs: add ktime_get_real_seconds support
[fs/lustre-release.git] / lnet / lnet / config.c
index 6cc64be..ba8b879 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
@@ -27,7 +23,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2014, Intel Corporation.
+ * Copyright (c) 2012, 2016, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -35,6 +31,8 @@
  */
 
 #define DEBUG_SUBSYSTEM S_LNET
+#include <linux/nsproxy.h>
+#include <net/net_namespace.h>
 #include <lnet/lib-lnet.h>
 
 /* tmp struct for parsing routes */
@@ -45,27 +43,27 @@ struct lnet_text_buf {
 };
 
 static int lnet_tbnob = 0;                     /* track text buf allocation */
-#define LNET_MAX_TEXTBUF_NOB     (64<<10)      /* bound allocation */
+#define LNET_MAX_TEXTBUF_NOB    (64<<10)       /* bound allocation */
 #define LNET_SINGLE_TEXTBUF_NOB  (4<<10)
 
-void
+static void
 lnet_syntax(char *name, char *str, int offset, int width)
 {
-        static char dots[LNET_SINGLE_TEXTBUF_NOB];
-        static char dashes[LNET_SINGLE_TEXTBUF_NOB];
+       static char dots[LNET_SINGLE_TEXTBUF_NOB];
+       static char dashes[LNET_SINGLE_TEXTBUF_NOB];
 
-        memset(dots, '.', sizeof(dots));
-        dots[sizeof(dots)-1] = 0;
-        memset(dashes, '-', sizeof(dashes));
-        dashes[sizeof(dashes)-1] = 0;
+       memset(dots, '.', sizeof(dots));
+       dots[sizeof(dots)-1] = 0;
+       memset(dashes, '-', sizeof(dashes));
+       dashes[sizeof(dashes)-1] = 0;
 
        LCONSOLE_ERROR_MSG(0x10f, "Error parsing '%s=\"%s\"'\n", name, str);
        LCONSOLE_ERROR_MSG(0x110, "here...........%.*s..%.*s|%.*s|\n",
-                           (int)strlen(name), dots, offset, dots,
-                            (width < 1) ? 0 : width - 1, dashes);
+                          (int)strlen(name), dots, offset, dots,
+                           (width < 1) ? 0 : width - 1, dashes);
 }
 
-int
+static int
 lnet_issep (char c)
 {
        switch (c) {
@@ -108,16 +106,19 @@ lnet_ni_free(struct lnet_ni *ni)
        if (ni->ni_cpts != NULL)
                cfs_expr_list_values_free(ni->ni_cpts, ni->ni_ncpts);
 
-#ifndef __KERNEL__
-# ifdef HAVE_LIBPTHREAD
-       pthread_mutex_destroy(&ni->ni_lock);
-# endif
-#endif
+       if (ni->ni_lnd_tunables != NULL)
+               LIBCFS_FREE(ni->ni_lnd_tunables, sizeof(*ni->ni_lnd_tunables));
+
        for (i = 0; i < LNET_MAX_INTERFACES &&
                    ni->ni_interfaces[i] != NULL; i++) {
                LIBCFS_FREE(ni->ni_interfaces[i],
                            strlen(ni->ni_interfaces[i]) + 1);
        }
+
+       /* release reference to net namespace */
+       if (ni->ni_net_ns != NULL)
+               put_net(ni->ni_net_ns);
+
        LIBCFS_FREE(ni, sizeof(*ni));
 }
 
@@ -129,26 +130,20 @@ lnet_ni_alloc(__u32 net, struct cfs_expr_list *el, struct list_head *nilist)
        int                     rc;
        int                     i;
 
-        if (!lnet_net_unique(net, nilist)) {
-                LCONSOLE_ERROR_MSG(0x111, "Duplicate network specified: %s\n",
-                                   libcfs_net2str(net));
-                return NULL;
-        }
+       if (!lnet_net_unique(net, nilist)) {
+               LCONSOLE_ERROR_MSG(0x111, "Duplicate network specified: %s\n",
+                                  libcfs_net2str(net));
+               return NULL;
+       }
 
-        LIBCFS_ALLOC(ni, sizeof(*ni));
-        if (ni == NULL) {
-                CERROR("Out of memory creating network %s\n",
-                       libcfs_net2str(net));
-                return NULL;
-        }
+       LIBCFS_ALLOC(ni, sizeof(*ni));
+       if (ni == NULL) {
+               CERROR("Out of memory creating network %s\n",
+                      libcfs_net2str(net));
+               return NULL;
+       }
 
-#ifdef __KERNEL__
        spin_lock_init(&ni->ni_lock);
-#else
-# ifdef HAVE_LIBPTHREAD
-       pthread_mutex_init(&ni->ni_lock, NULL);
-# endif
-#endif
        INIT_LIST_HEAD(&ni->ni_cptlist);
        ni->ni_refs = cfs_percpt_alloc(lnet_cpt_table(),
                                       sizeof(*ni->ni_refs[0]));
@@ -185,7 +180,14 @@ lnet_ni_alloc(__u32 net, struct cfs_expr_list *el, struct list_head *nilist)
 
        /* LND will fill in the address part of the NID */
        ni->ni_nid = LNET_MKNID(net, 0);
-       ni->ni_last_alive = cfs_time_current_sec();
+
+       /* Store net namespace in which current ni is being created */
+       if (current->nsproxy->net_ns != NULL)
+               ni->ni_net_ns = get_net(current->nsproxy->net_ns);
+       else
+               ni->ni_net_ns = NULL;
+
+       ni->ni_last_alive = ktime_get_real_seconds();
        list_add_tail(&ni->ni_list, nilist);
        return ni;
  failed:
@@ -204,6 +206,7 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
        struct lnet_ni  *ni;
        __u32           net;
        int             nnets = 0;
+       struct list_head *temp_node;
 
        if (networks == NULL) {
                CERROR("networks string is undefined\n");
@@ -213,7 +216,7 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
        if (strlen(networks) > LNET_SINGLE_TEXTBUF_NOB) {
                /* _WAY_ conservative */
                LCONSOLE_ERROR_MSG(0x112, "Can't parse networks: string too "
-                                   "long\n");
+                                  "long\n");
                return -EINVAL;
        }
 
@@ -228,11 +231,6 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
        memcpy(tokens, networks, tokensize);
        str = tmp = tokens;
 
-       /* Add in the loopback network */
-       ni = lnet_ni_alloc(LNET_MKNET(LOLND, 0), NULL, nilist);
-       if (ni == NULL)
-               goto failed;
-
        while (str != NULL && *str != 0) {
                char    *comma = strchr(str, ',');
                char    *bracket = strchr(str, '(');
@@ -269,21 +267,21 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
                                *square++ = ' ';
                }
 
-                if (bracket == NULL ||
+               if (bracket == NULL ||
                    (comma != NULL && comma < bracket)) {
 
-                        /* no interface list specified */
+                       /* no interface list specified */
 
                        if (comma != NULL)
                                *comma++ = 0;
                        net = libcfs_str2net(cfs_trimwhite(str));
 
                        if (net == LNET_NIDNET(LNET_NID_ANY)) {
-                                LCONSOLE_ERROR_MSG(0x113, "Unrecognised network"
-                                                   " type\n");
+                               LCONSOLE_ERROR_MSG(0x113, "Unrecognised network"
+                                                  " type\n");
                                tmp = str;
                                goto failed_syntax;
-                        }
+                       }
 
                        if (LNET_NETTYP(net) != LOLND && /* LO is implicit */
                            lnet_ni_alloc(net, el, nilist) == NULL)
@@ -305,7 +303,6 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
                        goto failed_syntax;
                }
 
-               nnets++;
                ni = lnet_ni_alloc(net, el, nilist);
                if (ni == NULL)
                        goto failed;
@@ -334,7 +331,7 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
                        if (*iface == 0) {
                                tmp = iface;
                                goto failed_syntax;
-                        }
+                       }
 
                        if (niface == LNET_MAX_INTERFACES) {
                                LCONSOLE_ERROR_MSG(0x115, "Too many interfaces "
@@ -343,7 +340,7 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
                                goto failed;
                        }
 
-                       /* Allocate a seperate piece of memory and copy
+                       /* Allocate a separate piece of memory and copy
                         * into it the string, so we don't have
                         * a depencency on the tokens string.  This way we
                         * can free the tokens at the end of the function.
@@ -369,7 +366,7 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
                        if (*str != 0) {
                                tmp = str;
                                goto failed_syntax;
-                        }
+                       }
                        str = comma + 1;
                        continue;
                }
@@ -381,10 +378,11 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
                }
        }
 
-       LASSERT(!list_empty(nilist));
+       list_for_each(temp_node, nilist)
+               nnets++;
 
        LIBCFS_FREE(tokens, tokensize);
-       return 0;
+       return nnets;
 
  failed_syntax:
        lnet_syntax("networks", networks, (int)(tmp - tokens), strlen(tmp));
@@ -404,7 +402,7 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
        return -EINVAL;
 }
 
-struct lnet_text_buf *lnet_new_text_buf(int str_len)
+static struct lnet_text_buf *lnet_new_text_buf(int str_len)
 {
        struct lnet_text_buf *ltb;
        int nob;
@@ -432,14 +430,14 @@ struct lnet_text_buf *lnet_new_text_buf(int str_len)
        return ltb;
 }
 
-void
+static void
 lnet_free_text_buf(struct lnet_text_buf *ltb)
 {
        lnet_tbnob -= ltb->ltb_size;
        LIBCFS_FREE(ltb, ltb->ltb_size);
 }
 
-void
+static void
 lnet_free_text_bufs(struct list_head *tbs)
 {
        struct lnet_text_buf  *ltb;
@@ -467,22 +465,22 @@ lnet_print_text_bufs(struct list_head *tbs)
        CDEBUG(D_WARNING, "%d allocated\n", lnet_tbnob);
 }
 
-int
+static int
 lnet_str2tbs_sep(struct list_head *tbs, char *str)
 {
        struct list_head  pending;
-       char             *sep;
-       int               nob;
-        int               i;
+       char             *sep;
+       int               nob;
+       int               i;
        struct lnet_text_buf  *ltb;
 
        INIT_LIST_HEAD(&pending);
 
        /* Split 'str' into separate commands */
        for (;;) {
-                /* skip leading whitespace */
-                while (cfs_iswhite(*str))
-                        str++;
+               /* skip leading whitespace */
+               while (isspace(*str))
+                       str++;
 
                /* scan for separator or comment */
                for (sep = str; *sep != 0; sep++)
@@ -494,14 +492,14 @@ lnet_str2tbs_sep(struct list_head *tbs, char *str)
                        ltb = lnet_new_text_buf(nob);
                        if (ltb == NULL) {
                                lnet_free_text_bufs(&pending);
-                               return -1;
+                               return -ENOMEM;
                        }
 
-                        for (i = 0; i < nob; i++)
-                                if (cfs_iswhite(str[i]))
-                                        ltb->ltb_text[i] = ' ';
-                                else
-                                        ltb->ltb_text[i] = str[i];
+                       for (i = 0; i < nob; i++)
+                               if (isspace(str[i]))
+                                       ltb->ltb_text[i] = ' ';
+                               else
+                                       ltb->ltb_text[i] = str[i];
 
                        ltb->ltb_text[nob] = 0;
 
@@ -525,13 +523,13 @@ lnet_str2tbs_sep(struct list_head *tbs, char *str)
        return 0;
 }
 
-int
+static int
 lnet_expand1tb(struct list_head *list,
               char *str, char *sep1, char *sep2,
               char *item, int itemlen)
 {
-       int              len1 = (int)(sep1 - str);
-       int              len2 = strlen(sep2 + 1);
+       int              len1 = (int)(sep1 - str);
+       int              len2 = strlen(sep2 + 1);
        struct lnet_text_buf *ltb;
 
        LASSERT (*sep1 == '[');
@@ -550,7 +548,7 @@ lnet_expand1tb(struct list_head *list,
        return 0;
 }
 
-int
+static int
 lnet_str2tbs_expand(struct list_head *tbs, char *str)
 {
        char              num[16];
@@ -572,9 +570,9 @@ lnet_str2tbs_expand(struct list_head *tbs, char *str)
        if (sep == NULL)                        /* nothing to expand */
                return 0;
 
-        sep2 = strchr(sep, ']');
-        if (sep2 == NULL)
-                goto failed;
+       sep2 = strchr(sep, ']');
+       if (sep2 == NULL)
+               goto failed;
 
        for (parsed = sep; parsed < sep2; parsed = enditem) {
 
@@ -585,13 +583,13 @@ lnet_str2tbs_expand(struct list_head *tbs, char *str)
                if (enditem == parsed)          /* no empty items */
                        goto failed;
 
-                if (sscanf(parsed, "%d-%d/%d%n", &lo, &hi, &stride, &scanned) < 3) {
+               if (sscanf(parsed, "%d-%d/%d%n", &lo, &hi, &stride, &scanned) < 3) {
 
                        if (sscanf(parsed, "%d-%d%n", &lo, &hi, &scanned) < 2) {
 
                                /* simple string enumeration */
                                if (lnet_expand1tb(&pending, str, sep, sep2,
-                                                   parsed, (int)(enditem - parsed)) != 0)
+                                                  parsed, (int)(enditem - parsed)) != 0)
                                        goto failed;
 
                                continue;
@@ -617,7 +615,7 @@ lnet_str2tbs_expand(struct list_head *tbs, char *str)
                                goto failed;
 
                        if (lnet_expand1tb(&pending, str, sep, sep2,
-                                           num, nob) != 0)
+                                          num, nob) != 0)
                                goto failed;
                }
        }
@@ -627,23 +625,23 @@ lnet_str2tbs_expand(struct list_head *tbs, char *str)
 
  failed:
        lnet_free_text_bufs(&pending);
-       return -1;
+       return -EINVAL;
 }
 
-int
+static int
 lnet_parse_hops (char *str, unsigned int *hops)
 {
-        int     len = strlen(str);
-        int     nob = len;
+       int     len = strlen(str);
+       int     nob = len;
 
-        return (sscanf(str, "%u%n", hops, &nob) >= 1 &&
-                nob == len &&
-                *hops > 0 && *hops < 256);
+       return (sscanf(str, "%u%n", hops, &nob) >= 1 &&
+               nob == len &&
+               *hops > 0 && *hops < 256);
 }
 
 #define LNET_PRIORITY_SEPARATOR (':')
 
-int
+static int
 lnet_parse_priority(char *str, unsigned int *priority, char **token)
 {
        int   nob;
@@ -661,7 +659,7 @@ lnet_parse_priority(char *str, unsigned int *priority, char **token)
                /* Update the caller's token pointer so it treats the found
                   priority as the token to report in the error message. */
                *token += sep - str + 1;
-               return -1;
+               return -EINVAL;
        }
 
        CDEBUG(D_NET, "gateway %s, priority %d, nob %d\n", str, *priority, nob);
@@ -673,26 +671,26 @@ lnet_parse_priority(char *str, unsigned int *priority, char **token)
        return 0;
 }
 
-int
+static int
 lnet_parse_route (char *str, int *im_a_router)
 {
        /* static scratch buffer OK (single threaded) */
-       static char       cmd[LNET_SINGLE_TEXTBUF_NOB];
+       static char       cmd[LNET_SINGLE_TEXTBUF_NOB];
 
        struct list_head  nets;
        struct list_head  gateways;
        struct list_head *tmp1;
        struct list_head *tmp2;
-       __u32             net;
-       lnet_nid_t        nid;
+       __u32             net;
+       lnet_nid_t        nid;
        struct lnet_text_buf  *ltb;
-       int               rc;
-       char             *sep;
-       char             *token = str;
-       int               ntokens = 0;
-       int               myrc = -1;
-       unsigned int      hops;
-       int               got_hops = 0;
+       int               rc;
+       char             *sep;
+       char             *token = str;
+       int               ntokens = 0;
+       int               myrc = -1;
+       __u32             hops;
+       int               got_hops = 0;
        unsigned int      priority = 0;
 
        INIT_LIST_HEAD(&gateways);
@@ -705,11 +703,11 @@ lnet_parse_route (char *str, int *im_a_router)
        sep = str;
        for (;;) {
                /* scan for token start */
-                while (cfs_iswhite(*sep))
+               while (isspace(*sep))
                        sep++;
                if (*sep == 0) {
                        if (ntokens < (got_hops ? 3 : 2))
-                                goto token_error;
+                               goto token_error;
                        break;
                }
 
@@ -717,20 +715,20 @@ lnet_parse_route (char *str, int *im_a_router)
                token = sep++;
 
                /* scan for token end */
-                while (*sep != 0 && !cfs_iswhite(*sep))
+               while (*sep != 0 && !isspace(*sep))
                        sep++;
                if (*sep != 0)
                        *sep++ = 0;
 
                if (ntokens == 1) {
                        tmp2 = &nets;           /* expanding nets */
-                } else if (ntokens == 2 &&
-                           lnet_parse_hops(token, &hops)) {
-                        got_hops = 1;           /* got a hop count */
-                        continue;
-                } else {
+               } else if (ntokens == 2 &&
+                          lnet_parse_hops(token, &hops)) {
+                       got_hops = 1;           /* got a hop count */
+                       continue;
+               } else {
                        tmp2 = &gateways;       /* expanding gateways */
-                }
+               }
 
                ltb = lnet_new_text_buf(strlen(token));
                if (ltb == NULL)
@@ -758,7 +756,7 @@ lnet_parse_route (char *str, int *im_a_router)
                        if (ntokens == 1) {
                                net = libcfs_str2net(ltb->ltb_text);
                                if (net == LNET_NIDNET(LNET_NID_ANY) ||
-                                    LNET_NETTYP(net) == LOLND)
+                                   LNET_NETTYP(net) == LOLND)
                                        goto token_error;
                        } else {
                                rc = lnet_parse_priority(ltb->ltb_text,
@@ -768,14 +766,16 @@ lnet_parse_route (char *str, int *im_a_router)
 
                                nid = libcfs_str2nid(ltb->ltb_text);
                                if (nid == LNET_NID_ANY ||
-                                    LNET_NETTYP(LNET_NIDNET(nid)) == LOLND)
+                                   LNET_NETTYP(LNET_NIDNET(nid)) == LOLND)
                                        goto token_error;
                        }
                }
        }
 
+       /* if there are no hops set then we want to flag this value as
+        * unset since hops is an optional parameter */
        if (!got_hops)
-               hops = 1;
+               hops = LNET_UNDEFINED_HOPS;
 
        LASSERT(!list_empty(&nets));
        LASSERT(!list_empty(&gateways));
@@ -796,7 +796,7 @@ lnet_parse_route (char *str, int *im_a_router)
                        }
 
                        rc = lnet_add_route(net, hops, nid, priority);
-                       if (rc != 0) {
+                       if (rc != 0 && rc != -EEXIST && rc != -EHOSTUNREACH) {
                                CERROR("Can't create route "
                                       "to %s via %s\n",
                                       libcfs_net2str(net),
@@ -817,7 +817,7 @@ out:
        return myrc;
 }
 
-int
+static int
 lnet_parse_route_tbs(struct list_head *tbs, int *im_a_router)
 {
        struct lnet_text_buf   *ltb;
@@ -834,16 +834,16 @@ lnet_parse_route_tbs(struct list_head *tbs, int *im_a_router)
                lnet_free_text_buf(ltb);
        }
 
-        return 0;
+       return 0;
 }
 
 int
 lnet_parse_routes (char *routes, int *im_a_router)
 {
        struct list_head tbs;
-       int              rc = 0;
+       int              rc = 0;
 
-        *im_a_router = 0;
+       *im_a_router = 0;
 
        INIT_LIST_HEAD(&tbs);
 
@@ -851,14 +851,14 @@ lnet_parse_routes (char *routes, int *im_a_router)
                CERROR("Error parsing routes\n");
                rc = -EINVAL;
        } else {
-                rc = lnet_parse_route_tbs(&tbs, im_a_router);
-        }
+               rc = lnet_parse_route_tbs(&tbs, im_a_router);
+       }
 
        LASSERT (lnet_tbnob == 0);
        return rc;
 }
 
-int
+static int
 lnet_match_network_token(char *token, int len, __u32 *ipaddrs, int nip)
 {
        struct list_head list = LIST_HEAD_INIT(list);
@@ -872,154 +872,154 @@ lnet_match_network_token(char *token, int len, __u32 *ipaddrs, int nip)
        for (rc = i = 0; !rc && i < nip; i++)
                rc = cfs_ip_addr_match(ipaddrs[i], &list);
 
-       cfs_ip_addr_free(&list);
+       cfs_expr_list_free_list(&list);
 
-        return rc;
+       return rc;
 }
 
-int
+static int
 lnet_match_network_tokens(char *net_entry, __u32 *ipaddrs, int nip)
 {
-        static char tokens[LNET_SINGLE_TEXTBUF_NOB];
-
-        int   matched = 0;
-        int   ntokens = 0;
-        int   len;
-        char *net = NULL;
-        char *sep;
-        char *token;
-        int   rc;
-
-        LASSERT (strlen(net_entry) < sizeof(tokens));
-
-        /* work on a copy of the string */
-        strcpy(tokens, net_entry);
-        sep = tokens;
-        for (;;) {
-                /* scan for token start */
-                while (cfs_iswhite(*sep))
-                        sep++;
-                if (*sep == 0)
-                        break;
-
-                token = sep++;
-
-                /* scan for token end */
-                while (*sep != 0 && !cfs_iswhite(*sep))
-                        sep++;
-                if (*sep != 0)
-                        *sep++ = 0;
-
-                if (ntokens++ == 0) {
-                        net = token;
-                        continue;
-                }
-
-                len = strlen(token);
+       static char tokens[LNET_SINGLE_TEXTBUF_NOB];
+
+       int   matched = 0;
+       int   ntokens = 0;
+       int   len;
+       char *net = NULL;
+       char *sep;
+       char *token;
+       int   rc;
+
+       LASSERT(strlen(net_entry) < sizeof(tokens));
+
+       /* work on a copy of the string */
+       strcpy(tokens, net_entry);
+       sep = tokens;
+       for (;;) {
+               /* scan for token start */
+               while (isspace(*sep))
+                       sep++;
+               if (*sep == 0)
+                       break;
+
+               token = sep++;
+
+               /* scan for token end */
+               while (*sep != 0 && !isspace(*sep))
+                       sep++;
+               if (*sep != 0)
+                       *sep++ = 0;
+
+               if (ntokens++ == 0) {
+                       net = token;
+                       continue;
+               }
+
+               len = strlen(token);
 
                rc = lnet_match_network_token(token, len, ipaddrs, nip);
-                if (rc < 0) {
-                        lnet_syntax("ip2nets", net_entry,
-                                    (int)(token - tokens), len);
-                        return rc;
-                }
+               if (rc < 0) {
+                       lnet_syntax("ip2nets", net_entry,
+                                   (int)(token - tokens), len);
+                       return rc;
+               }
 
-                matched |= (rc != 0);
-        }
+               matched |= (rc != 0);
+       }
 
-        if (!matched)
-                return 0;
+       if (!matched)
+               return 0;
 
-        strcpy(net_entry, net);                 /* replace with matched net */
-        return 1;
+       strcpy(net_entry, net);                 /* replace with matched net */
+       return 1;
 }
 
-__u32
+static __u32
 lnet_netspec2net(char *netspec)
 {
-        char   *bracket = strchr(netspec, '(');
-        __u32   net;
+       char   *bracket = strchr(netspec, '(');
+       __u32   net;
 
-        if (bracket != NULL)
-                *bracket = 0;
+       if (bracket != NULL)
+               *bracket = 0;
 
-        net = libcfs_str2net(netspec);
+       net = libcfs_str2net(netspec);
 
-        if (bracket != NULL)
-                *bracket = '(';
+       if (bracket != NULL)
+               *bracket = '(';
 
-        return net;
+       return net;
 }
 
-int
+static int
 lnet_splitnets(char *source, struct list_head *nets)
 {
-        int               offset = 0;
-        int               offset2;
-        int               len;
+       int               offset = 0;
+       int               offset2;
+       int               len;
        struct lnet_text_buf  *tb;
        struct lnet_text_buf  *tb2;
        struct list_head *t;
-        char             *sep;
-        char             *bracket;
-        __u32             net;
+       char             *sep;
+       char             *bracket;
+       __u32             net;
 
        LASSERT(!list_empty(nets));
        LASSERT(nets->next == nets->prev);      /* single entry */
 
        tb = list_entry(nets->next, struct lnet_text_buf, ltb_list);
 
-        for (;;) {
-                sep = strchr(tb->ltb_text, ',');
-                bracket = strchr(tb->ltb_text, '(');
+       for (;;) {
+               sep = strchr(tb->ltb_text, ',');
+               bracket = strchr(tb->ltb_text, '(');
 
                if (sep != NULL &&
                    bracket != NULL &&
                    bracket < sep) {
-                        /* netspec lists interfaces... */
+                       /* netspec lists interfaces... */
 
-                        offset2 = offset + (int)(bracket - tb->ltb_text);
-                        len = strlen(bracket);
+                       offset2 = offset + (int)(bracket - tb->ltb_text);
+                       len = strlen(bracket);
 
-                        bracket = strchr(bracket + 1, ')');
+                       bracket = strchr(bracket + 1, ')');
 
-                        if (bracket == NULL ||
-                            !(bracket[1] == ',' || bracket[1] == 0)) {
-                                lnet_syntax("ip2nets", source, offset2, len);
-                                return -EINVAL;
-                        }
+                       if (bracket == NULL ||
+                           !(bracket[1] == ',' || bracket[1] == 0)) {
+                               lnet_syntax("ip2nets", source, offset2, len);
+                               return -EINVAL;
+                       }
 
-                        sep = (bracket[1] == 0) ? NULL : bracket + 1;
-                }
+                       sep = (bracket[1] == 0) ? NULL : bracket + 1;
+               }
 
-                if (sep != NULL)
-                        *sep++ = 0;
+               if (sep != NULL)
+                       *sep++ = 0;
 
-                net = lnet_netspec2net(tb->ltb_text);
-                if (net == LNET_NIDNET(LNET_NID_ANY)) {
-                        lnet_syntax("ip2nets", source, offset,
-                                    strlen(tb->ltb_text));
-                        return -EINVAL;
-                }
+               net = lnet_netspec2net(tb->ltb_text);
+               if (net == LNET_NIDNET(LNET_NID_ANY)) {
+                       lnet_syntax("ip2nets", source, offset,
+                                   strlen(tb->ltb_text));
+                       return -EINVAL;
+               }
 
                list_for_each(t, nets) {
                        tb2 = list_entry(t, struct lnet_text_buf, ltb_list);
 
-                        if (tb2 == tb)
-                                continue;
+                       if (tb2 == tb)
+                               continue;
 
-                        if (net == lnet_netspec2net(tb2->ltb_text)) {
-                                /* duplicate network */
-                                lnet_syntax("ip2nets", source, offset,
-                                            strlen(tb->ltb_text));
-                                return -EINVAL;
-                        }
-                }
+                       if (net == lnet_netspec2net(tb2->ltb_text)) {
+                               /* duplicate network */
+                               lnet_syntax("ip2nets", source, offset,
+                                           strlen(tb->ltb_text));
+                               return -EINVAL;
+                       }
+               }
 
-                if (sep == NULL)
-                        return 0;
+               if (sep == NULL)
+                       return 0;
 
-                offset += (int)(sep - tb->ltb_text);
+               offset += (int)(sep - tb->ltb_text);
                len = strlen(sep);
                tb2 = lnet_new_text_buf(len);
                if (tb2 == NULL)
@@ -1033,7 +1033,7 @@ lnet_splitnets(char *source, struct list_head *nets)
        }
 }
 
-int
+static int
 lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
 {
        static char       networks[LNET_SINGLE_TEXTBUF_NOB];
@@ -1054,18 +1054,18 @@ lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
        int               rc;
 
        INIT_LIST_HEAD(&raw_entries);
-        if (lnet_str2tbs_sep(&raw_entries, ip2nets) < 0) {
-                CERROR("Error parsing ip2nets\n");
-                LASSERT (lnet_tbnob == 0);
-                return -EINVAL;
-        }
+       if (lnet_str2tbs_sep(&raw_entries, ip2nets) < 0) {
+               CERROR("Error parsing ip2nets\n");
+               LASSERT(lnet_tbnob == 0);
+               return -EINVAL;
+       }
 
        INIT_LIST_HEAD(&matched_nets);
        INIT_LIST_HEAD(&current_nets);
-        networks[0] = 0;
-        count = 0;
-        len = 0;
-        rc = 0;
+       networks[0] = 0;
+       count = 0;
+       len = 0;
+       rc = 0;
 
        while (!list_empty(&raw_entries)) {
                tb = list_entry(raw_entries.next, struct lnet_text_buf,
@@ -1074,29 +1074,29 @@ lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
                strncpy(source, tb->ltb_text, sizeof(source));
                source[sizeof(source) - 1] = '\0';
 
-                /* replace ltb_text with the network(s) add on match */
-                rc = lnet_match_network_tokens(tb->ltb_text, ipaddrs, nip);
-                if (rc < 0)
-                        break;
+               /* replace ltb_text with the network(s) add on match */
+               rc = lnet_match_network_tokens(tb->ltb_text, ipaddrs, nip);
+               if (rc < 0)
+                       break;
 
                list_del(&tb->ltb_list);
 
-                if (rc == 0) {                  /* no match */
-                        lnet_free_text_buf(tb);
-                        continue;
-                }
+               if (rc == 0) {                  /* no match */
+                       lnet_free_text_buf(tb);
+                       continue;
+               }
 
-                /* split into separate networks */
+               /* split into separate networks */
                INIT_LIST_HEAD(&current_nets);
                list_add(&tb->ltb_list, &current_nets);
-                rc = lnet_splitnets(source, &current_nets);
-                if (rc < 0)
-                        break;
+               rc = lnet_splitnets(source, &current_nets);
+               if (rc < 0)
+                       break;
 
-                dup = 0;
+               dup = 0;
                list_for_each(t, &current_nets) {
                        tb = list_entry(t, struct lnet_text_buf, ltb_list);
-                        net1 = lnet_netspec2net(tb->ltb_text);
+                       net1 = lnet_netspec2net(tb->ltb_text);
                        LASSERT(net1 != LNET_NIDNET(LNET_NID_ANY));
 
                        list_for_each(t2, &matched_nets) {
@@ -1115,10 +1115,10 @@ lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
                                break;
                }
 
-                if (dup) {
-                        lnet_free_text_bufs(&current_nets);
-                        continue;
-                }
+               if (dup) {
+                       lnet_free_text_bufs(&current_nets);
+                       continue;
+               }
 
                list_for_each_safe(t, t2, &current_nets) {
                        tb = list_entry(t, struct lnet_text_buf, ltb_list);
@@ -1130,215 +1130,133 @@ lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
                                        "%s%s", (len == 0) ? "" : ",",
                                        tb->ltb_text);
 
-                        if (len >= sizeof(networks)) {
-                                CERROR("Too many matched networks\n");
-                                rc = -E2BIG;
-                                goto out;
-                        }
-                }
+                       if (len >= sizeof(networks)) {
+                               CERROR("Too many matched networks\n");
+                               rc = -E2BIG;
+                               goto out;
+                       }
+               }
 
-                count++;
-        }
+               count++;
+       }
 
  out:
-        lnet_free_text_bufs(&raw_entries);
-        lnet_free_text_bufs(&matched_nets);
-        lnet_free_text_bufs(&current_nets);
-        LASSERT (lnet_tbnob == 0);
+       lnet_free_text_bufs(&raw_entries);
+       lnet_free_text_bufs(&matched_nets);
+       lnet_free_text_bufs(&current_nets);
+       LASSERT(lnet_tbnob == 0);
 
-        if (rc < 0)
-                return rc;
+       if (rc < 0)
+               return rc;
 
-        *networksp = networks;
-        return count;
+       *networksp = networks;
+       return count;
 }
 
-#ifdef __KERNEL__
-void
+static void
 lnet_ipaddr_free_enumeration(__u32 *ipaddrs, int nip)
 {
-        LIBCFS_FREE(ipaddrs, nip * sizeof(*ipaddrs));
+       LIBCFS_FREE(ipaddrs, nip * sizeof(*ipaddrs));
 }
 
-int
+static int
 lnet_ipaddr_enumerate (__u32 **ipaddrsp)
 {
-        int        up;
-        __u32      netmask;
-        __u32     *ipaddrs;
-        __u32     *ipaddrs2;
-        int        nip;
-        char     **ifnames;
-        int        nif = libcfs_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);
-                libcfs_ipif_free_enumeration(ifnames, nif);
-                return -ENOMEM;
-        }
-
-        for (i = nip = 0; i < nif; i++) {
-                if (!strcmp(ifnames[i], "lo"))
-                        continue;
-
-                rc = libcfs_ipif_query(ifnames[i], &up,
-                                       &ipaddrs[nip], &netmask);
-                if (rc != 0) {
-                        CWARN("Can't query interface %s: %d\n",
-                              ifnames[i], rc);
-                        continue;
-                }
-
-                if (!up) {
-                        CWARN("Ignoring interface %s: it's down\n",
-                              ifnames[i]);
-                        continue;
-                }
-
-                nip++;
-        }
-
-        libcfs_ipif_free_enumeration(ifnames, nif);
-
-        if (nip == nif) {
-                *ipaddrsp = ipaddrs;
-        } else {
-                if (nip > 0) {
-                        LIBCFS_ALLOC(ipaddrs2, nip * sizeof(*ipaddrs2));
-                        if (ipaddrs2 == NULL) {
-                                CERROR("Can't allocate ipaddrs[%d]\n", nip);
-                                nip = -ENOMEM;
-                        } else {
+       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);
+               return -ENOMEM;
+       }
+
+       for (i = nip = 0; i < nif; i++) {
+               if (!strcmp(ifnames[i], "lo"))
+                       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);
+                       continue;
+               }
+
+               if (!up) {
+                       CWARN("Ignoring interface %s: it's down\n",
+                             ifnames[i]);
+                       continue;
+               }
+
+               nip++;
+       }
+
+       lnet_ipif_free_enumeration(ifnames, nif);
+
+       if (nip == nif) {
+               *ipaddrsp = ipaddrs;
+       } else {
+               if (nip > 0) {
+                       LIBCFS_ALLOC(ipaddrs2, nip * sizeof(*ipaddrs2));
+                       if (ipaddrs2 == NULL) {
+                               CERROR("Can't allocate ipaddrs[%d]\n", nip);
+                               nip = -ENOMEM;
+                       } else {
                                memcpy(ipaddrs2, ipaddrs,
                                        nip * sizeof(*ipaddrs));
-                                *ipaddrsp = ipaddrs2;
-                                rc = nip;
-                        }
-                }
-                lnet_ipaddr_free_enumeration(ipaddrs, nif);
-        }
-        return nip;
+                               *ipaddrsp = ipaddrs2;
+                               rc = nip;
+                       }
+               }
+               lnet_ipaddr_free_enumeration(ipaddrs, nif);
+       }
+       return nip;
 }
 
 int
 lnet_parse_ip2nets (char **networksp, char *ip2nets)
 {
-        __u32     *ipaddrs;
-        int        nip = lnet_ipaddr_enumerate(&ipaddrs);
-        int        rc;
-
-        if (nip < 0) {
-                LCONSOLE_ERROR_MSG(0x117, "Error %d enumerating local IP "
-                                   "interfaces for ip2nets to match\n", nip);
-                return nip;
-        }
-
-        if (nip == 0) {
-                LCONSOLE_ERROR_MSG(0x118, "No local IP interfaces "
-                                   "for ip2nets to match\n");
-                return -ENOENT;
-        }
-
-        rc = lnet_match_networks(networksp, ip2nets, ipaddrs, nip);
-        lnet_ipaddr_free_enumeration(ipaddrs, nip);
-
-        if (rc < 0) {
-                LCONSOLE_ERROR_MSG(0x119, "Error %d parsing ip2nets\n", rc);
-                return rc;
-        }
-
-        if (rc == 0) {
-                LCONSOLE_ERROR_MSG(0x11a, "ip2nets does not match "
-                                   "any local IP interfaces\n");
-                return -ENOENT;
-        }
-
-        return 0;
-}
+       __u32     *ipaddrs = NULL;
+       int        nip = lnet_ipaddr_enumerate(&ipaddrs);
+       int        rc;
+
+       if (nip < 0) {
+               LCONSOLE_ERROR_MSG(0x117, "Error %d enumerating local IP "
+                                  "interfaces for ip2nets to match\n", nip);
+               return nip;
+       }
 
-int
-lnet_set_ip_niaddr (lnet_ni_t *ni)
-{
-        __u32  net = LNET_NIDNET(ni->ni_nid);
-        char **names;
-        int    n;
-        __u32  ip;
-        __u32  netmask;
-        int    up;
-        int    i;
-        int    rc;
-
-        /* Convenience for LNDs that use the IP address of a local interface as
-         * the local address part of their NID */
-
-        if (ni->ni_interfaces[0] != NULL) {
-
-                CLASSERT (LNET_MAX_INTERFACES > 1);
-
-                if (ni->ni_interfaces[1] != NULL) {
-                        CERROR("Net %s doesn't support multiple interfaces\n",
-                               libcfs_net2str(net));
-                        return -EPERM;
-                }
-
-                rc = libcfs_ipif_query(ni->ni_interfaces[0],
-                                       &up, &ip, &netmask);
-                if (rc != 0) {
-                        CERROR("Net %s can't query interface %s: %d\n",
-                               libcfs_net2str(net), ni->ni_interfaces[0], rc);
-                        return -EPERM;
-                }
-
-                if (!up) {
-                        CERROR("Net %s can't use interface %s: it's down\n",
-                               libcfs_net2str(net), ni->ni_interfaces[0]);
-                        return -ENETDOWN;
-                }
-
-                ni->ni_nid = LNET_MKNID(net, ip);
-                return 0;
-        }
-
-        n = libcfs_ipif_enumerate(&names);
-        if (n <= 0) {
-                CERROR("Net %s can't enumerate interfaces: %d\n",
-                       libcfs_net2str(net), n);
-                return 0;
-        }
-
-        for (i = 0; i < n; i++) {
-                if (!strcmp(names[i], "lo")) /* skip the loopback IF */
-                        continue;
-
-                rc = libcfs_ipif_query(names[i], &up, &ip, &netmask);
-
-                if (rc != 0) {
-                        CWARN("Net %s can't query interface %s: %d\n",
-                              libcfs_net2str(net), names[i], rc);
-                        continue;
-                }
-
-                if (!up) {
-                        CWARN("Net %s ignoring interface %s (down)\n",
-                              libcfs_net2str(net), names[i]);
-                        continue;
-                }
-
-                libcfs_ipif_free_enumeration(names, n);
-                ni->ni_nid = LNET_MKNID(net, ip);
-                return 0;
-        }
-
-        CERROR("Net %s can't find any interfaces\n", libcfs_net2str(net));
-        libcfs_ipif_free_enumeration(names, n);
-        return -ENOENT;
-}
-EXPORT_SYMBOL(lnet_set_ip_niaddr);
+       if (nip == 0) {
+               LCONSOLE_ERROR_MSG(0x118, "No local IP interfaces "
+                                  "for ip2nets to match\n");
+               return -ENOENT;
+       }
 
-#endif
+       rc = lnet_match_networks(networksp, ip2nets, ipaddrs, nip);
+       lnet_ipaddr_free_enumeration(ipaddrs, nip);
+
+       if (rc < 0) {
+               LCONSOLE_ERROR_MSG(0x119, "Error %d parsing ip2nets\n", rc);
+               return rc;
+       }
+
+       if (rc == 0) {
+               LCONSOLE_ERROR_MSG(0x11a, "ip2nets does not match "
+                                  "any local IP interfaces\n");
+               return -ENOENT;
+       }
+
+       return 0;
+}