From ddf878187ea8541051a5b4ae145fd9fbaf7089e1 Mon Sep 17 00:00:00 2001 From: Anand Jain Date: Wed, 30 Sep 2020 10:46:14 +0800 Subject: [PATCH] btrfs-progs: fix return code for failed replace start When replace starts with no-background and fails for the reason that a BTRFS_FS_EXCL_OP is in progress, we still return the value 0 and also leak the target device open, because in cmd_replace_start() we missed the goto leave_with_error for this error. So the test case btrfs/064 in its seqres.full output reports... Replacing /dev/sdf with /dev/sdc ERROR: /dev/sdc is mounted instead of... Replacing /dev/sdc with /dev/sdf ERROR: ioctl(DEV_REPLACE_START) '/mnt/scratch': add/delete/balance/replace/resize operation in progress for the failed replace attempts in the test case Fix it by jumping to the error label which also fixes the leaked open device. Signed-off-by: Anand Jain Signed-off-by: David Sterba --- cmds/replace.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmds/replace.c b/cmds/replace.c index 32a680e0..53af8ca6 100644 --- a/cmds/replace.c +++ b/cmds/replace.c @@ -323,9 +323,11 @@ static int cmd_replace_start(const struct cmd_struct *cmd, goto leave_with_error; } - if (ret > 0) + if (ret > 0) { error("ioctl(DEV_REPLACE_START) '%s': %s", path, btrfs_err_str(ret)); + goto leave_with_error; + } if (start_args.result != BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT && start_args.result != BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR) {