diff options
author | Yu Kuai <yukuai3@huawei.com> | 2023-08-25 11:16:21 +0800 |
---|---|---|
committer | Song Liu <song@kernel.org> | 2023-09-22 10:28:25 -0700 |
commit | a0ae7e4e0bc00ae178e42391157e8ddb88b2838a (patch) | |
tree | 059043d99ccf9ba80da52874fb7d6742537fd944 /drivers/md/md.c | |
parent | b172a0704d0ddea3a55f3633f8249c3ce7d960bc (diff) | |
download | lwn-a0ae7e4e0bc00ae178e42391157e8ddb88b2838a.tar.gz lwn-a0ae7e4e0bc00ae178e42391157e8ddb88b2838a.zip |
md: factor out a helper rdev_addable() from remove_and_add_spares()
There are no functional changes, just to make the code simpler and
prepare to delay remove_and_add_spares() to md_start_sync().
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Signed-off-by: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230825031622.1530464-7-yukuai1@huaweicloud.com
Diffstat (limited to 'drivers/md/md.c')
-rw-r--r-- | drivers/md/md.c | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/drivers/md/md.c b/drivers/md/md.c index fd96729c6655..324e1f3243b6 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -9208,6 +9208,31 @@ static bool rdev_is_spare(struct md_rdev *rdev) !test_bit(Faulty, &rdev->flags); } +static bool rdev_addable(struct md_rdev *rdev) +{ + /* rdev is already used, don't add it again. */ + if (test_bit(Candidate, &rdev->flags) || rdev->raid_disk >= 0 || + test_bit(Faulty, &rdev->flags)) + return false; + + /* Allow to add journal disk. */ + if (test_bit(Journal, &rdev->flags)) + return true; + + /* Allow to add if array is read-write. */ + if (md_is_rdwr(rdev->mddev)) + return true; + + /* + * For read-only array, only allow to readd a rdev. And if bitmap is + * used, don't allow to readd a rdev that is too old. + */ + if (rdev->saved_raid_disk >= 0 && !test_bit(Bitmap_sync, &rdev->flags)) + return true; + + return false; +} + static int remove_and_add_spares(struct mddev *mddev, struct md_rdev *this) { @@ -9265,20 +9290,10 @@ static int remove_and_add_spares(struct mddev *mddev, continue; if (rdev_is_spare(rdev)) spares++; - if (test_bit(Candidate, &rdev->flags)) - continue; - if (rdev->raid_disk >= 0) + if (!rdev_addable(rdev)) continue; - if (test_bit(Faulty, &rdev->flags)) - continue; - if (!test_bit(Journal, &rdev->flags)) { - if (!md_is_rdwr(mddev) && - !(rdev->saved_raid_disk >= 0 && - !test_bit(Bitmap_sync, &rdev->flags))) - continue; - + if (!test_bit(Journal, &rdev->flags)) rdev->recovery_offset = 0; - } if (mddev->pers->hot_add_disk(mddev, rdev) == 0) { /* failure here is OK */ sysfs_link_rdev(mddev, rdev); |