From aca8193adbcf36097085f592feb9d11caa9af58e Mon Sep 17 00:00:00 2001 From: Anand Jain Date: Wed, 19 Dec 2018 00:01:44 +0800 Subject: [PATCH] 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 [ update changelog ] Signed-off-by: David Sterba --- cmds-balance.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmds-balance.c b/cmds-balance.c index c1dfe86e..15dc385e 100644 --- a/cmds-balance.c +++ b/cmds-balance.c @@ -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: