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 9B9C61FF146 for ; Tue, 12 May 2026 15:49:57 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 73062152DF; Tue, 12 May 2026 15:49:57 +0200 (CEST) From: David Riley To: pve-devel@lists.proxmox.com Subject: [PATCH pve-storage 2/2] fix #3936: api: add zfs-blocksize format Date: Tue, 12 May 2026 15:48:52 +0200 Message-ID: <20260512134852.142044-3-d.riley@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260512134852.142044-1-d.riley@proxmox.com> References: <20260512134852.142044-1-d.riley@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1778593643531 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.330 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 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: LTKPPI65RHXNK6ZK22AYUATV3DEDTFIK X-Message-ID-Hash: LTKPPI65RHXNK6ZK22AYUATV3DEDTFIK X-MailFrom: d.riley@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 CC: David Riley X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Add a new JSONSchema format pve-storage-zfs-blocksize to validate the ZFS blocksize parameter. Validation [0][1]: * Range: 512 bytes to 16 MiB * Format: Allow positive integers with optional 'k' or 'm' suffix. * Constraint: Must be a power of two. Link: https://bugzilla.proxmox.com/show_bug.cgi?id=3936 [0] https://openzfs.github.io/openzfs-docs/man/v2.4/7/zfsprops.7.html#volblocksize [1] https://openzfs.github.io/openzfs-docs/man/v2.4/7/zfsprops.7.html#recordsize Signed-off-by: David Riley --- src/PVE/Storage/Plugin.pm | 34 ++++++++++++++++++++++++++++++++ src/PVE/Storage/ZFSPoolPlugin.pm | 1 + 2 files changed, 35 insertions(+) diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm index afd3141..486fab9 100644 --- a/src/PVE/Storage/Plugin.pm +++ b/src/PVE/Storage/Plugin.pm @@ -449,6 +449,40 @@ sub verify_dir_override { die "invalid override '$value'\n"; } +PVE::JSONSchema::register_format('pve-storage-zfs-blocksize', \&verify_zfs_blocksize); + +sub verify_zfs_blocksize { + my ($value, $noerr) = @_; + + return $value if !defined($value) || $value eq ''; + + if ($value =~ m/^([1-9][0-9]*)([km])?$/i) { + my ($num, $unit) = ($1, lc($2 // '')); + + if ($unit eq 'k') { + $num *= 1024; + } elsif ($unit eq 'm') { + $num *= 1024 * 1024; + } + + if ( + $num >= 512 + && $num <= 16 * 1024 * 1024 + && ($num & ($num - 1)) == 0 + ) { + return $value; + } + + return undef if $noerr; + die "value '$value' is not a valid ZFS blocksize. Must be a power of 2 " + . "between 512B and 16MiB (e.g., 4k, 8k, 16k, 64k, 1m).\n"; + } + + return undef if $noerr; + die "invalid ZFS blocksize format '$value'. Use a positive number " + . "(no leading zeros) with an optional 'k' or 'm' suffix.\n"; +} + sub private { return $defaultData; } diff --git a/src/PVE/Storage/ZFSPoolPlugin.pm b/src/PVE/Storage/ZFSPoolPlugin.pm index fcd7804..6a64401 100644 --- a/src/PVE/Storage/ZFSPoolPlugin.pm +++ b/src/PVE/Storage/ZFSPoolPlugin.pm @@ -31,6 +31,7 @@ sub properties { blocksize => { description => "block size", type => 'string', + format => 'pve-storage-zfs-blocksize', }, sparse => { description => "use sparse volumes", -- 2.47.3