linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Cc: Anand Jain <anand.jain@oracle.com>
Subject: [PATCH] btrfs-progs: fix return code for failed replace start
Date: Wed, 30 Sep 2020 10:46:14 +0800	[thread overview]
Message-ID: <48194115537d723d04bba0505411525b77f3e73b.1601402292.git.anand.jain@oracle.com> (raw)

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 adding a goto leave_with_error for this error which also fixes
the device open leak.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
This patch has passed fstests -g replace.

 cmds/replace.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/cmds/replace.c b/cmds/replace.c
index 84fcb80ed495..f4e81574804e 100644
--- a/cmds/replace.c
+++ b/cmds/replace.c
@@ -297,9 +297,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) {
-- 
2.25.1


             reply	other threads:[~2020-09-30  2:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-30  2:46 Anand Jain [this message]
2021-02-19 19:00 ` [PATCH] btrfs-progs: fix return code for failed replace start David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48194115537d723d04bba0505411525b77f3e73b.1601402292.git.anand.jain@oracle.com \
    --to=anand.jain@oracle.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).