all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: David Riley <d.riley@proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: David Riley <d.riley@proxmox.com>
Subject: [PATCH pve-storage 2/2] fix #3936: api: add zfs-blocksize format
Date: Tue, 12 May 2026 15:48:52 +0200	[thread overview]
Message-ID: <20260512134852.142044-3-d.riley@proxmox.com> (raw)
In-Reply-To: <20260512134852.142044-1-d.riley@proxmox.com>

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 <d.riley@proxmox.com>
---
 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





  parent reply	other threads:[~2026-05-12 13:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-12 13:48 [PATCH manager/storage 0/2] fix #3936: add validation for ZFS blocksize David Riley
2026-05-12 13:48 ` [PATCH pve-manager 1/2] fix #3936: ui: storage: " David Riley
2026-05-13 14:05   ` Fiona Ebner
2026-05-15  6:57     ` David Riley
2026-05-12 13:48 ` David Riley [this message]
2026-05-13 14:35   ` applied: [PATCH pve-storage 2/2] fix #3936: api: add zfs-blocksize format Fiona Ebner
2026-05-15  8:00 ` superseded: [PATCH manager/storage 0/2] fix #3936: add validation for ZFS blocksize David Riley

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=20260512134852.142044-3-d.riley@proxmox.com \
    --to=d.riley@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal