cleanup windows version handling and hyperv enlightments

This cleanup windows guest os version handling,
with normalizing ostype with numbers in a new windows_version sub.

if($ostype eq 'wxp' || $ostype eq 'w2k3' || $ostype eq 'w2k') {
      $winversion = 5;
} elsif($ostype eq 'w2k8' || $ostype eq 'wvista') {
      $winversion = 6;
} elsif ($ostype =~ m/^win(\d+)$/) {
      $winversion = $1;
}

so we can simply do test on windows version with lower or upper version

Hyperv enlightments configuration is centralized
in a new add_hyperv_enlighments sub.

Also disable hyperv with win < 8 + ovmf.

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
This commit is contained in:
Alexandre Derumier 2016-11-08 02:56:01 +01:00 committed by Dietmar Maurer
parent 36e54bd7f1
commit 4317f69fc5

View File

@ -2780,6 +2780,8 @@ sub config_to_command {
my $kvmver = kvm_user_version(); my $kvmver = kvm_user_version();
my $vernum = 0; # unknown my $vernum = 0; # unknown
my $ostype = $conf->{ostype}; my $ostype = $conf->{ostype};
my $winversion = windows_version($ostype);
if ($kvmver =~ m/^(\d+)\.(\d+)$/) { if ($kvmver =~ m/^(\d+)\.(\d+)$/) {
$vernum = $1*1000000+$2*1000; $vernum = $1*1000000+$2*1000;
} elsif ($kvmver =~ m/^(\d+)\.(\d+)\.(\d+)$/) { } elsif ($kvmver =~ m/^(\d+)\.(\d+)\.(\d+)$/) {
@ -2869,13 +2871,7 @@ sub config_to_command {
$vga = 'qxl' if $qxlnum; $vga = 'qxl' if $qxlnum;
if (!$vga) { if (!$vga) {
if ($conf->{ostype} && ($conf->{ostype} eq 'win8' || $vga = $winversion >= 6 ? 'std' : 'cirrus';
$conf->{ostype} eq 'win7' ||
$conf->{ostype} eq 'w2k8')) {
$vga = 'std';
} else {
$vga = 'cirrus';
}
} }
# enable absolute mouse coordinates (needed by vnc) # enable absolute mouse coordinates (needed by vnc)
@ -2891,6 +2887,8 @@ sub config_to_command {
push @$devices, '-device', print_tabletdevice_full($conf) if $tablet; push @$devices, '-device', print_tabletdevice_full($conf) if $tablet;
my $kvm_off = 0; my $kvm_off = 0;
my $gpu_passthrough;
# host pci devices # host pci devices
for (my $i = 0; $i < $MAX_HOSTPCI_DEVICES; $i++) { for (my $i = 0; $i < $MAX_HOSTPCI_DEVICES; $i++) {
my $d = parse_hostpci($conf->{"hostpci$i"}); my $d = parse_hostpci($conf->{"hostpci$i"});
@ -2910,9 +2908,8 @@ sub config_to_command {
$xvga = ',x-vga=on'; $xvga = ',x-vga=on';
$kvm_off = 1; $kvm_off = 1;
$vga = 'none'; $vga = 'none';
if ($ostype eq 'win7' || $ostype eq 'win8' || $ostype eq 'w2k8') { $gpu_passthrough = 1;
push @$cpuFlags , 'hv_vendor_id=proxmox';
}
if ($conf->{bios} && $conf->{bios} eq 'ovmf') { if ($conf->{bios} && $conf->{bios} eq 'ovmf') {
$xvga = ""; $xvga = "";
} }
@ -3030,41 +3027,18 @@ sub config_to_command {
my $nokvm = defined($conf->{kvm}) && $conf->{kvm} == 0 ? 1 : 0; my $nokvm = defined($conf->{kvm}) && $conf->{kvm} == 0 ? 1 : 0;
my $useLocaltime = $conf->{localtime}; my $useLocaltime = $conf->{localtime};
if ($ostype) { if ($winversion >= 5) { # windows
# other, wxp, w2k, w2k3, w2k8, wvista, win7, win8, l24, l26, solaris $useLocaltime = 1 if !defined($conf->{localtime});
if ($ostype =~ m/^w/) { # windows # use time drift fix when acpi is enabled
$useLocaltime = 1 if !defined($conf->{localtime}); if (!(defined($conf->{acpi}) && $conf->{acpi} == 0)) {
$tdf = 1 if !defined($conf->{tdf});
# use time drift fix when acpi is enabled
if (!(defined($conf->{acpi}) && $conf->{acpi} == 0)) {
$tdf = 1 if !defined($conf->{tdf});
}
} }
}
if ($ostype eq 'win7' || $ostype eq 'win8' || $ostype eq 'w2k8' || if ($winversion >= 6) {
$ostype eq 'wvista') { push @$globalFlags, 'kvm-pit.lost_tick_policy=discard';
push @$globalFlags, 'kvm-pit.lost_tick_policy=discard'; push @$cmd, '-no-hpet';
push @$cmd, '-no-hpet';
if (qemu_machine_feature_enabled ($machine_type, $kvmver, 2, 3)) {
push @$cpuFlags , 'hv_spinlocks=0x1fff' if !$nokvm;
push @$cpuFlags , 'hv_vapic' if !$nokvm;
push @$cpuFlags , 'hv_time' if !$nokvm;
if (qemu_machine_feature_enabled ($machine_type, $kvmver, 2, 6)) {
push @$cpuFlags , 'hv_reset' if !$nokvm;
push @$cpuFlags , 'hv_vpindex' if !$nokvm;
push @$cpuFlags , 'hv_runtime' if !$nokvm;
}
} else {
push @$cpuFlags , 'hv_spinlocks=0xffff' if !$nokvm;
}
}
if ($ostype eq 'win7' || $ostype eq 'win8') {
push @$cpuFlags , 'hv_relaxed' if !$nokvm;
}
} }
push @$rtcFlags, 'driftfix=slew' if $tdf; push @$rtcFlags, 'driftfix=slew' if $tdf;
@ -3108,6 +3082,8 @@ sub config_to_command {
push @$cpuFlags , '+kvm_pv_eoi' if !$nokvm; push @$cpuFlags , '+kvm_pv_eoi' if !$nokvm;
} }
add_hyperv_enlighments($cpuFlags, $winversion, $machine_type, $kvmver, $nokvm, $conf->{bios}, $gpu_passthrough);
push @$cpuFlags, 'enforce' if $cpu ne 'host' && !$nokvm; push @$cpuFlags, 'enforce' if $cpu ne 'host' && !$nokvm;
push @$cpuFlags, 'kvm=off' if $kvm_off; push @$cpuFlags, 'kvm=off' if $kvm_off;
@ -6117,6 +6093,51 @@ sub scsihw_infos {
return ($maxdev, $controller, $controller_prefix); return ($maxdev, $controller, $controller_prefix);
} }
sub add_hyperv_enlighments {
my ($cpuFlags, $winversion, $machine_type, $kvmver, $nokvm, $bios, $gpu_passthrough) = @_;
return if $nokvm;
return if $winversion < 6;
return if $bios && $bios eq 'ovmf' && $winversion < 8;
if (qemu_machine_feature_enabled ($machine_type, $kvmver, 2, 3)) {
push @$cpuFlags , 'hv_spinlocks=0x1fff';
push @$cpuFlags , 'hv_vapic';
push @$cpuFlags , 'hv_time';
} else {
push @$cpuFlags , 'hv_spinlocks=0xffff';
}
if (qemu_machine_feature_enabled ($machine_type, $kvmver, 2, 6)) {
push @$cpuFlags , 'hv_reset';
push @$cpuFlags , 'hv_vpindex';
push @$cpuFlags , 'hv_runtime';
}
if ($winversion >= 7) {
push @$cpuFlags , 'hv_relaxed';
push @$cpuFlags , 'hv_vendor_id=proxmox' if $gpu_passthrough;
}
}
sub windows_version {
my ($ostype) = @_;
return 0 if !$ostype;
my $winversion = 0;
if($ostype eq 'wxp' || $ostype eq 'w2k3' || $ostype eq 'w2k') {
$winversion = 5;
} elsif($ostype eq 'w2k8' || $ostype eq 'wvista') {
$winversion = 6;
} elsif ($ostype =~ m/^win(\d+)$/) {
$winversion = $1;
}
return $winversion;
}
# bash completion helper # bash completion helper
sub complete_backup_archives { sub complete_backup_archives {