Whamcloud - gitweb
LU-5829 lnet: remove unnecessary EXPORT_SYMBOL
[fs/lustre-release.git] / lnet / lnet / config.c
index 345dd26..a40f17b 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, Intel Corporation.
+ * Copyright (c) 2012, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -48,7 +48,7 @@ static int lnet_tbnob = 0;                    /* track text buf 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];
@@ -65,7 +65,7 @@ lnet_syntax(char *name, char *str, int offset, int width)
                             (width < 1) ? 0 : width - 1, dashes);
 }
 
-int
+static int
 lnet_issep (char c)
 {
        switch (c) {
@@ -97,6 +97,8 @@ lnet_net_unique(__u32 net, struct list_head *nilist)
 void
 lnet_ni_free(struct lnet_ni *ni)
 {
+       int i;
+
        if (ni->ni_refs != NULL)
                cfs_percpt_free(ni->ni_refs);
 
@@ -106,11 +108,11 @@ 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
+       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);
+       }
        LIBCFS_FREE(ni, sizeof(*ni));
 }
 
@@ -135,13 +137,7 @@ lnet_ni_alloc(__u32 net, struct cfs_expr_list *el, struct list_head *nilist)
                 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]));
@@ -190,13 +186,19 @@ int
 lnet_parse_networks(struct list_head *nilist, char *networks)
 {
        struct cfs_expr_list *el = NULL;
-       int             tokensize = strlen(networks) + 1;
+       int             tokensize;
        char            *tokens;
        char            *str;
        char            *tmp;
        struct lnet_ni  *ni;
        __u32           net;
        int             nnets = 0;
+       struct list_head *temp_node;
+
+       if (networks == NULL) {
+               CERROR("networks string is undefined\n");
+               return -EINVAL;
+       }
 
        if (strlen(networks) > LNET_SINGLE_TEXTBUF_NOB) {
                /* _WAY_ conservative */
@@ -205,22 +207,17 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
                return -EINVAL;
        }
 
-        LIBCFS_ALLOC(tokens, tokensize);
-        if (tokens == NULL) {
-                CERROR("Can't allocate net tokens\n");
+       tokensize = strlen(networks) + 1;
+
+       LIBCFS_ALLOC(tokens, tokensize);
+       if (tokens == NULL) {
+               CERROR("Can't allocate net tokens\n");
                return -ENOMEM;
-        }
+       }
 
-        the_lnet.ln_network_tokens = tokens;
-        the_lnet.ln_network_tokens_nob = tokensize;
-        memcpy (tokens, networks, tokensize);
+       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, '(');
@@ -293,7 +290,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;
@@ -324,14 +320,28 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
                                goto failed_syntax;
                         }
 
-                        if (niface == LNET_MAX_INTERFACES) {
-                                LCONSOLE_ERROR_MSG(0x115, "Too many interfaces "
-                                                   "for net %s\n",
-                                                   libcfs_net2str(net));
-                                goto failed;
-                        }
+                       if (niface == LNET_MAX_INTERFACES) {
+                               LCONSOLE_ERROR_MSG(0x115, "Too many interfaces "
+                                                  "for net %s\n",
+                                                  libcfs_net2str(net));
+                               goto failed;
+                       }
 
-                        ni->ni_interfaces[niface++] = iface;
+                       /* Allocate a seperate 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.
+                        * The newly allocated ni_interfaces[] can be
+                        * freed when freeing the NI */
+                       LIBCFS_ALLOC(ni->ni_interfaces[niface],
+                                    strlen(iface) + 1);
+                       if (ni->ni_interfaces[niface] == NULL) {
+                               CERROR("Can't allocate net interface name\n");
+                               goto failed;
+                       }
+                       strncpy(ni->ni_interfaces[niface], iface,
+                               strlen(iface));
+                       niface++;
                        iface = comma;
                } while (iface != NULL);
 
@@ -355,8 +365,11 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
                }
        }
 
-       LASSERT(!list_empty(nilist));
-       return 0;
+       list_for_each(temp_node, nilist)
+               nnets++;
+
+       LIBCFS_FREE(tokens, tokensize);
+       return nnets;
 
  failed_syntax:
        lnet_syntax("networks", networks, (int)(tmp - tokens), strlen(tmp));
@@ -372,12 +385,11 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
                cfs_expr_list_free(el);
 
        LIBCFS_FREE(tokens, tokensize);
-       the_lnet.ln_network_tokens = NULL;
 
        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;
@@ -405,14 +417,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;
@@ -440,7 +452,7 @@ 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;
@@ -498,7 +510,7 @@ 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)
@@ -523,7 +535,7 @@ lnet_expand1tb(struct list_head *list,
        return 0;
 }
 
-int
+static int
 lnet_str2tbs_expand(struct list_head *tbs, char *str)
 {
        char              num[16];
@@ -603,7 +615,7 @@ lnet_str2tbs_expand(struct list_head *tbs, char *str)
        return -1;
 }
 
