2023-06-23 09:35:21

by Li Nan

[permalink] [raw]
Subject: [PATCH] md/raid1: prioritize adding disk to 'removed' mirror

From: Li Nan <[email protected]>

New disk should be added to "removed" position first instead of to be a
replacement. Commit 6090368abcb4 ("md/raid10: prioritize adding disk to
'removed' mirror") has fixed this issue for raid10. This patch fixes raid1.

Signed-off-by: Li Nan <[email protected]>
---
drivers/md/raid1.c | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 68a9e2d9985b..320bede4bfab 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1782,7 +1782,7 @@ static int raid1_add_disk(struct mddev *mddev, struct md_rdev *rdev)
{
struct r1conf *conf = mddev->private;
int err = -EEXIST;
- int mirror = 0;
+ int mirror = 0, repl_slot = -1;
struct raid1_info *p;
int first = 0;
int last = conf->raid_disks - 1;
@@ -1825,17 +1825,21 @@ static int raid1_add_disk(struct mddev *mddev, struct md_rdev *rdev)
break;
}
if (test_bit(WantReplacement, &p->rdev->flags) &&
- p[conf->raid_disks].rdev == NULL) {
- /* Add this device as a replacement */
- clear_bit(In_sync, &rdev->flags);
- set_bit(Replacement, &rdev->flags);
- rdev->raid_disk = mirror;
- err = 0;
- conf->fullsync = 1;
- rcu_assign_pointer(p[conf->raid_disks].rdev, rdev);
- break;
- }
+ p[conf->raid_disks].rdev == NULL && repl_slot < 0)
+ repl_slot = mirror;
}
+
+ if (err && repl_slot >= 0) {
+ /* Add this device as a replacement */
+ p = conf->mirrors + repl_slot;
+ clear_bit(In_sync, &rdev->flags);
+ set_bit(Replacement, &rdev->flags);
+ rdev->raid_disk = repl_slot;
+ err = 0;
+ conf->fullsync = 1;
+ rcu_assign_pointer(p[conf->raid_disks].rdev, rdev);
+ }
+
print_conf(conf);
return err;
}
--
2.39.2



2023-06-25 02:38:56

by Yu Kuai

[permalink] [raw]
Subject: Re: [PATCH] md/raid1: prioritize adding disk to 'removed' mirror

Hi,

?? 2023/06/24 1:25, [email protected] д??:
> From: Li Nan <[email protected]>
>
> New disk should be added to "removed" position first instead of to be a
> replacement. Commit 6090368abcb4 ("md/raid10: prioritize adding disk to
> 'removed' mirror") has fixed this issue for raid10. This patch fixes raid1.

This commit message "This patch ..." shound use imperative mood, other
than that, this patch LGTM.

Reviewed-by: Yu Kuai <[email protected]>
>
> Signed-off-by: Li Nan <[email protected]>
> ---
> drivers/md/raid1.c | 26 +++++++++++++++-----------
> 1 file changed, 15 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
> index 68a9e2d9985b..320bede4bfab 100644
> --- a/drivers/md/raid1.c
> +++ b/drivers/md/raid1.c
> @@ -1782,7 +1782,7 @@ static int raid1_add_disk(struct mddev *mddev, struct md_rdev *rdev)
> {
> struct r1conf *conf = mddev->private;
> int err = -EEXIST;
> - int mirror = 0;
> + int mirror = 0, repl_slot = -1;
> struct raid1_info *p;
> int first = 0;
> int last = conf->raid_disks - 1;
> @@ -1825,17 +1825,21 @@ static int raid1_add_disk(struct mddev *mddev, struct md_rdev *rdev)
> break;
> }
> if (test_bit(WantReplacement, &p->rdev->flags) &&
> - p[conf->raid_disks].rdev == NULL) {
> - /* Add this device as a replacement */
> - clear_bit(In_sync, &rdev->flags);
> - set_bit(Replacement, &rdev->flags);
> - rdev->raid_disk = mirror;
> - err = 0;
> - conf->fullsync = 1;
> - rcu_assign_pointer(p[conf->raid_disks].rdev, rdev);
> - break;
> - }
> + p[conf->raid_disks].rdev == NULL && repl_slot < 0)
> + repl_slot = mirror;
> }
> +
> + if (err && repl_slot >= 0) {
> + /* Add this device as a replacement */
> + p = conf->mirrors + repl_slot;
> + clear_bit(In_sync, &rdev->flags);
> + set_bit(Replacement, &rdev->flags);
> + rdev->raid_disk = repl_slot;
> + err = 0;
> + conf->fullsync = 1;
> + rcu_assign_pointer(p[conf->raid_disks].rdev, rdev);
> + }
> +
> print_conf(conf);
> return err;
> }
>


2023-06-25 07:30:26

by Li Nan

[permalink] [raw]
Subject: Re: [PATCH] md/raid1: prioritize adding disk to 'removed' mirror



在 2023/6/25 10:06, Yu Kuai 写道:
> Hi,
>
> 在 2023/06/24 1:25, [email protected] 写道:
>> From: Li Nan <[email protected]>
>>
>> New disk should be added to "removed" position first instead of to be a
>> replacement. Commit 6090368abcb4 ("md/raid10: prioritize adding disk to
>> 'removed' mirror") has fixed this issue for raid10. This patch fixes
>> raid1.
>
> This commit message "This patch ..." shound use imperative mood, other
> than that, this patch LGTM.
>
> Reviewed-by: Yu Kuai <[email protected]>

OK, I will change it. Thanks for your review.

--
Thanks,
Nan