btrfs-progs: handle balance and replace concurrency

Starting device replace and balance does not properly report the status.

1. start replace:
   $ btrfs replace start -B -f /dev/sdd /dev/sdb /btrfs

2. while replace is still running, from another terminal try to start
   balance:
   $ btrfs balance start  --full-balance /btrfs
     Done, had to relocate 0 out of 0 chunks

This returns with exit code 0, which fails to report that balance failed
to start because another exclusive operation is running.
In fact kernel ioctl BTRFS_IOC_BALANCE(_V2) does return error code 8,
but it's incorrectly reset to 0. Fix it by checking for the error code > 0.

After:
  $ btrfs balance start --full-balance /btrfs
    ERROR: balance: add/delete/balance/replace/resize operation in progress

Signed-off-by: Anand Jain <anand.jain@oracle.com>
[ update changelog ]
Signed-off-by: David Sterba <dsterba@suse.com>
master
Anand Jain 2018-12-19 00:01:44 +08:00 committed by David Sterba
parent ccdd01a404
commit aca8193adb
1 changed files with 2 additions and 1 deletions

View File

@ -481,11 +481,12 @@ static int do_balance(const char *path, struct btrfs_ioctl_balance_args *args,
"There may be more info in syslog - try dmesg | tail\n");
ret = 1;
}
} else if (ret > 0) {
error("balance: %s", btrfs_err_str(ret));
} else {
printf("Done, had to relocate %llu out of %llu chunks\n",
(unsigned long long)args->stat.completed,
(unsigned long long)args->stat.considered);
ret = 0;
}
out: