[pve-devel] [PATCH qemu-server 02/13] add 'arch' vm configuration

Wolfgang Bumiller w.bumiller at proxmox.com
Wed Oct 24 10:56:38 CEST 2018


Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
 PVE/QemuServer.pm | 46 +++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 43 insertions(+), 3 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 6c95623..0385fbd 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -540,6 +540,12 @@ EODESCR
 	description => "Specifies the Qemu machine type of the running vm. This is used internally for snapshots.",
     }),
     machine => get_standard_option('pve-qemu-machine'),
+    arch => {
+	description => "Virtual processor architecture. Defaults to the host.",
+	optional => 1,
+	type => 'string',
+	enum => [qw(amd64 arm64)],
+    },
     smbios1 => {
 	description => "Specify SMBIOS type 1 fields.",
 	type => 'string', format => 'pve-qm-smbios1',
@@ -3144,6 +3150,34 @@ sub vga_conf_has_spice {
     return $1 || 1;
 }
 
+my $host_arch; # cache this... FIXME: do this in Tools.pm already?
+sub get_host_arch() {
+    return ($host_arch //= PVE::Tools::get_host_arch());
+}
+
+sub is_native($) {
+    my ($arch) = @_;
+    return get_host_arch() eq $arch;
+}
+
+my $default_machines = {
+    amd64 => 'pc',
+    arm64 => 'virt',
+};
+
+sub get_basic_machine_info {
+    my ($conf) = @_;
+
+    my $arch = $conf->{arch} // get_host_arch();
+
+    # $base_machine is the "base" type (q35, i440fx, virt) without version or pxe
+    # suffix...
+    my $base_machine = $conf->{machine} || $default_machines->{$arch};
+    $base_machine =~ s/-\d.*$//;
+
+    return ($arch, $base_machine);
+}
+
 sub config_to_command {
     my ($storecfg, $vmid, $conf, $defaults, $forcemachine) = @_;
 
@@ -3159,9 +3193,15 @@ sub config_to_command {
     my $vernum = 0; # unknown
     my $ostype = $conf->{ostype};
     my $winversion = windows_version($ostype);
-    my $kvm = $conf->{kvm} // 1;
+    my $kvm = $conf->{kvm};
 
-    die "KVM virtualisation configured, but not available. Either disable in VM configuration or enable in BIOS.\n" if (!$cpuinfo->{hvm} && $kvm);
+    my ($arch, $base_machine) = get_basic_machine_info($conf);
+    $kvm //= 1 if is_native($arch);
+
+    if ($kvm) {
+	die "KVM virtualisation configured, but not available. Either disable in VM configuration or enable in BIOS.\n"
+	    if !defined kvm_version();
+    }
 
     if ($kvmver =~ m/^(\d+)\.(\d+)$/) {
 	$vernum = $1*1000000+$2*1000;
@@ -3175,7 +3215,7 @@ sub config_to_command {
 
     my $q35 = machine_type_is_q35($conf);
     my $hotplug_features = parse_hotplug_features(defined($conf->{hotplug}) ? $conf->{hotplug} : '1');
-    my $machine_type = $forcemachine || $conf->{machine};
+    my $machine_type = $forcemachine || $base_machine;
     my $use_old_bios_files = undef;
     ($use_old_bios_files, $machine_type) = qemu_use_old_bios_files($machine_type);
 
-- 
2.11.0





More information about the pve-devel mailing list