There are already other places where 'aarch64' and 'x86_64' are
checked to be the only valid architectures, for example, the
get_command_for_arch() helper, so the new error scenario for an
unknown arch should not cause any regressions.

Signed-off-by: Fiona Ebner <f.eb...@proxmox.com>
---
 PVE/QemuServer.pm         |  9 ++-------
 PVE/QemuServer/Machine.pm | 12 ++++++++++++
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 164cb0e8..82795767 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -3271,11 +3271,6 @@ sub vga_conf_has_spice {
     return $1 || 1;
 }
 
-my $default_machines = {
-    x86_64 => 'pc',
-    aarch64 => 'virt',
-};
-
 sub get_installed_machine_version {
     my ($kvmversion) = @_;
     $kvmversion = kvm_user_version() if !defined($kvmversion);
@@ -3320,7 +3315,7 @@ sub get_vm_machine {
            $machine = windows_get_pinned_machine_version($machine, '5.1', 
$kvmversion);
        }
        $arch //= 'x86_64';
-       $machine ||= $default_machines->{$arch};
+       $machine ||= PVE::QemuServer::Machine::default_machine_for_arch($arch);
        my $pvever = PVE::QemuServer::Machine::get_pve_version($kvmversion);
        $machine .= "+pve$pvever";
     }
@@ -3386,7 +3381,7 @@ sub query_supported_cpu_flags {
     my ($arch) = @_;
 
     $arch //= get_host_arch();
-    my $default_machine = $default_machines->{$arch};
+    my $default_machine = 
PVE::QemuServer::Machine::default_machine_for_arch($arch);
 
     my $flags = {};
 
diff --git a/PVE/QemuServer/Machine.pm b/PVE/QemuServer/Machine.pm
index 7f03ef20..5a039244 100644
--- a/PVE/QemuServer/Machine.pm
+++ b/PVE/QemuServer/Machine.pm
@@ -55,6 +55,18 @@ sub print_machine {
     return print_property_string($machine_conf, $machine_fmt);
 }
 
+my $default_machines = {
+    x86_64 => 'pc',
+    aarch64 => 'virt',
+};
+
+sub default_machine_for_arch {
+    my ($arch) = @_;
+
+    my $machine = $default_machines->{$arch} or die "unsupported architecture 
'$arch'\n";
+    return $machine;
+}
+
 sub assert_valid_machine_property {
     my ($machine_conf) = @_;
     my $q35 = $machine_conf->{type} && ($machine_conf->{type} =~ m/q35/) ? 1 : 
0;
-- 
2.39.5



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

Reply via email to