public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: "Michael Köppl" <m.koeppl@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-installer 2/6] common: use get_min_disks as single source of truth for RAID config checks
Date: Tue, 22 Apr 2025 18:27:35 +0200	[thread overview]
Message-ID: <20250422162739.255641-3-m.koeppl@proxmox.com> (raw)
In-Reply-To: <20250422162739.255641-1-m.koeppl@proxmox.com>

To avoid having multiple places where the minimum number of disks
required for a certain RAID setup is defined, use get_min_disks in the
common installer RAID config checks as well, keeping the behavior the
same as for the answer file sanity checks.

Signed-off-by: Michael Köppl <m.koeppl@proxmox.com>
---
An argument could be made here that there should be a declarative single
source of truth in the form of a JSON or similar that both Perl and
Rust-based installers can use. I would love some input on this as I
think it could make sense, but would require more extensive changes.
We already use JSON files as sources for selectable values, etc. in
other parts of the installer, so we would not be doing anything new
here.

 proxmox-installer-common/src/disk_checks.rs | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/proxmox-installer-common/src/disk_checks.rs b/proxmox-installer-common/src/disk_checks.rs
index ecc43bd..1d17e2c 100644
--- a/proxmox-installer-common/src/disk_checks.rs
+++ b/proxmox-installer-common/src/disk_checks.rs
@@ -69,17 +69,16 @@ pub fn check_zfs_raid_config(level: ZfsRaidLevel, disks: &[Disk]) -> Result<(),
         }
     };
 
+    check_raid_min_disks(disks, level.get_min_disks())?;
+
     match level {
-        ZfsRaidLevel::Raid0 => check_raid_min_disks(disks, 1)?,
+        ZfsRaidLevel::Raid0 => {}
         ZfsRaidLevel::Raid1 => {
-            check_raid_min_disks(disks, 2)?;
             for disk in disks {
                 check_mirror_size(&disks[0], disk)?;
             }
         }
         ZfsRaidLevel::Raid10 => {
-            check_raid_min_disks(disks, 4)?;
-
             if disks.len() % 2 != 0 {
                 return Err(format!(
                     "Needs an even number of disks, currently selected: {}",
@@ -94,19 +93,16 @@ pub fn check_zfs_raid_config(level: ZfsRaidLevel, disks: &[Disk]) -> Result<(),
         }
         // For RAID-Z: minimum disks number is level + 2
         ZfsRaidLevel::RaidZ => {
-            check_raid_min_disks(disks, 3)?;
             for disk in disks {
                 check_mirror_size(&disks[0], disk)?;
             }
         }
         ZfsRaidLevel::RaidZ2 => {
-            check_raid_min_disks(disks, 4)?;
             for disk in disks {
                 check_mirror_size(&disks[0], disk)?;
             }
         }
         ZfsRaidLevel::RaidZ3 => {
-            check_raid_min_disks(disks, 5)?;
             for disk in disks {
                 check_mirror_size(&disks[0], disk)?;
             }
@@ -125,13 +121,7 @@ pub fn check_zfs_raid_config(level: ZfsRaidLevel, disks: &[Disk]) -> Result<(),
 /// * `disks` - List of disks designated as RAID targets.
 pub fn check_btrfs_raid_config(level: BtrfsRaidLevel, disks: &[Disk]) -> Result<(), String> {
     // See also Proxmox/Install.pm:get_btrfs_raid_setup()
-
-    match level {
-        BtrfsRaidLevel::Raid0 => check_raid_min_disks(disks, 1)?,
-        BtrfsRaidLevel::Raid1 => check_raid_min_disks(disks, 2)?,
-        BtrfsRaidLevel::Raid10 => check_raid_min_disks(disks, 4)?,
-    }
-
+    check_raid_min_disks(disks, level.get_min_disks())?;
     Ok(())
 }
 
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

  parent reply	other threads:[~2025-04-22 16:27 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-22 16:27 [pve-devel] [PATCH installer 0/6] add early disk and network sanity checks Michael Köppl
2025-04-22 16:27 ` [pve-devel] [PATCH pve-installer 1/6] auto: add early answer file sanity check for RAID configurations Michael Köppl
2025-04-28 11:25   ` Christoph Heiss
2025-04-28 14:31     ` Michael Köppl
2025-04-29  8:26       ` Christoph Heiss
2025-04-29  9:32         ` Michael Köppl
2025-04-29  9:40           ` Christoph Heiss
2025-04-22 16:27 ` Michael Köppl [this message]
2025-04-28 11:48   ` [pve-devel] [PATCH pve-installer 2/6] common: use get_min_disks as single source of truth for RAID config checks Christoph Heiss
2025-04-28 15:36     ` Michael Köppl
2025-04-22 16:27 ` [pve-devel] [RFC PATCH pve-installer 3/6] close #5887: add sanity check for LVM swapsize and maxroot Michael Köppl
2025-04-28 12:00   ` Christoph Heiss
2025-04-29 11:30     ` Michael Köppl
2025-04-22 16:27 ` [pve-devel] [PATCH pve-installer 4/6] run rustfmt Michael Köppl
2025-04-23 11:56   ` Christoph Heiss
2025-04-25 12:22     ` Michael Köppl
2025-04-22 16:27 ` [pve-devel] [PATCH pve-installer 5/6] common: add more descriptive errors for invalid network configs Michael Köppl
2025-04-28 12:20   ` Christoph Heiss
2025-04-22 16:27 ` [pve-devel] [RFC PATCH pve-installer 6/6] closes #5757: common: add checks for valid IPv4 address within subnet Michael Köppl
2025-04-28 10:22   ` Christoph Heiss
2025-04-28 14:20     ` Michael Köppl
2025-04-28 12:25 ` [pve-devel] [PATCH installer 0/6] add early disk and network sanity checks Christoph Heiss
2025-04-29 14:14   ` Michael Köppl

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=20250422162739.255641-3-m.koeppl@proxmox.com \
    --to=m.koeppl@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal