Replace start fails to report the appropriate error if balance is already
running, as below,

btrfs rep start -B -f /dev/sdb /dev/sde /btrfs
ERROR: ioctl(DEV_REPLACE_START) on '/btrfs' returns error: <illegal
result value>

Fix it by checking if the return is > 0, as the kernel returns
BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS for the above cli, if the balance is
running.

Signed-off-by: Anand Jain <anand.j...@oracle.com>
Reviewed-by: Nikolay Borisov <nbori...@suse.com>
---
 cmds-replace.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/cmds-replace.c b/cmds-replace.c
index 42de4de8c031..696f24c5c6d5 100644
--- a/cmds-replace.c
+++ b/cmds-replace.c
@@ -295,6 +295,10 @@ static int cmd_replace_start(int argc, char **argv)
                        goto leave_with_error;
                }
 
+               if (ret > 0)
+                       error("ioctl(DEV_REPLACE_START) '%s': %s", path,
+                             btrfs_err_str(ret));
+
                if (start_args.result !=
                    BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT &&
                    start_args.result !=
-- 
1.8.3.1

Reply via email to