-int
+static int
 lnet_parse_hops (char *str, unsigned int *hops)
 {
         int     len = strlen(str);
@@ -616,7 +628,7 @@ lnet_parse_hops (char *str, unsigned int *hops)
 
 #define LNET_PRIORITY_SEPARATOR (':')
 
-int
+static int
 lnet_parse_priority(char *str, unsigned int *priority, char **token)
 {
        int   nob;
@@ -646,7 +658,7 @@ 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) */
@@ -663,9 +675,9 @@ lnet_parse_route (char *str, int *im_a_router)
        char             *sep;
        char             *token = str;
        int               ntokens = 0;
-        int               myrc = -1;
-        unsigned int      hops;
-        int               got_hops = 0;
+       int               myrc = -1;
+       unsigned int      hops;
+       int               got_hops = 0;
        unsigned int      priority = 0;
 
        INIT_LIST_HEAD(&gateways);
@@ -747,8 +759,8 @@ lnet_parse_route (char *str, int *im_a_router)
                }
        }
 
-        if (!got_hops)
-                hops = 1;
+       if (!got_hops)
+               hops = 1;
 
        LASSERT(!list_empty(&nets));
        LASSERT(!list_empty(&gateways));
@@ -763,34 +775,34 @@ lnet_parse_route (char *str, int *im_a_router)
                        nid = libcfs_str2nid(ltb->ltb_text);
                        LASSERT(nid != LNET_NID_ANY);
 
-                        if (lnet_islocalnid(nid)) {
-                                *im_a_router = 1;
-                                continue;
-                        }
+                       if (lnet_islocalnid(nid)) {
+                               *im_a_router = 1;
+                               continue;
+                       }
 
                        rc = lnet_add_route(net, hops, nid, priority);
-                        if (rc != 0) {
-                                CERROR("Can't create route "
-                                       "to %s via %s\n",
-                                       libcfs_net2str(net),
-                                       libcfs_nid2str(nid));
-                                goto out;
-                        }
+                       if (rc != 0 && rc != -EEXIST && rc != -EHOSTUNREACH) {
+                               CERROR("Can't create route "
+                                      "to %s via %s\n",
+                                      libcfs_net2str(net),
+                                      libcfs_nid2str(nid));
+                               goto out;
+                       }
                }
        }
 
-        myrc = 0;
-        goto out;
+       myrc = 0;
+       goto out;
 
- token_error:
+token_error:
        lnet_syntax("routes", cmd, (int)(token - str), strlen(token));
- out:
+out:
        lnet_free_text_bufs(&nets);
        lnet_free_text_bufs(&gateways);
        return myrc;
 }
 
-int
+static int
 lnet_parse_route_tbs(struct list_head *tbs, int *im_a_router)
 {
        struct lnet_text_buf   *ltb;
@@ -831,7 +843,7 @@ lnet_parse_routes (char *routes, int *im_a_router)
        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);
@@ -850,7 +862,7 @@ lnet_match_network_token(char *token, int len, __u32 *ipaddrs, int nip)
         return rc;
 }
 
-int
+static int
 lnet_match_network_tokens(char *net_entry, __u32 *ipaddrs, int nip)
 {
         static char tokens[LNET_SINGLE_TEXTBUF_NOB];
@@ -907,7 +919,7 @@ lnet_match_network_tokens(char *net_entry, __u32 *ipaddrs, int nip)
         return 1;
 }
 
-__u32
+static __u32
 lnet_netspec2net(char *netspec)
 {
         char   *bracket = strchr(netspec, '(');
@@ -924,7 +936,7 @@ lnet_netspec2net(char *netspec)
         return net;
 }
 
-int
+static int
 lnet_splitnets(char *source, struct list_head *nets)
 {
         int               offset = 0;
@@ -1006,7 +1018,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];
@@ -1126,14 +1138,13 @@ lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
         return count;
 }
 
-#ifdef __KERNEL__
-void
+static void
 lnet_ipaddr_free_enumeration(__u32 *ipaddrs, int nip)
 {
         LIBCFS_FREE(ipaddrs, nip * sizeof(*ipaddrs));
 }
 
-int
+static int
 lnet_ipaddr_enumerate (__u32 **ipaddrsp)
 {
         int        up;
@@ -1202,7 +1213,7 @@ lnet_ipaddr_enumerate (__u32 **ipaddrsp)
 int
 lnet_parse_ip2nets (char **networksp, char *ip2nets)
 {
-        __u32     *ipaddrs;
+       __u32     *ipaddrs = NULL;
         int        nip = lnet_ipaddr_enumerate(&ipaddrs);
         int        rc;
 
@@ -1234,84 +1245,3 @@ lnet_parse_ip2nets (char **networksp, char *ip2nets)
 
         return 0;
 }
-
-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);
-
-#endif