]> git-server-git.apps.pok.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
fsstress: allow multiple suboptions to -f
authorDarrick J. Wong <djwong@kernel.org>
Thu, 4 Dec 2025 21:53:17 +0000 (13:53 -0800)
committerZorro Lang <zlang@kernel.org>
Fri, 5 Dec 2025 06:19:52 +0000 (14:19 +0800)
I got bitten by fsstress's argument parsing recently because it turns
out that if you do:

# fsstress -z -f creat=2,unlink=1

It will ignore everything after the '2' and worse yet it won't tell you
that it's done so unless you happen to pass -S to make it spit out the
frequency table.

Adapt process_freq to tokenize the argument string so that it can handle
a comma-separated list of key-value arguments.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Zorro Lang <zlang@redhat.com>
Signed-off-by: Zorro Lang <zlang@kernel.org>
ltp/fsstress.c

index ae31c6a22d4d930b97e32f1469b9527bdc99e4f6..dfd85db84b53b1f4a5b9ffad806f84e492cee181 100644 (file)
@@ -1781,23 +1781,38 @@ opendir_path(pathname_t *name)
 void
 process_freq(char *arg)
 {
-       opdesc_t        *p;
-       char            *s;
+       char            *token;
+       char            *argstr = strdup(arg);
+       char            *tokstr = argstr ? argstr : arg;
 
-       s = strchr(arg, '=');
-       if (s == NULL) {
-               fprintf(stderr, "bad argument '%s'\n", arg);
-               exit(1);
-       }
-       *s++ = '\0';
-       for (p = ops; p < ops_end; p++) {
-               if (strcmp(arg, p->name) == 0) {
-                       p->freq = atoi(s);
-                       return;
+       while ((token = strtok(tokstr, ",")) != NULL) {
+               opdesc_t        *p = ops;
+               char            *s = strchr(token, '=');
+               int             found = 0;
+
+               if (!s) {
+                       fprintf(stderr, "bad argument '%s'\n", token);
+                       exit(1);
+               }
+
+               *s = '\0';
+               for (; p < ops_end; p++) {
+                       if (strcmp(token, p->name) == 0) {
+                               p->freq = atoi(s + 1);
+                               found = 1;
+                               break;
+                       }
+               }
+
+               if (!found) {
+                       fprintf(stderr, "can't find op type %s for -f\n", token);
+                       exit(1);
                }
+
+               tokstr = NULL;
        }
-       fprintf(stderr, "can't find op type %s for -f\n", arg);
-       exit(1);
+
+       free(argstr);
 }
 
 int