Whamcloud - gitweb
LU-6245 libcfs: create userland and kernel string operations
[fs/lustre-release.git] / lnet / lnet / config.c
index 6cc64be..1b8fc3c 100644 (file)
@@ -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) {
@@ -108,11 +108,6 @@ 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],
@@ -142,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]));
@@ -204,6 +193,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");
@@ -228,11 +218,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, '(');
@@ -305,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;
@@ -381,10 +365,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 +389,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 +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;
@@ -467,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;
@@ -481,7 +466,7 @@ lnet_str2tbs_sep(struct list_head *tbs, char *str)
        /* Split 'str' into separate commands */
        for (;;) {
                 /* skip leading whitespace */
-                while (cfs_iswhite(*str))
+               while (isspace(*str))
                         str++;
 
                /* scan for separator or comment */
@@ -498,7 +483,7 @@ lnet_str2tbs_sep(struct list_head *tbs, char *str)
                        }
 
                         for (i = 0; i < nob; i++)
-                                if (cfs_iswhite(str[i]))
+                               if (isspace(str[i]))
                                         ltb->ltb_text[i] = ' ';
                                 else
                                         ltb->ltb_text[i] = str[i];
@@ -525,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)
@@ -550,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];
@@ -630,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);
@@ -643,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;
@@ -673,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) */
@@ -705,7 +690,7 @@ 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))
@@ -717,7 +702,7 @@ 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;
@@ -796,7 +781,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 +802,7 @@ out:
        return myrc;
 }
 
-int
+static int
 lnet_parse_route_tbs(struct list_head *tbs, int *im_a_router)
 {
        struct lnet_text_buf   *ltb;
@@ -858,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);
@@ -872,12 +857,12 @@ 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;
 }
 
-int
+static int
 lnet_match_network_tokens(char *net_entry, __u32 *ipaddrs, int nip)
 {
         static char tokens[LNET_SINGLE_TEXTBUF_NOB];
@@ -897,7 +882,7 @@ lnet_match_network_tokens(char *net_entry, __u32 *ipaddrs, int nip)
         sep = tokens;
         for (;;) {
                 /* scan for token start */
-                while (cfs_iswhite(*sep))
+               while (isspace(*sep))
                         sep++;
                 if (*sep == 0)
                         break;
@@ -905,7 +890,7 @@ lnet_match_network_tokens(char *net_entry, __u32 *ipaddrs, int nip)
                 token = sep++;
 
                 /* scan for token end */
-                while (*sep != 0 && !cfs_iswhite(*sep))
+               while (*sep != 0 && !isspace(*sep))
                         sep++;
                 if (*sep != 0)
                         *sep++ = 0;
@@ -934,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, '(');
@@ -951,7 +936,7 @@ lnet_netspec2net(char *netspec)
         return net;
 }
 
-int
+static int
 lnet_splitnets(char *source, struct list_head *nets)
 {
         int               offset = 0;
@@ -1033,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];
@@ -1153,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;
@@ -1169,7 +1153,7 @@ lnet_ipaddr_enumerate (__u32 **ipaddrsp)
         __u32     *ipaddrs2;
         int        nip;
         char     **ifnames;
-        int        nif = libcfs_ipif_enumerate(&ifnames);
+       int        nif = lnet_ipif_enumerate(&ifnames);
         int        i;
         int        rc;
 
@@ -1179,7 +1163,7 @@ lnet_ipaddr_enumerate (__u32 **ipaddrsp)
         LIBCFS_ALLOC(ipaddrs, nif * sizeof(*ipaddrs));
         if (ipaddrs == NULL) {
                 CERROR("Can't allocate ipaddrs[%d]\n", nif);
-                libcfs_ipif_free_enumeration(ifnames, nif);
+               lnet_ipif_free_enumeration(ifnames, nif);
                 return -ENOMEM;
         }
 
@@ -1187,7 +1171,7 @@ lnet_ipaddr_enumerate (__u32 **ipaddrsp)
                 if (!strcmp(ifnames[i], "lo"))
                         continue;
 
-                rc = libcfs_ipif_query(ifnames[i], &up,
+               rc = lnet_ipif_query(ifnames[i], &up,
                                        &ipaddrs[nip], &netmask);
                 if (rc != 0) {
                         CWARN("Can't query interface %s: %d\n",
@@ -1204,7 +1188,7 @@ lnet_ipaddr_enumerate (__u32 **ipaddrsp)
                 nip++;
         }
 
-        libcfs_ipif_free_enumeration(ifnames, nif);
+       lnet_ipif_free_enumeration(ifnames, nif);
 
         if (nip == nif) {
                 *ipaddrsp = ipaddrs;
@@ -1229,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;
 
@@ -1261,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