Skip to contentSkip to conversation

fsstress: improve error message on check_cwd() error

PATCH In review Luis Chamberlain 2 participants 5 messages Sep 21, 2021 – Nov 1, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fsstress: improve error message on check_cwd() error

I ran into an error with generic/083 with xfs due to check_cwd() but why it failed is not clear because there are two types of failures:

o stat64() failed (likely -ENOMEM is my guess)
o the inode actually changed

Thow a bone out to developers so that in case en error does happen they know which rabbit hole to go down on.

Cc Anthony Iliopoulos <[email protected]>
---
 ltp/fsstress.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
ltp/fsstress.c +14 -1
index b4ddf5e2..d2f09901 100644
@@ -9,6 +9,7 @@
 #include <sys/uio.h>
 #include <stddef.h>
 #include <stdbool.h>
+#include <string.h>
 #include "global.h"
 
 #ifdef HAVE_BTRFSUTIL_H
@@ -943,9 +944,21 @@ check_cwd(void)
 {
 #ifdef DEBUG
 	struct stat64	statbuf;
+	int ret;
+
+	ret = stat64(".", &statbuf);
+	if (ret !=0) {
+		fprintf(stderr, "fsstress: check_cwd stat64 failed with: %d (%s)\n",
+			ret, strerror(ret));
+		goto out;
+	}
 
-	if (stat64(".", &statbuf) == 0 && statbuf.st_ino == top_ino)
+	if (statbuf.st_ino == top_ino)
 		return;
+
+	fprintf(stderr, "fsstress: check_cwd statbuf.st_ino (%ld) != top_ino (%ld)\n",
+		(long)statbuf.st_ino, (long)top_ino);
+out:
 	assert(chdir(homedir) == 0);
 	fprintf(stderr, "fsstress: check_cwd failure\n");
 	abort();
Signature · 1 line
2.30.2
#1 lore raw
Quoted 30 lines · Luis Chamberlain

I ran into an error with generic/083 with xfs due to check_cwd() but why it failed is not clear because there are two types of failures:

o stat64() failed (likely -ENOMEM is my guess)
o the inode actually changed

Thow a bone out to developers so that in case en error does happen they know which rabbit hole to go down on.

Cc Anthony Iliopoulos <[email protected]>
---
 ltp/fsstress.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
ltp/fsstress.c +1 -0
index b4ddf5e2..d2f09901 100644
@@ -9,6 +9,7 @@
 #include <sys/uio.h>
 #include <stddef.h>
 #include <stdbool.h>
+#include <string.h>
 #include "global.h"
 
 #ifdef HAVE_BTRFSUTIL_H

ltp/fsstress.c check_cwd(void) · line 952

Quoted 9 lines
ltp/fsstress.c +6 -0
@@ -943,9 +944,21 @@ check_cwd(void)
 {
 #ifdef DEBUG
        struct stat64   statbuf;
+       int ret;
+
+       ret = stat64(".", &statbuf);
+       if (ret !=0) {
+               fprintf(stderr, "fsstress: check_cwd stat64 failed with: %d (%s)\n",
+                       ret, strerror(ret));

The error is not in 'ret' but instead in 'errno', so it should print errno and strerror(errno).

ltp/fsstress.c check_cwd(void) · line 960

Quoted 9 lines
ltp/fsstress.c +6 -1
+               goto out;
+       }
 
-       if (stat64(".", &statbuf) == 0 && statbuf.st_ino == top_ino)
+       if (statbuf.st_ino == top_ino)
                return;
+
+       fprintf(stderr, "fsstress: check_cwd statbuf.st_ino (%ld) != top_ino (%ld)\n",
+               (long)statbuf.st_ino, (long)top_ino);

ino_t is guaranteed to be an unsigned integer, and can be either 64 or 32 bits wide [1].
Casting to unsigned 64 bits would be better imo.

Thanks.

https://www.gnu.org/software/libc/manual/html_node/Attribute-Meanings.html

Quoted 7 lines
ltp/fsstress.c +1 -1
+out:
        assert(chdir(homedir) == 0);
        fprintf(stderr, "fsstress: check_cwd failure\n");
        abort();
--

2.30.2

Signature · 3 lines
Filipe David Manana,

“Whether you think you can, or you think you can't — you're right.”
#2 lore raw
Quoted 29 lines · Filipe Manana
Quoted 28 lines · Luis Chamberlain

I ran into an error with generic/083 with xfs due to check_cwd() but why it failed is not clear because there are two types of failures:

o stat64() failed (likely -ENOMEM is my guess)
o the inode actually changed

Thow a bone out to developers so that in case en error does happen they know which rabbit hole to go down on.

Cc Anthony Iliopoulos <[email protected]>
---
 ltp/fsstress.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
ltp/fsstress.c +1 -0
index b4ddf5e2..d2f09901 100644
@@ -9,6 +9,7 @@
 #include <sys/uio.h>
 #include <stddef.h>
 #include <stdbool.h>
+#include <string.h>
 #include "global.h"
 
Quoted 14 lines

ltp/fsstress.c check_cwd(void) · line 952

Quoted 11 lines
ltp/fsstress.c +6 -0
 #ifdef HAVE_BTRFSUTIL_H
@@ -943,9 +944,21 @@ check_cwd(void)
 {
 #ifdef DEBUG
        struct stat64   statbuf;
+       int ret;
+
+       ret = stat64(".", &statbuf);
+       if (ret !=0) {
+               fprintf(stderr, "fsstress: check_cwd stat64 failed with: %d (%s)\n",
+                       ret, strerror(ret));

The error is not in 'ret' but instead in 'errno', so it should print errno and strerror(errno).

Good call will fix.

Quoted 10 lines

ltp/fsstress.c check_cwd(void) · line 960

Quoted 9 lines
ltp/fsstress.c +6 -1
+               goto out;
+       }
 
-       if (stat64(".", &statbuf) == 0 && statbuf.st_ino == top_ino)
+       if (statbuf.st_ino == top_ino)
                return;
+
+       fprintf(stderr, "fsstress: check_cwd statbuf.st_ino (%ld) != top_ino (%ld)\n",
+               (long)statbuf.st_ino, (long)top_ino);
Quoted 3 lines

ino_t is guaranteed to be an unsigned integer, and can be either 64 or 32 bits wide [1].
Casting to unsigned 64 bits would be better imo.

There are other similar mi-uses in the code, should I fix those to then?

Luis

#3 lore raw
Quoted 58 lines · Luis Chamberlain
Quoted 29 lines · Filipe Manana
Quoted 28 lines · Luis Chamberlain

I ran into an error with generic/083 with xfs due to check_cwd() but why it failed is not clear because there are two types of failures:

o stat64() failed (likely -ENOMEM is my guess)
o the inode actually changed

Thow a bone out to developers so that in case en error does happen they know which rabbit hole to go down on.

Cc Anthony Iliopoulos <[email protected]>
---
 ltp/fsstress.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
ltp/fsstress.c +1 -0
index b4ddf5e2..d2f09901 100644
@@ -9,6 +9,7 @@
 #include <sys/uio.h>
 #include <stddef.h>
 #include <stdbool.h>
+#include <string.h>
 #include "global.h"
 
Quoted 14 lines

ltp/fsstress.c check_cwd(void) · line 952

Quoted 11 lines
ltp/fsstress.c +6 -0
 #ifdef HAVE_BTRFSUTIL_H
@@ -943,9 +944,21 @@ check_cwd(void)
 {
 #ifdef DEBUG
        struct stat64   statbuf;
+       int ret;
+
+       ret = stat64(".", &statbuf);
+       if (ret !=0) {
+               fprintf(stderr, "fsstress: check_cwd stat64 failed with: %d (%s)\n",
+                       ret, strerror(ret));

The error is not in 'ret' but instead in 'errno', so it should print errno and strerror(errno).

Good call will fix.

Quoted 10 lines
Quoted 9 lines
ltp/fsstress.c +6 -1
+               goto out;
+       }
 
-       if (stat64(".", &statbuf) == 0 && statbuf.st_ino == top_ino)
+       if (statbuf.st_ino == top_ino)
                return;
+
+       fprintf(stderr, "fsstress: check_cwd statbuf.st_ino (%ld) != top_ino (%ld)\n",
+               (long)statbuf.st_ino, (long)top_ino);
Quoted 6 lines
Quoted 3 lines

ino_t is guaranteed to be an unsigned integer, and can be either 64 or 32 bits wide [1].
Casting to unsigned 64 bits would be better imo.

There are other similar mi-uses in the code, should I fix those to then?

If you want to, as a separate patch.
Noticing now that since the code is using struct stat64, using %llu for the printfs without any casts should be fine [1].

Thanks.

[1] https://www.mkssoftware.com/docs/man5/struct_stat.5.asp

Quoted 3 lines

Luis

Signature · 3 lines
Filipe David Manana,

“Whether you think you can, or you think you can't — you're right.”
#4 lore raw
Quoted 10 lines · Filipe Manana
Quoted 9 lines · Luis Chamberlain
Quoted 6 lines · Filipe Manana

ltp/fsstress.c check_cwd(void) · line 960

Quoted 2 lines
ltp/fsstress.c +2 -0
+       fprintf(stderr, "fsstress: check_cwd statbuf.st_ino (%ld) != top_ino (%ld)\n",
+               (long)statbuf.st_ino, (long)top_ino);

ino_t is guaranteed to be an unsigned integer, and can be either 64 or 32 bits wide [1].
Casting to unsigned 64 bits would be better imo.

Quoted 7 lines
Quoted 2 lines

There are other similar mi-uses in the code, should I fix those to then?

If you want to, as a separate patch.

Since the code is using struct stat64, using %llu for the printfs without any casts should be fine [1].

You mean %lu because with %llu there is a warning.

Luis