[pve-devel] [PATCH qemu-server 07/19] machine: add default_machine_for_arch() helper
Fiona Ebner
f.ebner at proxmox.com
Fri Jan 3 16:57:50 CET 2025
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.ebner at 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 32b2a835..85bbb38f 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -3260,11 +3260,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);
@@ -3309,7 +3304,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";
}
@@ -3375,7 +3370,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
More information about the pve-devel
mailing list