From 0ba50a27f4279d06ea78c09196170c71a6fce83a Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Wed, 23 Aug 2023 10:27:50 -0400 Subject: [PATCH] btrfs-progs: fix improper error handling in btrfs filesystem usage 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 Signed-off-by: David Sterba --- cmds/filesystem-usage.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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; }