[pve-devel] [PATCH qemu-server 2/6] machine: get current: make it clear that pve-version only exists for the current machine

Fiona Ebner f.ebner at proxmox.com
Fri Nov 10 14:24:47 CET 2023


by adding a comment and grouping the code better. See the PVE QEMU
patch "PVE: Allow version code in machine type" for reference. The way
the code was written previously made it look like a bug where
$pve_version might be overwritten multiple times.

Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---
 PVE/QemuServer/Machine.pm | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/PVE/QemuServer/Machine.pm b/PVE/QemuServer/Machine.pm
index a4bc24a5..85cfb89c 100644
--- a/PVE/QemuServer/Machine.pm
+++ b/PVE/QemuServer/Machine.pm
@@ -21,14 +21,16 @@ sub machine_type_is_q35 {
 sub current_from_query_machines {
     my ($machines) = @_;
 
-    my ($current, $pve_version, $default);
+    my ($current, $default);
     for my $machine ($machines->@*) {
 	$default = $machine->{name} if $machine->{'is-default'};
-	$current = $machine->{name} if $machine->{'is-current'};
-	$pve_version = $machine->{'pve-version'} if $machine->{'pve-version'};
-    }
 
-    $current .= "+$pve_version" if $current && $pve_version;
+	if ($machine->{'is-current'}) {
+	    $current = $machine->{name};
+	    # pve-version only exists for the current machine
+	    $current .= "+$machine->{'pve-version'}" if $machine->{'pve-version'};
+	}
+    }
 
     # fallback to the default machine if current is not supported by qemu
     return $current || $default || 'pc';
-- 
2.39.2






More information about the pve-devel mailing list