all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH qemu-server v4 02/16] move get_command_for_arch() helper to helpers module
Date: Fri, 17 Jan 2025 15:24:16 +0100	[thread overview]
Message-ID: <20250117142430.99484-3-f.ebner@proxmox.com> (raw)
In-Reply-To: <20250117142430.99484-1-f.ebner@proxmox.com>

Cannot use the is_native_arch() helper inside the function anymore,
to avoid a cyclic dependency between the 'CPUConfig' and 'Helpers'
modules, inline it.

While at it, improve the variable name for the mapping.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---

Changes in v4:
* add import for get_host_arch()
* squash rename from following patch into this one

 PVE/QemuServer.pm         | 19 +++----------------
 PVE/QemuServer/Helpers.pm | 14 ++++++++++++++
 2 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index bc38fb1b..ce962b7a 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -1199,7 +1199,7 @@ my $kvm_mtime = {};
 sub kvm_user_version {
     my ($binary) = @_;
 
-    $binary //= get_command_for_arch(get_host_arch()); # get the native arch by default
+    $binary //= PVE::QemuServer::Helpers::get_command_for_arch(get_host_arch()); # get the native arch by default
     my $st = stat($binary);
 
     my $cachedmtime = $kvm_mtime->{$binary} // -1;
@@ -3397,19 +3397,6 @@ sub get_ovmf_files($$$) {
     return ($ovmf_code, $ovmf_vars);
 }
 
-my $Arch2Qemu = {
-    aarch64 => '/usr/bin/qemu-system-aarch64',
-    x86_64 => '/usr/bin/qemu-system-x86_64',
-};
-sub get_command_for_arch($) {
-    my ($arch) = @_;
-    return '/usr/bin/kvm' if is_native_arch($arch);
-
-    my $cmd = $Arch2Qemu->{$arch}
-	or die "don't know how to emulate architecture '$arch'\n";
-    return $cmd;
-}
-
 # To use query_supported_cpu_flags and query_understood_cpu_flags to get flags
 # to use in a QEMU command line (-cpu element), first array_intersect the result
 # of query_supported_ with query_understood_. This is necessary because:
@@ -3444,7 +3431,7 @@ sub query_supported_cpu_flags {
 	$arch eq "aarch64";
 
     my $kvm_supported = defined(kvm_version());
-    my $qemu_cmd = get_command_for_arch($arch);
+    my $qemu_cmd = PVE::QemuServer::Helpers::get_command_for_arch($arch);
     my $fakevmid = -1;
     my $pidfile = PVE::QemuServer::Helpers::pidfile_name($fakevmid);
 
@@ -3634,7 +3621,7 @@ sub config_to_command {
     my $machine_conf = PVE::QemuServer::Machine::parse_machine($conf->{machine});
 
     my $arch = get_vm_arch($conf);
-    my $kvm_binary = get_command_for_arch($arch);
+    my $kvm_binary = PVE::QemuServer::Helpers::get_command_for_arch($arch);
     my $kvmver = kvm_user_version($kvm_binary);
 
     if (!$kvmver || $kvmver !~ m/^(\d+)\.(\d+)/ || $1 < 5) {
diff --git a/PVE/QemuServer/Helpers.pm b/PVE/QemuServer/Helpers.pm
index 72a46a0a..7b65ba44 100644
--- a/PVE/QemuServer/Helpers.pm
+++ b/PVE/QemuServer/Helpers.pm
@@ -8,6 +8,7 @@ use JSON;
 
 use PVE::INotify;
 use PVE::ProcFSTools;
+use PVE::Tools qw(get_host_arch);
 
 use base 'Exporter';
 our @EXPORT_OK = qw(
@@ -19,6 +20,19 @@ windows_version
 
 my $nodename = PVE::INotify::nodename();
 
+my $arch_to_qemu_binary = {
+    aarch64 => '/usr/bin/qemu-system-aarch64',
+    x86_64 => '/usr/bin/qemu-system-x86_64',
+};
+sub get_command_for_arch($) {
+    my ($arch) = @_;
+    return '/usr/bin/kvm' if get_host_arch() eq $arch; # i.e. native arch
+
+    my $cmd = $arch_to_qemu_binary->{$arch}
+	or die "don't know how to emulate architecture '$arch'\n";
+    return $cmd;
+}
+
 # Paths and directories
 
 our $var_run_tmpdir = "/var/run/qemu-server";
-- 
2.39.5



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


  parent reply	other threads:[~2025-01-17 14:24 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-17 14:24 [pve-devel] [PATCH qemu-server/docs v4 00/16] adapt to changes in QEMU machine version deprecation/removal Fiona Ebner
2025-01-17 14:24 ` [pve-devel] [PATCH qemu-server v4 01/16] machine: drop unused parameter from assert_valid_machine_property() helper Fiona Ebner
2025-01-17 14:24 ` Fiona Ebner [this message]
2025-01-17 14:24 ` [pve-devel] [PATCH qemu-server v4 03/16] move kvm_user_version() function to helpers module Fiona Ebner
2025-01-17 14:24 ` [pve-devel] [PATCH qemu-server v4 04/16] move get_vm_arch() helper " Fiona Ebner
2025-01-17 14:24 ` [pve-devel] [PATCH qemu-server v4 05/16] machine: add default_machine_for_arch() helper Fiona Ebner
2025-01-17 14:24 ` [pve-devel] [PATCH qemu-server v4 06/16] move get_installed_machine_version() helper to machine module Fiona Ebner
2025-01-17 14:24 ` [pve-devel] [PATCH qemu-server v4 07/16] move windows_get_pinned_machine_version() function " Fiona Ebner
2025-01-17 14:24 ` [pve-devel] [PATCH qemu-server v4 08/16] move get_vm_machine() " Fiona Ebner
2025-01-17 14:24 ` [pve-devel] [PATCH qemu-server v4 09/16] move meta information handling to its own module Fiona Ebner
2025-01-17 14:24 ` [pve-devel] [PATCH qemu-server v4 10/16] machine: fallback to creation QEMU version for windows starting with 9.1 Fiona Ebner
2025-01-17 14:24 ` [pve-devel] [PATCH qemu-server v4 11/16] machine: add check_and_pin_machine_string() helper Fiona Ebner
2025-01-17 14:24 ` [pve-devel] [PATCH qemu-server v4 12/16] api: update vm config: pin machine version when switching to windows os type Fiona Ebner
2025-01-17 14:24 ` [pve-devel] [PATCH qemu-server v4 13/16] machine: log informational line when pinning machine version for Windows guest Fiona Ebner
2025-01-17 14:24 ` [pve-devel] [PATCH qemu-server v4 14/16] machine: rename machine_version() function to is_machine_version_at_least() Fiona Ebner
2025-01-17 14:24 ` [pve-devel] [PATCH qemu-server v4 15/16] machine: code cleanup: avoid superfluous augmented assignment operator Fiona Ebner
2025-01-17 14:24 ` [pve-devel] [PATCH docs v4 16/16] qm: machine version: document support in PVE Fiona Ebner
2025-01-17 18:55 ` [pve-devel] applied-series: [PATCH qemu-server/docs v4 00/16] adapt to changes in QEMU machine version deprecation/removal Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250117142430.99484-3-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal