mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yu Kuai <yukuai1@huaweicloud.com>
To: linan666@huaweicloud.com, song@kernel.org,
	bingjingc@synology.com, allenpeng@synology.com,
	alexwu@synology.com, shli@fb.com, neilb@suse.de
Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org,
	linan122@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com,
	yangerkun@huawei.com, "yukuai (C)" <yukuai3@huawei.com>
Subject: Re: [PATCH v2 2/4] md/raid10: improve code of mrdev in raid10_sync_request
Date: Sat, 27 May 2023 09:41:12 +0800	[thread overview]
Message-ID: <a9a6bf58-65c2-9f8d-3ab1-c7722f55b25e@huaweicloud.com> (raw)
In-Reply-To: <20230526074551.669792-3-linan666@huaweicloud.com>

在 2023/05/26 15:45, linan666@huaweicloud.com 写道:
> From: Li Nan <linan122@huawei.com>
> 
> 'need_recover' and 'mrdev' are equivalent in raid10_sync_request(), and
> inc mrdev->nr_pending is unreasonable if don't need recovery. Replace
> 'need_recover' with 'mrdev', and only inc nr_pending when needed.

LGTM, feel free to add:

Reviewed-by: Yu Kuai <yukuai3@huawei.com>
> 
> Suggested-by: Yu Kuai <yukuai3@huawei.com>
> Signed-off-by: Li Nan <linan122@huawei.com>
> ---
>   drivers/md/raid10.c | 22 ++++++++++++----------
>   1 file changed, 12 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
> index e21502c03b45..9de9eabff209 100644
> --- a/drivers/md/raid10.c
> +++ b/drivers/md/raid10.c
> @@ -3437,7 +3437,6 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
>   			sector_t sect;
>   			int must_sync;
>   			int any_working;
> -			int need_recover = 0;
>   			struct raid10_info *mirror = &conf->mirrors[i];
>   			struct md_rdev *mrdev, *mreplace;
>   
> @@ -3446,14 +3445,14 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
>   			mreplace = rcu_dereference(mirror->replacement);
>   
>   			if (mrdev != NULL &&
> -			    !test_bit(Faulty, &mrdev->flags) &&
> -			    !test_bit(In_sync, &mrdev->flags))
> -				need_recover = 1;
> +			    (test_bit(Faulty, &mrdev->flags) ||
> +			    test_bit(In_sync, &mrdev->flags)))
> +				mrdev = NULL;
>   			if (mreplace != NULL &&
>   			    test_bit(Faulty, &mreplace->flags))
>   				mreplace = NULL;
>   
> -			if (!need_recover && !mreplace) {
> +			if (!mrdev && !mreplace) {
>   				rcu_read_unlock();
>   				continue;
>   			}
> @@ -3487,7 +3486,8 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
>   				rcu_read_unlock();
>   				continue;
>   			}
> -			atomic_inc(&mrdev->nr_pending);
> +			if (mrdev)
> +				atomic_inc(&mrdev->nr_pending);
>   			if (mreplace)
>   				atomic_inc(&mreplace->nr_pending);
>   			rcu_read_unlock();
> @@ -3574,7 +3574,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
>   				r10_bio->devs[1].devnum = i;
>   				r10_bio->devs[1].addr = to_addr;
>   
> -				if (need_recover) {
> +				if (mrdev) {
>   					bio = r10_bio->devs[1].bio;
>   					bio->bi_next = biolist;
>   					biolist = bio;
> @@ -3619,7 +3619,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
>   					for (k = 0; k < conf->copies; k++)
>   						if (r10_bio->devs[k].devnum == i)
>   							break;
> -					if (!test_bit(In_sync,
> +					if (mrdev && !test_bit(In_sync,
>   						      &mrdev->flags)
>   					    && !rdev_set_badblocks(
>   						    mrdev,
> @@ -3645,12 +3645,14 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
>   				if (rb2)
>   					atomic_dec(&rb2->remaining);
>   				r10_bio = rb2;
> -				rdev_dec_pending(mrdev, mddev);
> +				if (mrdev)
> +					rdev_dec_pending(mrdev, mddev);
>   				if (mreplace)
>   					rdev_dec_pending(mreplace, mddev);
>   				break;
>   			}
> -			rdev_dec_pending(mrdev, mddev);
> +			if (mrdev)
> +				rdev_dec_pending(mrdev, mddev);
>   			if (mreplace)
>   				rdev_dec_pending(mreplace, mddev);
>   			if (r10_bio->devs[0].bio->bi_opf & MD_FAILFAST) {
> 


  reply	other threads:[~2023-05-27  1:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-26  7:45 [PATCH v2 0/4] raid10 bugfix linan666
2023-05-26  7:45 ` [PATCH v2 1/4] md/raid10: fix null-ptr-deref of mreplace in raid10_sync_request linan666
2023-05-26 21:38   ` Song Liu
2023-05-27  1:17     ` Yu Kuai
2023-05-27  1:28     ` Li Nan
2023-05-27  1:21   ` Yu Kuai
2023-05-27  1:29     ` Li Nan
2023-05-26  7:45 ` [PATCH v2 2/4] md/raid10: improve code of mrdev " linan666
2023-05-27  1:41   ` Yu Kuai [this message]
2023-05-26  7:45 ` [PATCH v2 3/4] md/raid10: fix incorrect done of recovery linan666
2023-05-26  7:45 ` [PATCH v2 4/4] md/raid10: fix io loss while replacement replace rdev linan666

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=a9a6bf58-65c2-9f8d-3ab1-c7722f55b25e@huaweicloud.com \
    --to=yukuai1@huaweicloud.com \
    --cc=alexwu@synology.com \
    --cc=allenpeng@synology.com \
    --cc=bingjingc@synology.com \
    --cc=houtao1@huawei.com \
    --cc=linan122@huawei.com \
    --cc=linan666@huaweicloud.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=neilb@suse.de \
    --cc=shli@fb.com \
    --cc=song@kernel.org \
    --cc=yangerkun@huawei.com \
    --cc=yi.zhang@huawei.com \
    --cc=yukuai3@huawei.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

all inboxes | Powered by JetHome®