Whamcloud - gitweb
LU-12410 lnet: Implement method to tokenize nidstrings 05/35505/11
authorChris Horn <hornc@cray.com>
Sun, 14 Jul 2019 18:57:56 +0000 (13:57 -0500)
committerOleg Drokin <green@whamcloud.com>
Fri, 3 Jan 2020 00:08:40 +0000 (00:08 +0000)
The CLI for various lnetctl operations allows the user to specify
multiple, comma separated nidstrings. Implement a common method
for tokenizing nidstrings that can be leveraged by the operations
that require it.

Test-Parameters: trivial
Signed-off-by: Chris Horn <hornc@cray.com>
Change-Id: I2f8ab6d5d9e7c3d5bde3a11b85bdf38fbf6fdf29
Reviewed-on: https://review.whamcloud.com/35505
Reviewed-by: Shaun Tancheff <stancheff@cray.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Petros Koutoupis <pkoutoupis@cray.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lnet/utils/lnetconfig/liblnetconfig.c
lnet/utils/lnetconfig/liblnetconfig.h

index ac48ec3..9f77bc9 100644 (file)
@@ -262,6 +262,57 @@ static char *get_next_delimiter_in_nid(char *str, char sep)
        return comma;
 }
 
+int tokenize_nidstr(char *nidstr, char *out[LNET_MAX_STR_LEN], char *err_str)
+{
+       int bracket = 0, num_str = 0;
+       char *strstart, *chptr;
+
+       if (!nidstr) {
+               snprintf(err_str, LNET_MAX_STR_LEN, "supplied nidstr is NULL");
+               return LUSTRE_CFG_RC_BAD_PARAM;
+       }
+
+       /* comma-separated nidranges -> space-separated nidranges */
+       chptr = &nidstr[0];
+       strstart = chptr;
+       while (true) {
+               if (*chptr == '\0') {
+                       out[num_str] = strstart;
+                       num_str++;
+                       break;
+               }
+
+               if (*chptr == '[')
+                       bracket++;
+               else if (*chptr == ']')
+                       bracket--;
+
+               if (bracket < 0) {
+                       snprintf(err_str, LNET_MAX_STR_LEN,
+                                "Mismatched brackets in nidstring \"%s\"",
+                                nidstr);
+                       return LUSTRE_CFG_RC_BAD_PARAM;
+               }
+
+               if (bracket == 0 && *chptr == ',') {
+                       out[num_str] = strstart;
+                       *chptr = '\0';
+                       num_str++;
+                       strstart = chptr + 1;
+               }
+
+               chptr++;
+       }
+
+       if (bracket != 0) {
+               snprintf(err_str, LNET_MAX_STR_LEN,
+                        "Mismatched brackets in nidstring \"%s\"", nidstr);
+               return LUSTRE_CFG_RC_BAD_PARAM;
+       }
+
+       return num_str;
+}
+
 int lustre_lnet_parse_nidstr(char *nidstr, lnet_nid_t *lnet_nidlist,
                             int max_nids, char *err_str)
 {
index 3e4334b..5c5fb6a 100644 (file)
@@ -69,6 +69,8 @@ struct lnet_dlc_intf_descr {
 /* forward declaration of the cYAML structure. */
 struct cYAML;
 
+int tokenize_nidstr(char *nidstr, char *out[LNET_MAX_STR_LEN], char *err_str);
+
 /*
  * lustre_lnet_config_lib_init()
  *   Initialize the Library to enable communication with the LNET kernel