From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id C0C3E1FF164
	for <inbox@lore.proxmox.com>; Fri,  3 Jan 2025 16:59:29 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id B038B290B7;
	Fri,  3 Jan 2025 16:58:19 +0100 (CET)
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Fri,  3 Jan 2025 16:57:53 +0100
Message-Id: <20250103155802.143669-11-f.ebner@proxmox.com>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20250103155802.143669-1-f.ebner@proxmox.com>
References: <20250103155802.143669-1-f.ebner@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.051 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 qemu-server 10/19] move get_vm_machine()
 function to machine module
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 PVE/API2/Qemu.pm          |  2 +-
 PVE/QemuServer.pm         | 38 ++------------------------------------
 PVE/QemuServer/Machine.pm | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 37 insertions(+), 37 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 528fc261..4ad9165a 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -851,7 +851,7 @@ sub assert_scsi_feature_compatibility {
 
     my $drive = PVE::QemuServer::Drive::parse_drive($opt, $drive_attributes, 1);
 
-    my $machine_type = PVE::QemuServer::get_vm_machine($conf, undef, $conf->{arch});
+    my $machine_type = PVE::QemuServer::Machine::get_vm_machine($conf, undef, $conf->{arch});
     my $machine_version = PVE::QemuServer::Machine::extract_version(
 	$machine_type, PVE::QemuServer::Helpers::kvm_user_version());
     my $drivetype = PVE::QemuServer::Drive::get_scsi_device_type(
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 6ae524b2..af8712f6 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -3260,40 +3260,6 @@ sub vga_conf_has_spice {
     return $1 || 1;
 }
 
-sub get_vm_machine {
-    my ($conf, $forcemachine, $arch) = @_;
-
-    my $machine_conf = PVE::QemuServer::Machine::parse_machine($conf->{machine});
-    my $machine = $forcemachine || $machine_conf->{type};
-
-    if (!$machine || $machine =~ m/^(?:pc|q35|virt)$/) {
-	my $kvmversion //= kvm_user_version();
-	# we must pin Windows VMs without a specific version to 5.1, as 5.2 fixed a bug in ACPI
-	# 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 = PVE::QemuServer::Machine::windows_get_pinned_machine_version($machine, '5.1', $kvmversion);
-	}
-	$arch //= 'x86_64';
-	$machine ||= PVE::QemuServer::Machine::default_machine_for_arch($arch);
-	my $pvever = PVE::QemuServer::Machine::get_pve_version($kvmversion);
-	$machine .= "+pve$pvever";
-    }
-
-    if ($machine !~ m/\+pve\d+?(?:\.pxe)?$/) {
-	my $is_pxe = $machine =~ m/^(.*?)\.pxe$/;
-	$machine = $1 if $is_pxe;
-
-	# for version-pinned machines that do not include a pve-version (e.g.
-	# pc-q35-4.1), we assume 0 to keep them stable in case we bump
-	$machine .= '+pve0';
-
-	$machine .= '.pxe' if $is_pxe;
-    }
-
-    return $machine;
-}
-
 sub get_ovmf_files($$$) {
     my ($arch, $efidisk, $smm) = @_;
 
@@ -3549,7 +3515,7 @@ sub config_to_command {
 	die "Detected old QEMU binary ('$kvmver', at least 5.0 is required)\n";
     }
 
-    my $machine_type = get_vm_machine($conf, $forcemachine, $arch);
+    my $machine_type = PVE::QemuServer::Machine::get_vm_machine($conf, $forcemachine, $arch);
     my $machine_version = extract_version($machine_type, $kvmver);
     $kvm //= 1 if is_native_arch($arch);
 
@@ -4863,7 +4829,7 @@ sub vmconfig_hotplug_pending {
 
     my $defaults = load_defaults();
     my $arch = PVE::QemuServer::Helpers::get_vm_arch($conf);
-    my $machine_type = get_vm_machine($conf, undef, $arch);
+    my $machine_type = PVE::QemuServer::Machine::get_vm_machine($conf, undef, $arch);
 
     # commit values which do not have any impact on running VM first
     # Note: those option cannot raise errors, we we do not care about
diff --git a/PVE/QemuServer/Machine.pm b/PVE/QemuServer/Machine.pm
index 04c77ed5..915913c0 100644
--- a/PVE/QemuServer/Machine.pm
+++ b/PVE/QemuServer/Machine.pm
@@ -213,4 +213,38 @@ sub windows_get_pinned_machine_version {
     return $machine;
 }
 
+sub get_vm_machine {
+    my ($conf, $forcemachine, $arch) = @_;
+
+    my $machine_conf = parse_machine($conf->{machine});
+    my $machine = $forcemachine || $machine_conf->{type};
+
+    if (!$machine || $machine =~ m/^(?:pc|q35|virt)$/) {
+	my $kvmversion //= PVE::QemuServer::Helpers::kvm_user_version();
+	# we must pin Windows VMs without a specific version to 5.1, as 5.2 fixed a bug in ACPI
+	# 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 (PVE::QemuServer::Helpers::windows_version($conf->{ostype})) {
+	    $machine = windows_get_pinned_machine_version($machine, '5.1', $kvmversion);
+	}
+	$arch //= 'x86_64';
+	$machine ||= default_machine_for_arch($arch);
+	my $pvever = get_pve_version($kvmversion);
+	$machine .= "+pve$pvever";
+    }
+
+    if ($machine !~ m/\+pve\d+?(?:\.pxe)?$/) {
+	my $is_pxe = $machine =~ m/^(.*?)\.pxe$/;
+	$machine = $1 if $is_pxe;
+
+	# for version-pinned machines that do not include a pve-version (e.g.
+	# pc-q35-4.1), we assume 0 to keep them stable in case we bump
+	$machine .= '+pve0';
+
+	$machine .= '.pxe' if $is_pxe;
+    }
+
+    return $machine;
+}
+
 1;
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel