[pve-devel] [PATCH qemu-server v2 3/8] cpu config: introduce is_abstracted() helper
Fiona Ebner
f.ebner at proxmox.com
Fri Nov 7 15:43:41 CET 2025
The helper reports whether the CPU configuration cannot be determined
from the configuration alone. Currently, this means using a custom
model, because that depends on the contents of the custom model
configuration. The next commit will add an abstract flag that depends
on the host.
Note that parse_property_string() returns a hash reference or fails,
so there is no need to check its return value for evaluating to true
in boolean context. Even if the check were necessary, having no result
should be treated as a failure, not quietly ignored.
Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---
New in v2.
src/PVE/QemuMigrate.pm | 11 +++--------
src/PVE/QemuServer/CPUConfig.pm | 25 +++++++++++++++++++++++++
2 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/src/PVE/QemuMigrate.pm b/src/PVE/QemuMigrate.pm
index 78954c20..063fd6f2 100644
--- a/src/PVE/QemuMigrate.pm
+++ b/src/PVE/QemuMigrate.pm
@@ -226,14 +226,9 @@ sub prepare {
$self->{forcemachine} = PVE::QemuServer::Machine::qemu_machine_pxe($vmid, $conf);
- # To support custom CPU types, we keep QEMU's "-cpu" parameter intact.
- # Since the parameter itself contains no reference to a custom model,
- # this makes migration independent of changes to "cpu-models.conf".
- if ($conf->{cpu}) {
- my $cpuconf = PVE::JSONSchema::parse_property_string('pve-cpu-conf', $conf->{cpu});
- if ($cpuconf && PVE::QemuServer::CPUConfig::is_custom_model($cpuconf->{cputype})) {
- $self->{forcecpu} = PVE::QemuServer::CPUConfig::get_cpu_from_running_vm($pid);
- }
+ # To support abstracted CPU configurations, keep QEMU's "-cpu" parameter intact.
+ if ($conf->{cpu} && PVE::QemuServer::CPUConfig::is_abstracted($conf->{cpu})) {
+ $self->{forcecpu} = PVE::QemuServer::CPUConfig::get_cpu_from_running_vm($pid);
}
# Do not treat a suspended VM as paused, as it might wake up
diff --git a/src/PVE/QemuServer/CPUConfig.pm b/src/PVE/QemuServer/CPUConfig.pm
index ebec42d5..4cbd7b48 100644
--- a/src/PVE/QemuServer/CPUConfig.pm
+++ b/src/PVE/QemuServer/CPUConfig.pm
@@ -567,6 +567,31 @@ sub print_cpu_device {
return "$cpu-x86_64-cpu,id=cpu$id,socket-id=$current_socket,core-id=$current_core,thread-id=0";
}
+=head3 is_abstracted
+
+ if (is_abstracted($conf->{cpu})) {
+ # better check running CPU of QEMU instance
+ }
+
+Check if the configured CPU is abstracted in any way, meaning that the actual CPU model cannot be
+determined from the configuration alone. Possible abstractions:
+
+=over
+
+=item custom model: can change with updates to the custom model configuration
+
+=back
+
+=cut
+
+sub is_abstracted {
+ my ($cpu_property_string) = @_;
+
+ my $cpu_conf = PVE::JSONSchema::parse_property_string('pve-cpu-conf', $cpu_property_string);
+
+ return is_custom_model($cpu_conf->{cputype});
+}
+
# Resolves multiple arrays of hashes representing CPU flags with metadata to a
# single string in QEMU "-cpu" compatible format. Later arrays have higher
# priority.
--
2.47.3
More information about the pve-devel
mailing list