From 045749f2fce79109a17cc5189351bd2b3b0d5b21 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Mon, 25 Nov 2019 08:56:58 +0100 Subject: [PATCH] split get_basic_machine_info into get_vm_arch and get_vm_machine Signed-off-by: Thomas Lamprecht --- PVE/QemuServer.pm | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 61deb3f..8c40ea2 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -3350,17 +3350,27 @@ sub is_native($) { return get_host_arch() eq $arch; } +sub get_vm_arch { + my ($conf) = @_; + return $conf->{arch} // get_host_arch(); +} + my $default_machines = { x86_64 => 'pc', aarch64 => 'virt', }; -sub get_basic_machine_info { - my ($conf, $forcemachine) = @_; +sub get_vm_machine { + my ($conf, $forcemachine, $arch) = @_; + + my $machine = $forcemachine || $conf->{machine}; - my $arch = $conf->{arch} // get_host_arch(); - my $machine = $forcemachine || $conf->{machine} || $default_machines->{$arch}; - return ($arch, $machine); + if (!$machine) { + $arch //= 'x86_64'; + $machine ||= $default_machines->{$arch}; + } + + return $machine; } sub get_ovmf_files($) { @@ -3455,9 +3465,11 @@ sub config_to_command { my $winversion = windows_version($ostype); my $kvm = $conf->{kvm}; - my ($arch, $machine_type) = get_basic_machine_info($conf, $forcemachine); + my $arch = get_vm_arch($conf); my $kvm_binary = get_command_for_arch($arch); my $kvmver = kvm_user_version($kvm_binary); + + my $machine_type = get_vm_machine($conf, $forcemachine, $arch); my $machine_version = PVE::QemuServer::Machine::extract_version($machine_type) // $kvmver; $kvm //= 1 if is_native($arch); @@ -4735,7 +4747,8 @@ sub vmconfig_hotplug_pending { my ($vmid, $conf, $storecfg, $selection, $errors) = @_; my $defaults = load_defaults(); - my ($arch, $machine_type) = get_basic_machine_info($conf, undef); + my $arch = get_vm_arch($conf); + my $machine_type = 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 -- 2.39.2