diff options
| author | Chen Cheng <chencheng@fnnas.com> | 2026-09-21 15:16:52 +0800 |
|---|---|---|
| committer | Yu Kuai <yukuai@fygo.io> | 2026-09-22 15:20:18 +0800 |
| commit | 08c8e27535f2688fbe2d8f965477eafd5826f556 (patch) | |
| tree | dd457d5e62186075bac48b8b28fb27c3dbc1c235 /drivers/md | |
| parent | 96858e2308431ff5678e0e6fab1a06e19f3d95da (diff) | |
md/raid5: extract min_raid_disks()
Reuse the minimum disk count in setup_conf() and check_reshape().
Signed-off-by: Chen Cheng <chencheng@fnnas.com>
Link: https://patch.msgid.link/1dc59914e6935a0d6cdafaa1e73f682935f13abf.1789974245.git.chencheng@fnnas.com
Signed-off-by: Yu Kuai <yukuai@fygo.io>
Diffstat (limited to 'drivers/md')
| -rw-r--r-- | drivers/md/raid5.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index c315e99d0f30..f418b6aa1d37 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -7629,10 +7629,15 @@ static unsigned long raid5_cache_count(struct shrinker *shrink, return max_stripes - min_stripes; } +static int min_raid_disks(int level) +{ + return level == 6 ? 4 : 2; +} + static struct r5conf *setup_conf(struct mddev *mddev) { struct r5conf *conf; - int raid_disk, memory, max_disks; + int raid_disk, memory, max_disks, min_disks; struct md_rdev *rdev; struct disk_info *disk; char pers_name[6]; @@ -7656,11 +7661,11 @@ static struct r5conf *setup_conf(struct mddev *mddev) mdname(mddev), mddev->new_layout); return ERR_PTR(-EIO); } - if ((mddev->new_level != 6 && mddev->raid_disks < 2) || - (mddev->new_level == 6 && mddev->raid_disks < 4)) { + min_disks = min_raid_disks(mddev->new_level); + if (mddev->raid_disks < min_disks) { pr_warn("md/raid:%s: not enough configured devices (%d, minimum %d)\n", mdname(mddev), mddev->raid_disks, - mddev->new_level == 6 ? 4 : 2); + min_disks); return ERR_PTR(-EINVAL); } @@ -8615,13 +8620,9 @@ static int check_reshape(struct mddev *mddev) if (mddev->delta_disks < 0 && mddev->reshape_position == MaxSector) { /* We might be able to shrink, but the devices must * be made bigger first. - * For raid6, 4 is the minimum size. - * Otherwise 2 is the minimum */ - int min = 2; - if (mddev->level == 6) - min = 4; - if (mddev->raid_disks + mddev->delta_disks < min) + if (mddev->raid_disks + mddev->delta_disks < + min_raid_disks(mddev->level)) return -EINVAL; } |
