linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: fix return code for failed replace start
@ 2020-09-30  2:46 Anand Jain
  2021-02-19 19:00 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: Anand Jain @ 2020-09-30  2:46 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Anand Jain

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] btrfs-progs: fix return code for failed replace start
  2020-09-30  2:46 [PATCH] btrfs-progs: fix return code for failed replace start Anand Jain
@ 2021-02-19 19:00 ` David Sterba
  0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2021-02-19 19:00 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs

On Wed, Sep 30, 2020 at 10:46:14AM +0800, Anand Jain wrote:
> 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>

Added to devel, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-02-19 19:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-30  2:46 [PATCH] btrfs-progs: fix return code for failed replace start Anand Jain
2021-02-19 19:00 ` David Sterba

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).