From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 0DAC11FF0E5 for ; Wed, 12 Aug 2026 15:56:02 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id A41B521423; Wed, 12 Aug 2026 15:56:01 +0200 (CEST) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 12 Aug 2026 15:55:58 +0200 Message-Id: Subject: Re: [PATCH proxmox v2 3/3] pbs-api-types: zfs: define schema for recordsize From: "Shan Shaji" To: "Nicolas Frey" , X-Mailer: aerc 0.20.0 References: <20260812110338.77010-1-s.shaji@proxmox.com> <20260812110338.77010-4-s.shaji@proxmox.com> In-Reply-To: X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1786542943582 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.746 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: ZSBWGPZRW7FTOPX7XVNM6XN6FDJZYVIL X-Message-ID-Hash: ZSBWGPZRW7FTOPX7XVNM6XN6FDJZYVIL X-MailFrom: s.shaji@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Backup Server development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Hi, Thanks for testing and verifying the code changes. On Wed Aug 12, 2026 at 3:41 PM CEST, Nicolas Frey wrote: > thanks for the v2 and adding a test! one small style nit inline > > On Wed Aug 12, 2026 at 1:03 PM CEST, Shan Shaji wrote: >> add schema and verifcation function for recordsize to check against >> allowed zfs constraints. Without the verification function the dataset >> will be created using the default 128k recordsize. >> >> Signed-off-by: Shan Shaji >> --- >> >> changes since v1: Please see the cover letter. >> >> pbs-api-types/src/zfs.rs | 68 ++++++++++++++++++++++++++++++++++++++++ >> 1 file changed, 68 insertions(+) >> >> diff --git a/pbs-api-types/src/zfs.rs b/pbs-api-types/src/zfs.rs >> index 2cfbd403..dea84b2e 100644 >> --- a/pbs-api-types/src/zfs.rs >> +++ b/pbs-api-types/src/zfs.rs >> @@ -1,3 +1,4 @@ >> +use anyhow::{Error, bail}; >> use serde::{Deserialize, Serialize}; >> >> #[cfg(feature =3D "enum-fallback")] >> @@ -6,6 +7,7 @@ use proxmox_schema::*; >> >> const_regex! { >> pub ZPOOL_NAME_REGEX =3D r"^[a-zA-Z][a-z0-9A-Z\-_.:]+$"; >> + ZFS_RECORD_SIZE_REGEX =3D r"^(?i)([1-9][0-9]*)([km])?$"; >> } >> >> pub const ZFS_ASHIFT_SCHEMA: Schema =3D IntegerSchema::new("Pool sector= size exponent.") >> @@ -18,6 +20,39 @@ pub const ZPOOL_NAME_SCHEMA: Schema =3D StringSchema:= :new("ZFS Pool Name") >> .format(&ApiStringFormat::Pattern(&ZPOOL_NAME_REGEX)) >> .schema(); >> >> +fn verify_zfs_recordsize(value: &str) -> Result<(), Error> { >> + if let Some(caps) =3D ZFS_RECORD_SIZE_REGEX.captures(value) { > > nit: you could instead use `let Some(x)` so the whole block does not need= to be nested: > > let Some(caps) =3D ZFS_RECORD_SIZE_REGEX.captures(value) else { > bail!("Invalid format. Use numbers with optional k or m suffix (e.g., 16= k)."); > }; ahh, right! this is much more cleaner. I did used `let..else` inside the bl= ock but didn't change it here.=20 > .. rest of the code >=20 > though no need to send a v3 for it, as it's just a style nit >> + let range_error =3D "Value must be a power of 2 between 512 and= 16m"; >> + >> + let Ok(number) =3D caps[1].parse::() else { >> + bail!(range_error); >> + }; ^^^^ here >> + let multiplier =3D match caps.get(2).map(|v| v.as_str()) { >> + Some(suffix) if suffix.eq_ignore_ascii_case("k") =3D> 1024, >> + Some(suffix) if suffix.eq_ignore_ascii_case("m") =3D> 1024 = * 1024, >> + _ =3D> 1, >> + }; >> + >> + let bytes =3D number >> + .checked_mul(multiplier) >> + .filter(|&b| b.is_power_of_two() && (512..=3D16 * 1024 * 10= 24).contains(&b)); >> + >> + if bytes.is_none() { >> + bail!(range_error); >> + } >> + >> + Ok(()) >> + } else { >> + bail!("Invalid format. Use numbers with optional k or m suffix = (e.g., 16k).") >> + } >> +} >> + >> +pub const ZFS_RECORD_SIZE_SCHEMA: Schema =3D >> + StringSchema::new("ZFS Recordsize. Use numbers with optional k or m= suffix (e.g., 128k).") >> + .format(&ApiStringFormat::VerifyFn(verify_zfs_recordsize)) >> + .schema(); >> + >> #[api(default: "On")] >> #[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] >> #[serde(rename_all =3D "lowercase")] >> @@ -84,3 +119,36 @@ pub struct ZpoolListItem { >> /// ZFS deduplication ratio >> pub dedup: f64, >> } >> + >> +#[cfg(test)] >> +mod tests { >> + >> + use super::verify_zfs_recordsize; >> + >> + #[test] >> + fn test_zfs_record_size_verify_fn() { >> + let format_error =3D "Invalid format. Use numbers with optional= k or m suffix (e.g., 16k)."; >> + let range_error =3D "Value must be a power of 2 between 512 and= 16m"; >> + >> + let valid_inputs =3D ["512", "1024", "16m", "16384k", "16777216= "]; >> + for input in valid_inputs { >> + assert!(verify_zfs_recordsize(input).is_ok()); >> + } >> + >> + let range_error_inputs =3D ["31m", "256", "31m", "32m", "429496= 7297"]; >> + for input in range_error_inputs { >> + assert_eq!( >> + verify_zfs_recordsize(input).unwrap_err().to_string(), >> + range_error >> + ); >> + } >> + >> + let format_error_inputs =3D ["0", "k12", "16g", "1.5m", "-512",= "0512"]; >> + for input in format_error_inputs { >> + assert_eq!( >> + verify_zfs_recordsize(input).unwrap_err().to_string(), >> + format_error >> + ); >> + } >> + } >> +} > > thanks for adding a test too!