Skip to contentSkip to conversation

btrfs_progs: _PROGRESS ioctl for error output in do_balance()

RFC PATCH New Petr Janecek 1 participant 1 message Apr 8, 2020 Btrfs file system

lore
Share & tools
lore
#0 lore raw

RFC PATCH 2/3 btrfs_progs: _PROGRESS ioctl for error output in do_balance()

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(+)
cmds/balance.c +18 -0
index fada2ab3..3d4deb27 100644
@@ -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");
Signature · 1 line
2.26.0