[pve-devel] [PATCH qemu-server v3 09/18] move windows_get_pinned_machine_version() function to machine module

Fiona Ebner f.ebner at proxmox.com
Fri Jan 17 13:08:08 CET 2025


Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---
 PVE/API2/Qemu.pm          |  3 ++-
 PVE/QemuServer.pm         | 24 +-----------------------
 PVE/QemuServer/Machine.pm | 20 ++++++++++++++++++++
 3 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 2840de1b..8d0d788f 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -1246,7 +1246,8 @@ __PACKAGE__->register_method({
 		    if (!$machine || $machine =~ m/^(?:pc|q35|virt)$/) {
 			# always pin Windows' machine version on create, they get to easily confused
 			if (PVE::QemuServer::Helpers::windows_version($conf->{ostype})) {
-			    $machine_conf->{type} = PVE::QemuServer::windows_get_pinned_machine_version($machine);
+			    $machine_conf->{type} =
+				PVE::QemuServer::Machine::windows_get_pinned_machine_version($machine);
 			    $conf->{machine} = PVE::QemuServer::Machine::print_machine($machine_conf);
 			}
 		    }
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index ee7bb017..989fafbd 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -3271,28 +3271,6 @@ sub vga_conf_has_spice {
     return $1 || 1;
 }
 
-sub windows_get_pinned_machine_version {
-    my ($machine, $base_version, $kvmversion) = @_;
-
-    my $pin_version = $base_version;
-    if (!defined($base_version) ||
-	!PVE::QemuServer::Machine::can_run_pve_machine_version($base_version, $kvmversion)
-    ) {
-	$pin_version = PVE::QemuServer::Machine::get_installed_machine_version($kvmversion);
-    }
-    if (!$machine || $machine eq 'pc') {
-	$machine = "pc-i440fx-$pin_version";
-    } elsif ($machine eq 'q35') {
-	$machine = "pc-q35-$pin_version";
-    } elsif ($machine eq 'virt') {
-	$machine = "virt-$pin_version";
-    } else {
-	warn "unknown machine type '$machine', not touching that!\n";
-    }
-
-    return $machine;
-}
-
 sub get_vm_machine {
     my ($conf, $forcemachine, $arch) = @_;
 
@@ -3305,7 +3283,7 @@ sub get_vm_machine {
 	# layout which confuses windows quite a bit and may result in various regressions..
 	# see: https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg08484.html
 	if (windows_version($conf->{ostype})) {
-	    $machine = windows_get_pinned_machine_version($machine, '5.1', $kvmversion);
+	    $machine = PVE::QemuServer::Machine::windows_get_pinned_machine_version($machine, '5.1', $kvmversion);
 	}
 	$arch //= 'x86_64';
 	$machine ||= PVE::QemuServer::Machine::default_machine_for_arch($arch);
diff --git a/PVE/QemuServer/Machine.pm b/PVE/QemuServer/Machine.pm
index 075554f4..04c77ed5 100644
--- a/PVE/QemuServer/Machine.pm
+++ b/PVE/QemuServer/Machine.pm
@@ -193,4 +193,24 @@ sub get_installed_machine_version {
     return $1;
 }
 
+sub windows_get_pinned_machine_version {
+    my ($machine, $base_version, $kvmversion) = @_;
+
+    my $pin_version = $base_version;
+    if (!defined($base_version) || !can_run_pve_machine_version($base_version, $kvmversion)) {
+	$pin_version = get_installed_machine_version($kvmversion);
+    }
+    if (!$machine || $machine eq 'pc') {
+	$machine = "pc-i440fx-$pin_version";
+    } elsif ($machine eq 'q35') {
+	$machine = "pc-q35-$pin_version";
+    } elsif ($machine eq 'virt') {
+	$machine = "virt-$pin_version";
+    } else {
+	warn "unknown machine type '$machine', not touching that!\n";
+    }
+
+    return $machine;
+}
+
 1;
-- 
2.39.5





More information about the pve-devel mailing list