diff mbox

btrfs-progs: report failure when resize ioctl fails

Message ID 1429673927-3854-1-git-send-email-ce3g8jdj@umail.furryterror.org (mailing list archive)
State Accepted
Headers show

Commit Message

Zygo Blaxell April 22, 2015, 3:38 a.m. UTC
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!
---
 cmds-filesystem.c |   10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

David Sterba April 22, 2015, 4:31 p.m. UTC | #1
On Tue, Apr 21, 2015 at 11:38:47PM -0400, Zygo Blaxell wrote:
> 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!

Added the signed-off-by and applied, thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index f3fc160..85f0406 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -1263,6 +1263,16 @@  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;
 }