Skip to contentSkip to conversation

ltp/fsstress: check mkdir(2) return value

PATCH In review Xiong Zhou 2 participants 3 messages Oct 14, 2017 – Oct 24, 2017

lore
Share & tools
lore

Xiong Zhou

author
#0 lore raw

PATCH 1/1 ltp/fsstress: check mkdir(2) return value

If mkdir(2) fails, the following chdir(2) would fail either. Although dirname and error message are printed, we don't know which operation has failed.

Like this:
+/test2/fsstress.1582: No such file or directory

This trivial fix will check the return value and print detail error info if fail.

---
 ltp/fsstress.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
ltp/fsstress.c +12 -3
index 96f48b1..1962d14 100644
@@ -493,7 +493,11 @@ int main(int argc, char **argv)
             exit(1);
         }
 
-	(void)mkdir(dirname, 0777);
+	if (mkdir((const char *)dirname, 0777) < 0) {
+		fprintf(stderr, "mkdir %s failed: %s\n", dirname,
+			strerror(errno));
+		exit(1);
+	}
 	if (logname && logname[0] != '/') {
 		if (getcwd(rpath, sizeof(rpath)) < 0){
 			perror("getcwd failed");
@@ -503,7 +507,8 @@ int main(int argc, char **argv)
 		rpath[0] = '\0';
 	}
 	if (chdir(dirname) < 0) {
-		perror(dirname);
+		fprintf(stderr, "chdir %s failed: %s\n", dirname,
+			strerror(errno));
 		exit(1);
 	}
 	if (logname) {
@@ -959,7 +964,11 @@ doproc(void)
 
 	dividend = (operations + execute_freq) / (execute_freq + 1);
 	sprintf(buf, "p%x", procid);
-	(void)mkdir(buf, 0777);
+	if (mkdir((const char *)buf, 0777) < 0) {
+		fprintf(stderr, "mkdir %s failed: %s\n", buf,
+			strerror(errno));
+		exit(1);
+	}
 	if (chdir(buf) < 0 || stat64(".", &statbuf) < 0) {
 		perror(buf);
 		_exit(1);
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 20 lines · Xiong Zhou

If mkdir(2) fails, the following chdir(2) would fail either. Although dirname and error message are printed, we don't know which operation has failed.

Like this:
+/test2/fsstress.1582: No such file or directory

This trivial fix will check the return value and print detail error info if fail.

---
 ltp/fsstress.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
ltp/fsstress.c +0 -0
index 96f48b1..1962d14 100644

ltp/fsstress.c int main(int argc, char **argv) · line 500

Quoted 9 lines
ltp/fsstress.c +5 -1
@@ -493,7 +493,11 @@ int main(int argc, char **argv)
             exit(1);
         }
 
-	(void)mkdir(dirname, 0777);
+	if (mkdir((const char *)dirname, 0777) < 0) {
+		fprintf(stderr, "mkdir %s failed: %s\n", dirname,
+			strerror(errno));
+		exit(1);
+	}

This changed current fsstress behavior and made some tests fail, e.g. generic/013, because fsstress exited with EEXIST if there was a pre-created test dir. e.g.

mkdir /mnt/test/fsstress
./ltp/fsstress -d /mnt/test/fsstress -n 10 -p 10 -v mkdir /mnt/test/fsstress failed: File exists

Quoted 14 lines
ltp/fsstress.c +2 -1
 	if (logname && logname[0] != '/') {
 		if (getcwd(rpath, sizeof(rpath)) < 0){
 			perror("getcwd failed");
@@ -503,7 +507,8 @@ int main(int argc, char **argv)
 		rpath[0] = '\0';
 	}
 	if (chdir(dirname) < 0) {
-		perror(dirname);
+		fprintf(stderr, "chdir %s failed: %s\n", dirname,
+			strerror(errno));
 		exit(1);
 	}
 	if (logname) {

ltp/fsstress.c doproc(void) · line 971

Quoted 9 lines
ltp/fsstress.c +5 -1
@@ -959,7 +964,11 @@ doproc(void)
 
 	dividend = (operations + execute_freq) / (execute_freq + 1);
 	sprintf(buf, "p%x", procid);
-	(void)mkdir(buf, 0777);
+	if (mkdir((const char *)buf, 0777) < 0) {
+		fprintf(stderr, "mkdir %s failed: %s\n", buf,
+			strerror(errno));
+		exit(1);
+	}

Same here.

Thanks,
Eryu

Quoted 10 lines
ltp/fsstress.c +0 -0
 	if (chdir(buf) < 0 || stat64(".", &statbuf) < 0) {
 		perror(buf);
 		_exit(1);
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe fstests" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#2 lore raw
Quoted 35 lines · Eryu Guan
Quoted 20 lines · Xiong Zhou

If mkdir(2) fails, the following chdir(2) would fail either. Although dirname and error message are printed, we don't know which operation has failed.

Like this:
+/test2/fsstress.1582: No such file or directory

This trivial fix will check the return value and print detail error info if fail.

---
 ltp/fsstress.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
ltp/fsstress.c +0 -0
index 96f48b1..1962d14 100644

ltp/fsstress.c int main(int argc, char **argv) · line 500

Quoted 9 lines
ltp/fsstress.c +5 -1
@@ -493,7 +493,11 @@ int main(int argc, char **argv)
             exit(1);
         }
 
-	(void)mkdir(dirname, 0777);
+	if (mkdir((const char *)dirname, 0777) < 0) {
+		fprintf(stderr, "mkdir %s failed: %s\n", dirname,
+			strerror(errno));
+		exit(1);
+	}

This changed current fsstress behavior and made some tests fail, e.g. generic/013, because fsstress exited with EEXIST if there was a pre-created test dir. e.g.

Quoted 3 lines

mkdir /mnt/test/fsstress
./ltp/fsstress -d /mnt/test/fsstress -n 10 -p 10 -v mkdir /mnt/test/fsstress failed: File exists

hmm.. Please forget this thread.

Thanks,
Xiong

Quoted 44 lines
Quoted 15 lines
ltp/fsstress.c +2 -1
 	if (logname && logname[0] != '/') {
 		if (getcwd(rpath, sizeof(rpath)) < 0){
 			perror("getcwd failed");
@@ -503,7 +507,8 @@ int main(int argc, char **argv)
 		rpath[0] = '\0';
 	}
 	if (chdir(dirname) < 0) {
-		perror(dirname);
+		fprintf(stderr, "chdir %s failed: %s\n", dirname,
+			strerror(errno));
 		exit(1);
 	}
 	if (logname) {

ltp/fsstress.c doproc(void) · line 971

Quoted 9 lines
ltp/fsstress.c +5 -1
@@ -959,7 +964,11 @@ doproc(void)
 
 	dividend = (operations + execute_freq) / (execute_freq + 1);
 	sprintf(buf, "p%x", procid);
-	(void)mkdir(buf, 0777);
+	if (mkdir((const char *)buf, 0777) < 0) {
+		fprintf(stderr, "mkdir %s failed: %s\n", buf,
+			strerror(errno));
+		exit(1);
+	}

Same here.

Thanks,
Eryu

Quoted 10 lines
ltp/fsstress.c +0 -0
 	if (chdir(buf) < 0 || stat64(".", &statbuf) < 0) {
 		perror(buf);
 		_exit(1);
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe fstests" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe fstests" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html