Whamcloud - gitweb
LU-6245 libcfs: create userland and kernel string operations
[fs/lustre-release.git] / lnet / lnet / config.c
index 446eb8a..1b8fc3c 100644 (file)
@@ -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]));
@@ -477,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 */
@@ -494,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];
@@ -701,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))
@@ -713,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;
@@ -868,7 +857,7 @@ 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;
 }
@@ -893,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;
@@ -901,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;
@@ -1149,7 +1138,6 @@ lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
         return count;
 }
 
-#ifdef __KERNEL__
 static void
 lnet_ipaddr_free_enumeration(__u32 *ipaddrs, int nip)
 {
@@ -1165,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;
 
@@ -1175,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;
         }
 
@@ -1183,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",
@@ -1200,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;
@@ -1257,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