mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Chen Cheng" <chencheng@fnnas.com>
To: <linux-raid@vger.kernel.org>, <yukuai@fygo.io>, <nixiao@fygo.io>
Cc: <chencheng@fnnas.com>, <linux-kernel@vger.kernel.org>
Subject: [PATCH v1 1/2] md/raid5: extract min_raid_disks()
Date: Mon, 14 Sep 2026 20:17:46 +0800	[thread overview]
Message-ID: <f79037a8c7cceafab6a6d372bc2bc7810de8653f.1789387793.git.chencheng@fnnas.com> (raw)
In-Reply-To: <cover.1789387793.git.chencheng@fnnas.com>

From: Chen Cheng <chencheng@fnnas.com>

Reuse the minimum disk count in setup_conf() and check_reshape().

Signed-off-by: Chen Cheng <chencheng@fnnas.com>
---
 drivers/md/raid5.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index e1f20035703b..4ab31af34b9f 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -7628,14 +7628,19 @@ static unsigned long raid5_cache_count(struct shrinker *shrink,
 		/* unlikely, but not impossible */
 		return 0;
 	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];
 	int i;
 	int group_cnt;
@@ -7655,15 +7660,15 @@ static struct r5conf *setup_conf(struct mddev *mddev)
 	     && !algorithm_valid_raid6(mddev->new_layout))) {
 		pr_warn("md/raid:%s: layout %d not supported\n",
 			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);
 	}
 
 	if (!mddev->new_chunk_sectors ||
 	    (mddev->new_chunk_sectors << 9) % PAGE_SIZE ||
@@ -8600,17 +8605,13 @@ static int check_reshape(struct mddev *mddev)
 	if (!mddev->new_chunk_sectors)
 		return -EINVAL;
 	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;
 	}
 
 	if (!check_stripe_cache(mddev))
 		return -ENOSPC;
-- 
2.55.0

  reply	other threads:[~2026-09-14 12:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-14 12:17 [PATCH v1 0/2] md/raid5: validate disk count before reshape assembly Chen Cheng
2026-09-14 12:17 ` Chen Cheng [this message]
2026-09-14 12:17 ` [PATCH v1 2/2] md/raid5: reject invalid reshape disks in raid5_run() Chen Cheng

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=f79037a8c7cceafab6a6d372bc2bc7810de8653f.1789387793.git.chencheng@fnnas.com \
    --to=chencheng@fnnas.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=nixiao@fygo.io \
    --cc=yukuai@fygo.io \
    /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®