From: Mr NeilBrown Date: Wed, 19 Jul 2023 18:15:57 +0000 (-0400) Subject: LU-9859 ptlrpc: simplify nrs_tbf_opcode_list_parse() X-Git-Tag: 2.15.58~102 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=refs%2Fchanges%2F37%2F50837%2F13;p=fs%2Flustre-release.git LU-9859 ptlrpc: simplify nrs_tbf_opcode_list_parse() If nrs_tbf_opcode_list_parse() duplicates the string it is passed, it can use standard mutating functions for parsing the string. Test-Parameters: trivial Test-Parameters: testlist=sanityn Test-Parameters: testlist=sanity Signed-off-by: Mr NeilBrown Change-Id: I4acb57de52abde97fa9c2d133cf10a432b12f604 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50837 Tested-by: jenkins Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Arshad Hussain Reviewed-by: Etienne AUJAMES Reviewed-by: Nathaniel Clark Reviewed-by: Oleg Drokin --- diff --git a/lustre/ptlrpc/nrs_tbf.c b/lustre/ptlrpc/nrs_tbf.c index 5b66dd9..4ed0a66 100644 --- a/lustre/ptlrpc/nrs_tbf.c +++ b/lustre/ptlrpc/nrs_tbf.c @@ -1821,7 +1821,7 @@ nrs_tbf_generic_cmd_fini(struct nrs_tbf_cmd *cmd) #define NRS_TBF_EXPRESSION_DELIM ("=") static int -nrs_tbf_opcode_list_parse(char *str, int len, unsigned long **bitmaptr); +nrs_tbf_opcode_list_parse(char *str, unsigned long **bitmaptr); static int nrs_tbf_id_list_parse(char *str, struct list_head *id_list, enum nrs_tbf_flag tif); @@ -1862,7 +1862,7 @@ nrs_tbf_expression_parse(char *str, struct list_head *cond_list) GOTO(out, rc = -EINVAL); expr->te_field = NRS_TBF_FIELD_JOBID; } else if (strcmp(field, "opcode") == 0) { - if (nrs_tbf_opcode_list_parse(str, len, &expr->te_opcodes) < 0) + if (nrs_tbf_opcode_list_parse(str, &expr->te_opcodes) < 0) GOTO(out, rc = -EINVAL); expr->te_field = NRS_TBF_FIELD_OPCODE; } else if (strcmp(field, "uid") == 0) { @@ -2204,18 +2204,11 @@ nrs_tbf_opcode_cli_init(struct nrs_tbf_client *cli, #define MAX_OPCODE_LEN 32 static int -nrs_tbf_opcode_set_bit(const struct cfs_lstr *id, unsigned long *opcodes) +nrs_tbf_opcode_set_bit(char *id, unsigned long *opcodes) { - int op = 0; - char opcode_str[MAX_OPCODE_LEN]; + int op; - if (id->ls_len + 1 > MAX_OPCODE_LEN) - return -EINVAL; - - memcpy(opcode_str, id->ls_str, id->ls_len); - opcode_str[id->ls_len] = '\0'; - - op = ll_str2opcode(opcode_str); + op = ll_str2opcode(id); if (op < 0) return -EINVAL; @@ -2224,31 +2217,35 @@ nrs_tbf_opcode_set_bit(const struct cfs_lstr *id, unsigned long *opcodes) } static int -nrs_tbf_opcode_list_parse(char *str, int len, unsigned long **bitmaptr) +nrs_tbf_opcode_list_parse(char *orig, unsigned long **bitmaptr) { unsigned long *opcodes; - struct cfs_lstr src; - struct cfs_lstr res; + char *str; + int cnt = 0; int rc = 0; ENTRY; + orig = kstrdup(orig, GFP_KERNEL); + if (!orig) + return -ENOMEM; opcodes = bitmap_zalloc(LUSTRE_MAX_OPCODES, GFP_KERNEL); - if (!opcodes) + if (!opcodes) { + kfree(orig); return -ENOMEM; + } + str = orig; + while (str && rc == 0) { + char *tok = strsep(&str, " "); - src.ls_str = str; - src.ls_len = len; - while (src.ls_str) { - rc = cfs_gettok(&src, ' ', &res); - if (rc == 0) { - rc = -EINVAL; - break; + if (*tok) { + rc = nrs_tbf_opcode_set_bit(tok, opcodes); + cnt += 1; } - rc = nrs_tbf_opcode_set_bit(&res, opcodes); - if (rc) - break; } + if (cnt == 0) + rc = -EINVAL; + kfree(orig); if (rc == 0 && bitmaptr) *bitmaptr = opcodes; else @@ -2280,9 +2277,7 @@ static int nrs_tbf_opcode_parse(struct nrs_tbf_cmd *cmd, char *id) strcpy(cmd->u.tc_start.ts_opcodes_str, id); /* parse opcode list */ - rc = nrs_tbf_opcode_list_parse(cmd->u.tc_start.ts_opcodes_str, - strlen(cmd->u.tc_start.ts_opcodes_str), - NULL); + rc = nrs_tbf_opcode_list_parse(cmd->u.tc_start.ts_opcodes_str, NULL); if (rc) nrs_tbf_opcode_cmd_fini(cmd); @@ -2319,7 +2314,6 @@ static int nrs_tbf_opcode_rule_init(struct ptlrpc_nrs_policy *policy, return 0; rc = nrs_tbf_opcode_list_parse(rule->tr_opcodes_str, - strlen(rule->tr_opcodes_str), &rule->tr_opcodes); if (rc) OBD_FREE(rule->tr_opcodes_str,