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 DBD091FF15C for ; Fri, 31 Oct 2025 13:28:57 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4C78F10BC5; Fri, 31 Oct 2025 13:29:15 +0100 (CET) From: Fiona Ebner To: pve-devel@lists.proxmox.com Date: Fri, 31 Oct 2025 13:27:43 +0100 Message-ID: <20251031122834.62482-8-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251031122834.62482-1-f.ebner@proxmox.com> References: <20251031122834.62482-1-f.ebner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1761913704537 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.020 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 Subject: [pve-devel] [PATCH manager 7/7] ui: cpu flag selector: query CPU flag list via API X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" There is coupling between the store and value for the top-level grid, which has a field mixin. Becuase of this, the setValue() method needs to update the 'state' value for the records in the store accordingly. This can however only be done if the store is already loaded, so the store gets a refresh() callback. It also remembers which value it was already adjusted for for potential subsequent setValue() calls. Signed-off-by: Fiona Ebner --- Happy to hear suggestions if this is too involved already! The grid itself is a field (via mixin) and the 'state' values in the store are coupled with the field value, so I couldn't figure out a simpler way yet. www/manager6/form/VMCPUFlagSelector.js | 100 +++++++++++-------------- 1 file changed, 42 insertions(+), 58 deletions(-) diff --git a/www/manager6/form/VMCPUFlagSelector.js b/www/manager6/form/VMCPUFlagSelector.js index 2dbc21dc..1bd5a60f 100644 --- a/www/manager6/form/VMCPUFlagSelector.js +++ b/www/manager6/form/VMCPUFlagSelector.js @@ -18,63 +18,43 @@ Ext.define('PVE.form.VMCPUFlagSelector', { store: { type: 'store', - fields: ['flag', { name: 'state', defaultValue: '=' }, 'desc'], - data: [ - // FIXME: let qemu-server host this and autogenerate or get from API call?? - { - flag: 'md-clear', - desc: 'Required to let the guest OS know if MDS is mitigated correctly', - }, - { - flag: 'pcid', - desc: 'Meltdown fix cost reduction on Westmere, Sandy-, and IvyBridge Intel CPUs', - }, - { flag: 'spec-ctrl', desc: 'Allows improved Spectre mitigation with Intel CPUs' }, - { flag: 'ssbd', desc: 'Protection for "Speculative Store Bypass" for Intel models' }, - { flag: 'ibpb', desc: 'Allows improved Spectre mitigation with AMD CPUs' }, - { - flag: 'virt-ssbd', - desc: 'Basis for "Speculative Store Bypass" protection for AMD models', - }, - { - flag: 'amd-ssbd', - desc: 'Improves Spectre mitigation performance with AMD CPUs, best used with "virt-ssbd"', - }, - { - flag: 'amd-no-ssb', - desc: 'Notifies guest OS that host is not vulnerable for Spectre on AMD CPUs', - }, - { - flag: 'pdpe1gb', - desc: 'Allow guest OS to use 1GB size pages, if host HW supports it', - }, - { - flag: 'hv-tlbflush', - desc: 'Improve performance in overcommitted Windows guests. May lead to guest bluescreens on old CPUs.', - }, - { - flag: 'hv-evmcs', - desc: 'Improve performance for nested virtualization. Only supported on Intel CPUs.', - }, - { flag: 'aes', desc: 'Activate AES instruction set for HW acceleration.' }, - ], + fields: ['name', { name: 'state', defaultValue: '=' }, 'description'], + autoLoad: true, + proxy: { + type: 'proxmox', + url: '/api2/json/nodes/localhost/capabilities/qemu/cpu-flags', + }, listeners: { update: function () { this.commitChanges(); }, + refresh: function (store, eOpts) { + let me = this; + let view = me.view; + + if (store.adjustedForValue !== view.value) { + view.adjustStoreForValue(); + } + }, }, + adjustedForValue: undefined, }, getValue: function () { let me = this; let store = me.getStore(); + + if (!store.isLoaded()) { + return me.value; + } + let flags = ''; // ExtJS does not has a nice getAllRecords interface for stores :/ store.queryBy(Ext.returnTrue).each(function (rec) { let s = rec.get('state'); if (s && s !== '=') { - let f = rec.get('flag'); + let f = rec.get('name'); if (flags === '') { flags = s + f; } else { @@ -88,33 +68,41 @@ Ext.define('PVE.form.VMCPUFlagSelector', { return flags; }, - setValue: function (value) { + // Adjusts the store for the current value and determines the unkown flags based on what the + // store does not know. + adjustStoreForValue: function () { let me = this; let store = me.getStore(); - - me.value = value || ''; + let value = me.value; me.unkownFlags = []; - me.getStore() - .queryBy(Ext.returnTrue) - .each(function (rec) { - rec.set('state', '='); - }); + store.queryBy(Ext.returnTrue).each((rec) => rec.set('state', '=')); let flags = value ? value.split(';') : []; flags.forEach(function (flag) { let sign = flag.substr(0, 1); flag = flag.substr(1); - let rec = store.findRecord('flag', flag, 0, false, true, true); + let rec = store.findRecord('name', flag, 0, false, true, true); if (rec !== null) { rec.set('state', sign); } else { me.unkownFlags.push(flag); } }); - store.reload(); + + store.adjustedForValue = value; + }, + + setValue: function (value) { + let me = this; + + me.value = value || ''; + + if (me.getStore().isLoaded()) { + me.adjustForValue(); + } // if not yet loaded, the store will trigger the function let res = me.mixins.field.setValue.call(me, value); @@ -184,11 +172,11 @@ Ext.define('PVE.form.VMCPUFlagSelector', { }, }, { - dataIndex: 'flag', + dataIndex: 'name', width: 100, }, { - dataIndex: 'desc', + dataIndex: 'description', cellWrap: true, flex: 1, }, @@ -197,12 +185,8 @@ Ext.define('PVE.form.VMCPUFlagSelector', { initComponent: function () { let me = this; - // static class store, thus gets not recreated, so ensure defaults are set! - me.getStore().data.forEach(function (v) { - v.state = '='; - }); - me.value = me.originalValue = ''; + me.store.view = me; me.callParent(arguments); }, -- 2.47.3 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel