[pve-devel] [PATCH manager v5 5/5] ui: MachineEdit with viommu checkbox

Markus Frank m.frank at proxmox.com
Wed Jan 18 14:58:00 CET 2023


Added a checkbox to enable viommu, if q35 is selected.
Otherwise (i440fx & !kvm) the checkbox is disabled, if not ticked on
before. If ticked on before, the user is able to uncheck the checkbox.

If kvm is deactivated or i440fx is selected, a hint tells that q35 and
kvm are required for vIOMMU.

The UI also needs to parse the new machine parameter as PropertyString.

Signed-off-by: Markus Frank <m.frank at proxmox.com>
---
 www/manager6/qemu/MachineEdit.js | 58 ++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/www/manager6/qemu/MachineEdit.js b/www/manager6/qemu/MachineEdit.js
index f928c80c..d7650ea9 100644
--- a/www/manager6/qemu/MachineEdit.js
+++ b/www/manager6/qemu/MachineEdit.js
@@ -1,6 +1,7 @@
 Ext.define('PVE.qemu.MachineInputPanel', {
     extend: 'Proxmox.panel.InputPanel',
     xtype: 'pveMachineInputPanel',
+    onlineHelp: 'qm_pci_viommu',
 
     controller: {
 	xclass: 'Ext.app.ViewController',
@@ -12,11 +13,26 @@ Ext.define('PVE.qemu.MachineInputPanel', {
 	onMachineChange: function(field, value) {
 	    let me = this;
 	    let version = me.lookup('version');
+	    let kvm = me.lookup('kvm');
+	    let viommu = me.lookup('viommu');
+	    let kvmHint = me.lookup('kvmQ35Hint');
 	    let store = version.getStore();
 	    let oldRec = store.findRecord('id', version.getValue(), 0, false, false, true);
 	    let type = value === 'q35' ? 'q35' : 'i440fx';
 	    store.clearFilter();
 	    store.addFilter(val => val.data.id === 'latest' || val.data.type === type);
+	    if ((type === 'q35' && kvm.getValue()) || viommu.getValue()) {
+		viommu.setDisabled(false);
+		kvmHint.setVisible(false);
+	    } else {
+		// disable checkbox if vIOMMU is not possible and checkbox was not
+		// ticked on before
+		viommu.setDisabled(true);
+	    }
+	    if (type === 'i440fx' || !kvm.getValue()) {
+		// show hint when vIOMMU cannot be used
+		kvmHint.setVisible(true);
+	    }
 	    if (!me.getView().isWindows) {
 		version.setValue('latest');
 	    } else {
@@ -38,14 +54,27 @@ Ext.define('PVE.qemu.MachineInputPanel', {
 	if (values.version && values.version !== 'latest') {
 	    values.machine = values.version;
 	    delete values.delete;
+	} else if (values.machine === undefined && values.viommu) {
+	    // set machine to pc to raise the viommu + i440fx error
+	    // from qemu-server instead of a regex error
+	    values.machine = "pc";
+	    delete values.delete;
 	}
 	delete values.version;
+	if (values.viommu) {
+	    values.machine += ",viommu=1";
+	}
+	delete values.viommu;
+	delete values.kvm;
 	return values;
     },
 
     setValues: function(values) {
 	let me = this;
 
+	let machineConf = PVE.Parser.parsePropertyString(values.machine, "type");
+	values.machine = machineConf.type;
+
 	me.isWindows = values.isWindows;
 	if (values.machine === 'pc') {
 	    values.machine = '__default__';
@@ -58,6 +87,11 @@ Ext.define('PVE.qemu.MachineInputPanel', {
 		values.version = 'pc-q35-5.1';
 	    }
 	}
+
+	me.lookup('kvm').setValue(values.kvm);
+	values.viommu = machineConf.viommu === '1';
+	me.lookup('viommu').setValue(values.viommu);
+
 	if (values.machine !== '__default__' && values.machine !== 'q35') {
 	    values.version = values.machine;
 	    values.machine = values.version.match(/q35/) ? 'q35' : '__default__';
@@ -113,6 +147,26 @@ Ext.define('PVE.qemu.MachineInputPanel', {
 	    fieldLabel: gettext('Note'),
 	    value: gettext('Machine version change may affect hardware layout and settings in the guest OS.'),
 	},
+	{
+	    xtype: 'proxmoxcheckbox',
+	    fieldLabel: gettext('vIOMMU'),
+	    name: 'viommu',
+	    reference: 'viommu',
+	},
+	{
+	    xtype: 'proxmoxcheckbox',
+	    name: 'kvm',
+	    reference: 'kvm',
+	    hidden: true,
+	},
+	{
+	    xtype: 'displayfield',
+	    name: 'kvmQ35Hint',
+	    reference: 'kvmQ35Hint',
+	    userCls: 'pmx-hint',
+	    value: gettext('vIOMMU needs kvm enabled and q35 firmware'),
+	    hidden: true,
+	},
     ],
 });
 
@@ -135,8 +189,12 @@ Ext.define('PVE.qemu.MachineEdit', {
 	me.load({
 	    success: function(response) {
 		let conf = response.result.data;
+		if (conf.kvm === undefined || conf.kvm === null) {
+		    conf.kvm = 1;
+		}
 		let values = {
 		    machine: conf.machine || '__default__',
+		    kvm: conf.kvm,
 		};
 		values.isWindows = PVE.Utils.is_windows(conf.ostype);
 		me.setValues(values);
-- 
2.30.2






More information about the pve-devel mailing list