[pve-devel] [PATCH 3/3] kvm: introduce qemuver and set machine flag based on qemuver

Stefan Priebe s.priebe at profihost.ag
Mon May 27 22:52:17 CEST 2013


Signed-off-by: Stefan Priebe <s.priebe at profihost.ag>
---
 PVE/QemuServer.pm |   35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 2dba4ec..8e633bb 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -242,6 +242,11 @@ my $confdesc = {
 	description => "qemu machine version",
 	enum => [qw(pc q35 pc-q35-1.6 pc-q35-1.5 pc-q35-1.4 pc-i440fx-1.6 pc-i440fx-1.5 pc-i440fx-1.4)],
     },
+    qemuver => {
+	optional => 1,
+	type => 'string',
+	description => "last qemu version when vm was started",
+    },
     description => {
 	optional => 1,
 	type => 'string',
@@ -688,6 +693,26 @@ sub version_to_int {
     die "Cannot read version $ver\n";
 }
 
+my @qemuver_to_machine = (
+    { ver => version_to_int('1.4'), machine => 'pc-i440fx-1.4' },
+    { ver => version_to_int('1.5'), machine => 'pc-i440fx-1.5' },
+    { ver => version_to_int('1.6'), machine => 'pc-i440fx-1.6' },
+);
+
+sub get_kvm_machine_by_qemuver {
+    my $qemuver = shift;
+
+    # we have no qemu version at all this might happen on VMs never started since introducing qemuver
+    return $qemuver_to_machine[0]->{machine} if !$qemuver;
+
+    # this is an ordered array to the first reversed match is fine
+    foreach my $qm (reverse @qemuver_to_machine) {
+       return $qm->{machine} if ($qm->{ver} <= version_to_int($qemuver));
+    }
+
+    die "unsupported qemu version: $qemuver\n";
+}
+
 my $kernel_has_vhost_net = -c '/dev/vhost-net';
 
 sub disknames {
@@ -2390,7 +2415,9 @@ sub config_to_command {
 
     push @$rtcFlags, 'driftfix=slew' if $tdf;
 
-    push @$machineFlags, $conf->{machine} if $conf->{machine};
+    my $machine = $conf->{machine} // get_kvm_machine_by_qemuver($conf->{qemuver});
+    push @$machineFlags, $machine;
+
     if ($nokvm) {
 	push @$machineFlags, 'accel=tcg';
     } else {
@@ -2997,6 +3024,12 @@ sub vm_start {
 	# set environment variable useful inside network script
 	$ENV{PVE_MIGRATED_FROM} = $migratedfrom if $migratedfrom;
 
+        # always safe qemu version in config file - if we have a fresh start
+        if (!$statefile && !$migratedfrom) {
+            $conf->{qemuver} = kvm_user_version();
+            update_config_nolock($vmid, $conf, 1);
+        }
+
 	my ($cmd, $vollist) = config_to_command($storecfg, $vmid, $conf, $defaults);
 
 	my $migrate_port = 0;
-- 
1.7.10.4




More information about the pve-devel mailing list