Add the option to control the size of the qcow2 L2/refcount cache in the vm disk create and edit dialogs. This enables huge performance gains in some vm configurations.
For a detailed explanation see the QEMU docs [0]. Currently only the cache-size is configurable in the frontend, either directly or based on the size of the disk. [0] https://gitlab.com/qemu-project/qemu/-/blob/master/docs/qcow2-cache.txt Signed-off-by: Erik Fastermann <[email protected]> --- www/manager6/Parser.js | 2 +- www/manager6/qemu/HDEdit.js | 70 +++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/www/manager6/Parser.js b/www/manager6/Parser.js index 36df8e9d..90467316 100644 --- a/www/manager6/Parser.js +++ b/www/manager6/Parser.js @@ -207,7 +207,7 @@ Ext.define('PVE.Parser', { if (!p || p.match(/^\s*$/)) { return undefined; // continue } - let match = p.match(/^([a-z_]+)=(\S+)$/); + let match = p.match(/^([0-9a-z_]+)=(\S+)$/); if (!match) { if (!p.match(/[=]/)) { res.file = p; diff --git a/www/manager6/qemu/HDEdit.js b/www/manager6/qemu/HDEdit.js index 1bb2bfda..401b8032 100644 --- a/www/manager6/qemu/HDEdit.js +++ b/www/manager6/qemu/HDEdit.js @@ -18,6 +18,8 @@ Ext.define('PVE.qemu.HDInputPanel', { isSCSI: false, isVirtIO: false, isSCSISingle: false, + isQcow2: false, + cacheSizeBasedOnDisk: false, }, }, @@ -54,6 +56,22 @@ Ext.define('PVE.qemu.HDInputPanel', { vm.set('isSCSISingle', value === 'virtio-scsi-single'); }, }, + 'field[name=diskformat]': { + change: function (f, value) { + this.getViewModel().set('isQcow2', value === 'qcow2'); + }, + afterrender: function (f) { + this.getViewModel().set('isQcow2', f.getValue() === 'qcow2'); + }, + }, + 'field[name=cacheSizeBasedOnDisk]': { + change: function (f, value) { + this.getViewModel().set('cacheSizeBasedOnDisk', value); + }, + afterrender: function (f) { + this.getViewModel().set('cacheSizeBasedOnDisk', f.getValue()); + }, + }, }, init: function (view) { @@ -88,6 +106,16 @@ Ext.define('PVE.qemu.HDInputPanel', { me.drive.format = values.diskformat; } + if (me.drive?.format === 'qcow2' || me.drive?.file?.endsWith('.qcow2')) { + if (values.cacheSizeBasedOnDisk) { + me.drive.cache_size = 'based-on-disk'; + } else if (values.cacheSize) { + me.drive.cache_size = values.cacheSize; + } else { + delete me.drive.cache_size; + } + } + PVE.Utils.propertyStringSet(me.drive, !values.backup, 'backup', '0'); PVE.Utils.propertyStringSet(me.drive, values.noreplicate, 'replicate', 'no'); PVE.Utils.propertyStringSet(me.drive, values.discard, 'discard', 'on'); @@ -157,6 +185,14 @@ Ext.define('PVE.qemu.HDInputPanel', { values.readOnly = PVE.Parser.parseBoolean(drive.ro); values.aio = drive.aio || '__default__'; + if (drive.cache_size === 'based-on-disk') { + values.cacheSizeBasedOnDisk = true; + values.cacheSize = undefined; + } else { + values.cacheSizeBasedOnDisk = false; + values.cacheSize = drive.cache_size; + } + values.mbps_rd = drive.mbps_rd; values.mbps_wr = drive.mbps_wr; values.iops_rd = drive.iops_rd; @@ -167,6 +203,12 @@ Ext.define('PVE.qemu.HDInputPanel', { values.iops_wr_max = drive.iops_wr_max; me.setValues(values); + + me.getViewModel().set( + 'isQcow2', + values.diskformat === 'qcow2' || values.hdimage?.endsWith('.qcow2'), + ); + this.getViewModel().set('cacheSizeBasedOnDisk', values.cacheSizeBasedOnDisk); }, setNodename: function (nodename) { @@ -355,6 +397,34 @@ Ext.define('PVE.qemu.HDInputPanel', { disabled: '{!isVirtIO && !isSCSI}', }, }, + { + xtype: 'numberfield', + name: 'cacheSize', + minValue: 1, + step: 1024 * 1024, + fieldLabel: gettext('Cache size'), + emptyText: gettext('Default cache size'), + bind: { + disabled: '{!isQcow2 || cacheSizeBasedOnDisk}', + }, + listeners: { + disable: function (field) { + console.log(field); + field.setValue(null); + }, + }, + }, + { + xtype: 'proxmoxcheckbox', + name: 'cacheSizeBasedOnDisk', + reference: 'cacheSizeBasedOnDisk', + defaultValue: 0, + fieldLabel: gettext('Cache size based on disk'), + clearOnDisable: true, + bind: { + disabled: '{!isQcow2}', + }, + }, ); advancedColumn2.push( -- 2.47.3
