@@ -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");