all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH pve-manager v2] fix #3936: ui: storage: add validation for ZFS blocksize
@ 2026-05-15  7:51 David Riley
  2026-05-18 10:25 ` Thomas Lamprecht
  0 siblings, 1 reply; 2+ messages in thread
From: David Riley @ 2026-05-15  7:51 UTC (permalink / raw)
  To: pve-devel; +Cc: David Riley

Add validation to the ZFS storage blocksize form field to prevent
misconfigurations.

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

Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
Signed-off-by: David Riley <d.riley@proxmox.com>
---

Notes:
    v2:
    * Renamed function to follow the style guide (camelCase)
    * combined checks power-of-two and range check
    * Adapted error message

 www/manager6/Utils.js               | 28 ++++++++++++++++++++++++++++
 www/manager6/storage/ZFSEdit.js     |  1 +
 www/manager6/storage/ZFSPoolEdit.js |  1 +
 3 files changed, 30 insertions(+)

diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
index 01e80682..2ed4e65d 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -274,6 +274,34 @@ Ext.define('PVE.Utils', {
             return '<i class="fa fa-' + iconCls + '"></i> ' + value;
         },
 
+        validateZfsBlocksize: function (value) {
+            if (!value) {
+                return true;
+            }
+
+            let match = value.match(/^([1-9][0-9]*)([km])?$/i);
+            if (!match) {
+                return gettext(
+                    'Invalid format. Use numbers with optional k or m suffix (e.g., 16k).',
+                );
+            }
+
+            let bytes = parseInt(match[1], 10);
+            let suffix = match[2]?.toLowerCase();
+
+            if (suffix === 'k') {
+                bytes *= 1024;
+            } else if (suffix === 'm') {
+                bytes *= 1024 * 1024;
+            }
+
+            if (bytes < 512 || (bytes & (bytes - 1)) !== 0 || bytes > 16 * 1024 * 1024) {
+                return gettext('Value must be a power of 2 between 512 and 16m');
+            }
+
+            return true;
+        },
+
         render_pbs_fingerprint: (fp) => fp.substring(0, 23),
 
         render_backup_encryption: function (v, meta, record) {
diff --git a/www/manager6/storage/ZFSEdit.js b/www/manager6/storage/ZFSEdit.js
index e9d24642..0d7a971c 100644
--- a/www/manager6/storage/ZFSEdit.js
+++ b/www/manager6/storage/ZFSEdit.js
@@ -67,6 +67,7 @@ Ext.define('PVE.storage.ZFSInputPanel', {
                 value: '4k',
                 fieldLabel: gettext('Block Size'),
                 allowBlank: false,
+                validator: PVE.Utils.validateZfsBlocksize,
             },
             {
                 xtype: me.isCreate ? 'textfield' : 'displayfield',
diff --git a/www/manager6/storage/ZFSPoolEdit.js b/www/manager6/storage/ZFSPoolEdit.js
index 0066dfef..6789b9a3 100644
--- a/www/manager6/storage/ZFSPoolEdit.js
+++ b/www/manager6/storage/ZFSPoolEdit.js
@@ -106,6 +106,7 @@ Ext.define('PVE.storage.ZFSPoolInputPanel', {
             emptyText: '16k',
             fieldLabel: gettext('Block Size'),
             allowBlank: true,
+            validator: PVE.Utils.validateZfsBlocksize,
         },
     ],
 });
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-05-18 10:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-15  7:51 [PATCH pve-manager v2] fix #3936: ui: storage: add validation for ZFS blocksize David Riley
2026-05-18 10:25 ` Thomas Lamprecht

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