[pve-devel] [PATCH 3/3] kvm: introduce qemuver and set machine flag based on qemuver
Dietmar Maurer
dietmar at proxmox.com
Tue May 28 06:19:16 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)],
We will end up with an endless list here?
q35 pc-q35-1.6 q35 pc-q35-1.7 q35 pc-q35-1.8 q35 pc-q35-1.9 .....
> },
> + 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);
> + }
> +
IMHO vm_start should not touch/modify the configuration file.
I guess we just need to save the machine for snapshots.
More information about the pve-devel
mailing list