From c6e9a5d02936a215aa01021eab6d8827ceb6b19d Mon Sep 17 00:00:00 2001 From: Chris Horn Date: Sun, 14 Jul 2019 13:57:56 -0500 Subject: [PATCH] LU-12410 lnet: Implement method to tokenize nidstrings 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 Change-Id: I2f8ab6d5d9e7c3d5bde3a11b85bdf38fbf6fdf29 Reviewed-on: https://review.whamcloud.com/35505 Reviewed-by: Shaun Tancheff Tested-by: jenkins Tested-by: Maloo Reviewed-by: Petros Koutoupis Reviewed-by: Oleg Drokin --- lnet/utils/lnetconfig/liblnetconfig.c | 51 +++++++++++++++++++++++++++++++++++ lnet/utils/lnetconfig/liblnetconfig.h | 2 ++ 2 files changed, 53 insertions(+) diff --git a/lnet/utils/lnetconfig/liblnetconfig.c b/lnet/utils/lnetconfig/liblnetconfig.c index ac48ec3..9f77bc9 100644 --- a/lnet/utils/lnetconfig/liblnetconfig.c +++ b/lnet/utils/lnetconfig/liblnetconfig.c @@ -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) { diff --git a/lnet/utils/lnetconfig/liblnetconfig.h b/lnet/utils/lnetconfig/liblnetconfig.h index 3e4334b..5c5fb6a 100644 --- a/lnet/utils/lnetconfig/liblnetconfig.h +++ b/lnet/utils/lnetconfig/liblnetconfig.h @@ -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 -- 1.8.3.1