diff mbox series

[3/3] btrfs-progs: fix improper error handling in btrfs filesystem usage

Message ID 6c916b6ad8042d676c17be3b3a3f78c7b5cb62cf.1692800798.git.josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: a couple fixes | expand

Commit Message

Josef Bacik Aug. 23, 2023, 2:27 p.m. UTC
I was seeing test-cli/016 failures because it claimed we were getting
EPERM from the TREE_SEARCH ioctl to get the chunk info out of the file
system.  This turned out to be because errno was already set going into
this function, the ioctl itself wasn't actually failing.  Fix this by
checking for a return value from the ioctl first, and then returning
-EPERM if appropriate.  This fixed the failures in my setup.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 cmds/filesystem-usage.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/cmds/filesystem-usage.c b/cmds/filesystem-usage.c
index 73b0ca35..f38051a2 100644
--- a/cmds/filesystem-usage.c
+++ b/cmds/filesystem-usage.c
@@ -145,7 +145,7 @@  static int load_chunk_info(int fd, struct chunk_info **chunkinfo_ret,
 	struct btrfs_ioctl_search_key *sk = &args.key;
 	struct btrfs_ioctl_search_header *sh;
 	unsigned long off = 0;
-	int i, e;
+	int i;
 
 	memset(&args, 0, sizeof(args));
 
@@ -168,11 +168,9 @@  static int load_chunk_info(int fd, struct chunk_info **chunkinfo_ret,
 
 	while (1) {
 		ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
-		e = errno;
-		if (e == EPERM)
-			return -e;
-
 		if (ret < 0) {
+			if (errno == EPERM)
+				return -errno;
 			error("cannot look up chunk tree info: %m");
 			return 1;
 		}