Whamcloud - gitweb
LU-9859 lnet: simplifiy cfs_ip_addr_parse() 42/50842/9
authorMr NeilBrown <neilb@suse.de>
Tue, 24 Nov 2020 23:10:14 +0000 (10:10 +1100)
committerOleg Drokin <green@whamcloud.com>
Thu, 24 Aug 2023 04:33:07 +0000 (04:33 +0000)
cfs_ip_add_parse() is now always passed a string that it is safe to
modify.  So change the parsing to benefit from this and use standard
tools like strsep().

Note that the 'len' argument is now ignored.  It cannot be removed
without a larger change.

Test-Parameters: trivial testlist=sanity-lnet
Signed-off-by: Mr NeilBrown <neilb@suse.de>
Change-Id: Ice492edf109dca2e411132b891514f0caa535d8c
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50842
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Frank Sehr <fsehr@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Chris Horn <chris.horn@hpe.com>
lnet/lnet/config.c
lnet/lnet/nidstrings.c

index cfa55c4..d5eb3ed 100644 (file)
@@ -1247,13 +1247,13 @@ lnet_parse_routes(const char *routes, int *im_a_router)
 }
 
 static int
-lnet_match_network_token(char *token, int len, __u32 *ipaddrs, int nip)
+lnet_match_network_token(char *token, __u32 *ipaddrs, int nip)
 {
        LIST_HEAD(list);
        int             rc;
        int             i;
 
-       rc = cfs_ip_addr_parse(token, len, &list);
+       rc = cfs_ip_addr_parse(token, 0, &list);
        if (rc != 0)
                return rc;
 
@@ -1272,7 +1272,6 @@ lnet_match_network_tokens(char *net_entry, __u32 *ipaddrs, int nip)
 
        int   matched = 0;
        int   ntokens = 0;
-       int   len;
        char *net = NULL;
        char *sep;
        char *token;
@@ -1283,32 +1282,23 @@ lnet_match_network_tokens(char *net_entry, __u32 *ipaddrs, int nip)
        /* work on a copy of the string */
        strcpy(tokens, net_entry);
        sep = tokens;
-       for (;;) {
+       while (sep) {
                /* scan for token start */
-               while (isspace(*sep))
-                       sep++;
+               sep = skip_spaces(sep);
                if (*sep == 0)
                        break;
 
-               token = sep++;
-
-               /* scan for token end */
-               while (*sep != 0 && !isspace(*sep))
-                       sep++;
-               if (*sep != 0)
-                       *sep++ = 0;
+               token = strsep(&sep, " \t\n\r\v\f");
 
                if (ntokens++ == 0) {
                        net = token;
                        continue;
                }
 
-               len = strlen(token);
-
-               rc = lnet_match_network_token(token, len, ipaddrs, nip);
+               rc = lnet_match_network_token(token, ipaddrs, nip);
                if (rc < 0) {
                        lnet_syntax("ip2nets", net_entry,
-                                   (int)(token - tokens), len);
+                                   (int)(token - tokens), strlen(token));
                        return rc;
                }
 
index ae28f92..3c822a4 100644 (file)
@@ -552,41 +552,32 @@ libcfs_ip_str2addr_size(const char *str, int nob,
 
 /* Used by lnet/config.c so it can't be static */
 int
-cfs_ip_addr_parse(char *str, int len, struct list_head *list)
+cfs_ip_addr_parse(char *str, int len_ignored, struct list_head *list)
 {
        struct cfs_expr_list *el;
-       struct cfs_lstr src;
-       int rc;
-       int i;
-
-       src.ls_str = str;
-       src.ls_len = len;
-       i = 0;
+       int rc = 0;
+       int i = 0;
 
-       while (src.ls_str != NULL) {
-               struct cfs_lstr res;
+       str = strim(str);
+       while (rc == 0 && str) {
+               char *res;
 
-               if (!cfs_gettok(&src, '.', &res)) {
+               res = strsep(&str, ".");
+               res = strim(res);
+               if (!*res) {
                        rc = -EINVAL;
-                       goto out;
+               } else if ((rc = cfs_expr_list_parse(res, strlen(res),
+                                                  0, 255, &el)) == 0) {
+                       list_add_tail(&el->el_link, list);
+                       i++;
                }
-
-               rc = cfs_expr_list_parse(res.ls_str, res.ls_len, 0, 255, &el);
-               if (rc != 0)
-                       goto out;
-
-               list_add_tail(&el->el_link, list);
-               i++;
        }
 
-       if (i == 4)
+       if (rc == 0 && i == 4)
                return 0;
-
-       rc = -EINVAL;
-out:
        cfs_expr_list_free_list(list);
 
-       return rc;
+       return rc ?: -EINVAL;
 }
 
 /**