diff mbox series

[RFC,2/3] btrfs_progs: _PROGRESS ioctl for error output in do_balance()

Message ID 20200408131517.GC19101@jkm (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: balance --bg invocation | expand

Commit Message

Petr Janecek April 8, 2020, 1:15 p.m. UTC
With 'btrfs balance start --background ...', all the potential error
messages are lost.  Add ioctl() to check for basic permission denied
and balance in progress conditions.
---
 cmds/balance.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
diff mbox series

Patch

diff --git a/cmds/balance.c b/cmds/balance.c
index fada2ab3..3d4deb27 100644
--- a/cmds/balance.c
+++ b/cmds/balance.c
@@ -444,6 +444,24 @@  static int do_balance(const char *path, struct btrfs_ioctl_balance_args *args,
 		return 1;
 
 	if (flags & BALANCE_START_BACKGROUND) {
+		/*
+		 * We are not going to see any error output from the
+		 * forked process.  So do a sanity check that the
+		 * balance is likely to start.
+		 */
+	        struct btrfs_ioctl_balance_args stat_args;
+		ret = ioctl(fd, BTRFS_IOC_BALANCE_PROGRESS, &stat_args);
+		if (ret == 0) {
+			error("error during balancing '%s': "
+				"Operation now in progress", path);
+			ret = 1;
+			goto out;
+		} else if (errno != ENOTCONN) {
+			error("error during balancing '%s': %m", path);
+			ret = 1;
+			goto out;
+		}
+
 		switch (fork()) {
 		case (-1):
 			error("unable to fork to run balance in background");