From 7ab0bdd7125c098670a6c2bb9d6bb95c1aaa78ed Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Tue, 21 Apr 2015 23:38:47 -0400 Subject: btrfs-progs: report failure when resize ioctl fails The BTRFS_IOC_RESIZE ioctl returns 0 on success, negative for POSIX errors, and positive for btrfs-specific errors. If resize fails with a btrfs-specific error, decode the error and report it. If we can't decode the error, report its numeric value so that the userspace tool is not instantly useless when a new error code is defined in the kernel. Exit with non-zero status on any resize error. This is very important for scripts that will shrink the underlying storage when btrfs reports success! Signed-off-by: Zygo Blaxell --- cmds-filesystem.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'cmds-filesystem.c') diff --git a/cmds-filesystem.c b/cmds-filesystem.c index 2cace758..b93bb330 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -1278,6 +1278,18 @@ static int cmd_resize(int argc, char **argv) fprintf(stderr, "ERROR: unable to resize '%s' - %s\n", path, strerror(e)); return 1; + } else if (res > 0) { + const char *err_str = btrfs_err_str(res); + + if (err_str) { + fprintf(stderr, "ERROR: btrfs error resizing '%s' - %s\n", + path, err_str); + } else { + fprintf(stderr, + "ERROR: btrfs error resizing '%s' - unknown btrfs_err_code %d\n", + path, res); + } + return 1; } return 0; } -- cgit v1.2.3