Skip to contentSkip to conversation

fsstress: allow multiple suboptions to -f

PATCH In review Darrick J. Wong 2 participants 2 messages Dec 4, 2025 – Dec 5, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fsstress: allow multiple suboptions to -f

From: Darrick J. Wong <[email protected]>

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.

---
 ltp/fsstress.c |   43 +++++++++++++++++++++++++++++--------------
 1 file changed, 29 insertions(+), 14 deletions(-)
ltp/fsstress.c +29 -14
index 00773cc004bfac..c17ac440414325 100644
@@ -1792,23 +1792,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
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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.

Quoted 5 lines

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

---

Looks and tests good to me, it even works with:
"-f rmdir=10,link=10,creat=10,mkdir=10,rename=30 -f stat=30 -f unlink=30 -f truncate=20"

Quoted 61 lines
 ltp/fsstress.c |   43 +++++++++++++++++++++++++++++--------------
 1 file changed, 29 insertions(+), 14 deletions(-)
ltp/fsstress.c +29 -14
index 00773cc004bfac..c17ac440414325 100644
@@ -1792,23 +1792,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