md/raid10: improve code of mrdev in raid10_sync_request
commit 59f8f0b54c8ffb4521f6bbd1cb6f4dfa5022e75e upstream. '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. Signed-off-by: Li Nan <linan122@huawei.com> Reviewed-by: Yu Kuai <yukuai3@huawei.com> Signed-off-by: Song Liu <song@kernel.org> Link: https://lore.kernel.org/r/20230527072218.2365857-3-linan666@huaweicloud.com Cc: Hagar Gamal Halim <hagarhem@amazon.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
60cea42f5a
commit
4eeda86cdc
1 changed files with 12 additions and 11 deletions
|
@ -3052,7 +3052,6 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
|
||||||
sector_t sect;
|
sector_t sect;
|
||||||
int must_sync;
|
int must_sync;
|
||||||
int any_working;
|
int any_working;
|
||||||
int need_recover = 0;
|
|
||||||
struct raid10_info *mirror = &conf->mirrors[i];
|
struct raid10_info *mirror = &conf->mirrors[i];
|
||||||
struct md_rdev *mrdev, *mreplace;
|
struct md_rdev *mrdev, *mreplace;
|
||||||
|
|
||||||
|
@ -3060,14 +3059,13 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
|
||||||
mrdev = rcu_dereference(mirror->rdev);
|
mrdev = rcu_dereference(mirror->rdev);
|
||||||
mreplace = rcu_dereference(mirror->replacement);
|
mreplace = rcu_dereference(mirror->replacement);
|
||||||
|
|
||||||
if (mrdev != NULL &&
|
if (mrdev && (test_bit(Faulty, &mrdev->flags) ||
|
||||||
!test_bit(Faulty, &mrdev->flags) &&
|
test_bit(In_sync, &mrdev->flags)))
|
||||||
!test_bit(In_sync, &mrdev->flags))
|
mrdev = NULL;
|
||||||
need_recover = 1;
|
|
||||||
if (mreplace && test_bit(Faulty, &mreplace->flags))
|
if (mreplace && test_bit(Faulty, &mreplace->flags))
|
||||||
mreplace = NULL;
|
mreplace = NULL;
|
||||||
|
|
||||||
if (!need_recover && !mreplace) {
|
if (!mrdev && !mreplace) {
|
||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -3101,6 +3099,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
|
||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (mrdev)
|
||||||
atomic_inc(&mrdev->nr_pending);
|
atomic_inc(&mrdev->nr_pending);
|
||||||
if (mreplace)
|
if (mreplace)
|
||||||
atomic_inc(&mreplace->nr_pending);
|
atomic_inc(&mreplace->nr_pending);
|
||||||
|
@ -3188,7 +3187,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
|
||||||
r10_bio->devs[1].devnum = i;
|
r10_bio->devs[1].devnum = i;
|
||||||
r10_bio->devs[1].addr = to_addr;
|
r10_bio->devs[1].addr = to_addr;
|
||||||
|
|
||||||
if (need_recover) {
|
if (mrdev) {
|
||||||
bio = r10_bio->devs[1].bio;
|
bio = r10_bio->devs[1].bio;
|
||||||
bio->bi_next = biolist;
|
bio->bi_next = biolist;
|
||||||
biolist = bio;
|
biolist = bio;
|
||||||
|
@ -3233,7 +3232,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
|
||||||
for (k = 0; k < conf->copies; k++)
|
for (k = 0; k < conf->copies; k++)
|
||||||
if (r10_bio->devs[k].devnum == i)
|
if (r10_bio->devs[k].devnum == i)
|
||||||
break;
|
break;
|
||||||
if (!test_bit(In_sync,
|
if (mrdev && !test_bit(In_sync,
|
||||||
&mrdev->flags)
|
&mrdev->flags)
|
||||||
&& !rdev_set_badblocks(
|
&& !rdev_set_badblocks(
|
||||||
mrdev,
|
mrdev,
|
||||||
|
@ -3259,11 +3258,13 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
|
||||||
if (rb2)
|
if (rb2)
|
||||||
atomic_dec(&rb2->remaining);
|
atomic_dec(&rb2->remaining);
|
||||||
r10_bio = rb2;
|
r10_bio = rb2;
|
||||||
|
if (mrdev)
|
||||||
rdev_dec_pending(mrdev, mddev);
|
rdev_dec_pending(mrdev, mddev);
|
||||||
if (mreplace)
|
if (mreplace)
|
||||||
rdev_dec_pending(mreplace, mddev);
|
rdev_dec_pending(mreplace, mddev);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (mrdev)
|
||||||
rdev_dec_pending(mrdev, mddev);
|
rdev_dec_pending(mrdev, mddev);
|
||||||
if (mreplace)
|
if (mreplace)
|
||||||
rdev_dec_pending(mreplace, mddev);
|
rdev_dec_pending(mreplace, mddev);
|
||||||
|
|
Loading…
Reference in a new issue