Skip to content

Commit ca151f1

Browse files
josefbacikkdave
authored andcommitted
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 <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent e3503c5 commit ca151f1

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

cmds/filesystem-usage.c

+3-5
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static int load_chunk_info(int fd, struct chunk_info **chunkinfo_ret,
145145
struct btrfs_ioctl_search_key *sk = &args.key;
146146
struct btrfs_ioctl_search_header *sh;
147147
unsigned long off = 0;
148-
int i, e;
148+
int i;
149149

150150
memset(&args, 0, sizeof(args));
151151

@@ -168,11 +168,9 @@ static int load_chunk_info(int fd, struct chunk_info **chunkinfo_ret,
168168

169169
while (1) {
170170
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
171-
e = errno;
172-
if (e == EPERM)
173-
return -e;
174-
175171
if (ret < 0) {
172+
if (errno == EPERM)
173+
return -errno;
176174
error("cannot look up chunk tree info: %m");
177175
return 1;
178176
}

0 commit comments

Comments
 (0)