linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eryu Guan <guaneryu@gmail.com>
To: Miao Xie <miaox@cn.fujitsu.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] Btrfs: return failure if btrfs_dev_replace_finishing() failed
Date: Sat, 11 Oct 2014 14:45:29 +0800	[thread overview]
Message-ID: <20141011064529.GI13950@dhcp-13-216.nay.redhat.com> (raw)
In-Reply-To: <543797BA.3090103@cn.fujitsu.com>

On Fri, Oct 10, 2014 at 04:24:26PM +0800, Miao Xie wrote:
> On Fri, 10 Oct 2014 15:13:31 +0800, Eryu Guan wrote:
> > On Thu, Sep 25, 2014 at 06:28:14PM +0800, Eryu Guan wrote:
> >> device replace could fail due to another running scrub process, but this
> >> failure doesn't get returned to userspace.
> >>
> >> The following steps could reproduce this issue
> >>
> >> 	mkfs -t btrfs -f /dev/sdb1 /dev/sdb2
> >> 	mount /dev/sdb1 /mnt/btrfs
> >> 	while true; do
> >> 		btrfs scrub start -B /mnt/btrfs >/dev/null 2>&1
> >> 	done &
> >> 	btrfs replace start -Bf /dev/sdb2 /dev/sdb3 /mnt/btrfs
> >> 	# if this replace succeeded, do the following and repeat until
> >> 	# you see this log in dmesg
> >> 	# BTRFS: btrfs_scrub_dev(/dev/sdb2, 2, /dev/sdb3) failed -115
> >> 	#btrfs replace start -Bf /dev/sdb3 /dev/sdb2 /mnt/btrfs
> >>
> >> 	# once you see the error log in dmesg, check return value of
> >> 	# replace
> >> 	echo $?
> >>
> >> Also only WARN_ON if the return code is not -EINPROGRESS.
> >>
> >> Signed-off-by: Eryu Guan <guaneryu@gmail.com>
> > 
> > Ping, any comments on this patch?
> > 
> > Thanks,
> > Eryu
> >> ---
> >>  fs/btrfs/dev-replace.c | 8 +++++---
> >>  1 file changed, 5 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
> >> index eea26e1..44d32ab 100644
> >> --- a/fs/btrfs/dev-replace.c
> >> +++ b/fs/btrfs/dev-replace.c
> >> @@ -418,9 +418,11 @@ int btrfs_dev_replace_start(struct btrfs_root *root,
> >>  			      &dev_replace->scrub_progress, 0, 1);
> >>  
> >>  	ret = btrfs_dev_replace_finishing(root->fs_info, ret);
> >> -	WARN_ON(ret);
> >> +	/* don't warn if EINPROGRESS, someone else might be running scrub */
> >> +	if (ret != -EINPROGRESS)
> >> +		WARN_ON(ret);
> 
> picky comment
> 
> I prefer WARN_ON(ret && ret != -EINPROGRESS).

Yes, this is simpler :)
> 
> >>  
> >> -	return 0;
> >> +	return ret;
> 
> here we will return -EINPROGRESS if scrub is running, I think it better that
> we assign some special number to args->result, and then return 0, just like
> the case the device replace is running.

Seems that requires a new result type, say,

#define BTRFS_IOCTL_DEV_REPLACE_RESULT_SCRUB_INPROGRESS          3

and assign this result to args->result if btrfs_scrub_dev() returned -EINPROGRESS

But I don't think returning 0 unconditionally is a good idea, since
btrfs_dev_replace_finishing() could return other errors too, that way
these errors will be lost, and userspace still won't catch the
errors ($? is 0)

What I'm thinking about is something like:

	ret = btrfs_scrub_dev(...);
	ret = btrfs_dev_replace_finishing(root->fs_info, ret);
	if (ret == -EINPROGRESS) {
		args->result = BTRFS_IOCTL_DEV_REPLACE_RESULT_SCRUB_INPROGRESS;
		ret = 0;
	} else {
		WARN_ON(ret);
	}

	return ret;

What do you think? If no objection I'll work on v2.

Thanks for your review!

Eryu
> 
> Thanks
> Miao
> 
> >>  
> >>  leave:
> >>  	dev_replace->srcdev = NULL;
> >> @@ -538,7 +540,7 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
> >>  			btrfs_destroy_dev_replace_tgtdev(fs_info, tgt_device);
> >>  		mutex_unlock(&dev_replace->lock_finishing_cancel_unmount);
> >>  
> >> -		return 0;
> >> +		return scrub_ret;
> >>  	}
> >>  
> >>  	printk_in_rcu(KERN_INFO
> >> -- 
> >> 1.8.3.1
> >>
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > 
> 

  reply	other threads:[~2014-10-11  6:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-25 10:28 [PATCH] Btrfs: return failure if btrfs_dev_replace_finishing() failed Eryu Guan
2014-10-10  7:13 ` Eryu Guan
2014-10-10  8:24   ` Miao Xie
2014-10-11  6:45     ` Eryu Guan [this message]
2014-10-13  1:41       ` Miao Xie

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=20141011064529.GI13950@dhcp-13-216.nay.redhat.com \
    --to=guaneryu@gmail.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=miaox@cn.fujitsu.com \
    /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).