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

Stefan Priebe s.priebe at profihost.ag
Sun May 26 22:55:06 CEST 2013


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

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 81aeb0c..3ac442c 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',
@@ -687,6 +692,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 {
@@ -2254,7 +2279,8 @@ sub config_to_command {
 
     push @$cmd, '-id', $vmid;
 
-    push @$cmd, '-machine', $conf->{machine} if $conf->{machine};
+    my $machine = $conf->{machine} // get_kvm_machine_by_qemuver($conf->{qemuver});
+    push @$cmd, '-machine', $machine;
 
     my $use_virtio = 0;
 
@@ -2990,6 +3016,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