From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 58C711FF16F for ; Tue, 8 Jul 2025 14:00:32 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CF7C915F25; Tue, 8 Jul 2025 14:01:14 +0200 (CEST) Message-ID: <3d66a3fa-e7ce-49e7-805d-5f4bccc553f6@proxmox.com> Date: Tue, 8 Jul 2025 14:01:09 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: Christoph Heiss References: <20250626151119.255169-1-m.koeppl@proxmox.com> <20250626151119.255169-3-m.koeppl@proxmox.com> From: =?UTF-8?Q?Michael_K=C3=B6ppl?= Content-Language: en-US In-Reply-To: X-SPAM-LEVEL: Spam detection results: 0 AWL 0.013 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [options.rs] Subject: Re: [pve-devel] [PATCH pve-installer v3 2/7] move RAID setup checks to RAID level enum implementations X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Cc: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" On 7/7/25 13:47, Christoph Heiss wrote: >> + >> + for v in zfs_raid_variants { >> + assert!(v.check_disks(&[]).is_err()); >> + assert!(v.check_disks(&disks[..v.get_min_disks() - 1]).is_err()); >> + assert!(v.check_disks(&disks[..v.get_min_disks()]).is_ok()); >> + assert!(v.check_disks(&disks).is_ok()); >> + } >> } > > These unit tests should be moved to `proxmox_installer_common::options`, > if the implementation of these methods also resides there. First of all, thanks for having a look at this! True, I forgot to move the tests as well. Will move them for v4. Right now, both sets of unit tests (for proxmox_installer_common::options and proxmox_installer_common::disk_checks) use the dummy_disks and dummy_disk helpers. I think simply copying the implementation of these over to the options.rs tests is fine since the implementation is not exactly complicated and it seems a bit overkill to introduce some sort of test utils for this. What do you think? > >> } >> diff --git a/proxmox-installer-common/src/options.rs b/proxmox-installer-common/src/options.rs >> index 9271b8b..0552954 100644 >> --- a/proxmox-installer-common/src/options.rs >> +++ b/proxmox-installer-common/src/options.rs >> @@ -6,6 +6,7 @@ use std::str::FromStr; >> use std::sync::OnceLock; >> use std::{cmp, fmt}; >> >> +use crate::disk_checks::check_raid_min_disks; >> use crate::setup::{LocaleInfo, NetworkInfo, RuntimeInfo, SetupInfo}; >> use crate::utils::{CidrAddress, Fqdn}; >> >> @@ -28,6 +29,17 @@ impl BtrfsRaidLevel { >> BtrfsRaidLevel::Raid10 => 4, >> } >> } >> + >> + /// Checks whether a user-supplied Btrfs RAID setup is valid or not, such as minimum >> + /// number of disks. >> + /// >> + /// # Arguments >> + /// >> + /// * `disks` - List of disks designated as RAID targets. >> + pub fn check_disks(&self, disks: &[Disk]) -> Result<(), String> { > > Maybe rename this to something more expressive, e.g. > check_raid_disks_setup()? > > check_disks() by itself is a rather "opaque" method name and would (at > least to me, if I didn't know the implementation) suggests that the > actual disks are checked, not just the RAID configuration and sizes. I agree that check_disks() suggests that the function does more/something different than it actually does. Thanks for your suggestion, I'll adapt it to check_raid_disks_setup() in v4. > >> + check_raid_min_disks(disks, self.get_min_disks())?; >> + Ok(()) >> + } >> } >> >> serde_plain::derive_display_from_serialize!(BtrfsRaidLevel); >> @@ -69,6 +81,53 @@ impl ZfsRaidLevel { >> ZfsRaidLevel::RaidZ3 => 5, >> } >> } >> + >> + fn check_mirror_size(&self, disk1: &Disk, disk2: &Disk) -> Result<(), String> { >> + if (disk1.size - disk2.size).abs() > disk1.size / 10. { >> + Err(format!( >> + "Mirrored disks must have same size:\n\n * {disk1}\n * {disk2}" >> + )) >> + } else { >> + Ok(()) >> + } >> + } >> + >> + /// Checks whether a user-supplied ZFS RAID setup is valid or not, such as disk sizes andminimum >> + /// number of disks. >> + /// >> + /// # Arguments >> + /// >> + /// * `disks` - List of disks designated as RAID targets. >> + pub fn check_disks(&self, disks: &[Disk]) -> Result<(), String> { > > ^ Same here as above. > >> + check_raid_min_disks(disks, self.get_min_disks())?; >> + >> + match self { >> + ZfsRaidLevel::Raid0 => {} >> + ZfsRaidLevel::Raid10 => { >> + if disks.len() % 2 != 0 { >> + return Err(format!( >> + "Needs an even number of disks, currently selected: {}", >> + disks.len(), >> + )); >> + } >> + >> + // Pairs need to have the same size >> + for i in (0..disks.len()).step_by(2) { >> + self.check_mirror_size(&disks[i], &disks[i + 1])?; >> + } >> + } >> + ZfsRaidLevel::Raid1 >> + | ZfsRaidLevel::RaidZ >> + | ZfsRaidLevel::RaidZ2 >> + | ZfsRaidLevel::RaidZ3 => { >> + for disk in disks { >> + self.check_mirror_size(&disks[0], disk)?; >> + } >> + } >> + } >> + >> + Ok(()) >> + } >> } _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel