my $pcisysfs = "/sys/bus/pci";
my $confdesc = {
- iothread => {
- optional => 1,
- type => 'boolean',
- description => "Enable iothread dataplane.",
- default => 0,
- },
onboot => {
optional => 1,
type => 'boolean',
optional => 1,
description => "Emulated CPU type.",
type => 'string',
- enum => [ qw(486 athlon pentium pentium2 pentium3 coreduo core2duo kvm32 kvm64 qemu32 qemu64 phenom Conroe Penryn Nehalem Westmere SandyBridge Haswell Broadwell Opteron_G1 Opteron_G2 Opteron_G3 Opteron_G4 Opteron_G5 host) ],
+ enum => [ qw(486 athlon pentium pentium2 pentium3 coreduo core2duo kvm32 kvm64 qemu32 qemu64 phenom Conroe Penryn Nehalem Westmere SandyBridge IvyBridge Haswell Broadwell Opteron_G1 Opteron_G2 Opteron_G3 Opteron_G4 Opteron_G5 host) ],
default => 'kvm64',
},
parent => get_standard_option('pve-snapshot-name', {
my $virtiodesc = {
optional => 1,
type => 'string', format => 'pve-qm-drive',
- typetext => '[volume=]volume,] [,media=cdrom|disk] [,cyls=c,heads=h,secs=s[,trans=t]] [,snapshot=on|off] [,cache=none|writethrough|writeback|unsafe|directsync] [,format=f] [,backup=yes|no] [,rerror=ignore|report|stop] [,werror=enospc|ignore|report|stop] [,aio=native|threads] [,discard=ignore|on]',
+ typetext => '[volume=]volume,] [,media=cdrom|disk] [,cyls=c,heads=h,secs=s[,trans=t]] [,snapshot=on|off] [,cache=none|writethrough|writeback|unsafe|directsync] [,format=f] [,backup=yes|no] [,rerror=ignore|report|stop] [,werror=enospc|ignore|report|stop] [,aio=native|threads] [,discard=ignore|on] [,iothread=on]',
description => "Use volume as VIRTIO hard disk (n is 0 to " . ($MAX_VIRTIO_DISKS - 1) . ").",
};
PVE::JSONSchema::register_standard_option("pve-qm-virtio", $virtiodesc);
# ideX = [volume=]volume-id[,media=d][,cyls=c,heads=h,secs=s[,trans=t]]
# [,snapshot=on|off][,cache=on|off][,format=f][,backup=yes|no]
# [,rerror=ignore|report|stop][,werror=enospc|ignore|report|stop]
-# [,aio=native|threads][,discard=ignore|on]
+# [,aio=native|threads][,discard=ignore|on][,iothread=on]
sub parse_drive {
my ($key, $data) = @_;
foreach my $p (split (/,/, $data)) {
next if $p =~ m/^\s*$/;
- if ($p =~ m/^(file|volume|cyls|heads|secs|trans|media|snapshot|cache|format|rerror|werror|backup|aio|bps|mbps|mbps_max|bps_rd|mbps_rd|mbps_rd_max|bps_wr|mbps_wr|mbps_wr_max|iops|iops_max|iops_rd|iops_rd_max|iops_wr|iops_wr_max|size|discard)=(.+)$/) {
+ if ($p =~ m/^(file|volume|cyls|heads|secs|trans|media|snapshot|cache|format|rerror|werror|backup|aio|bps|mbps|mbps_max|bps_rd|mbps_rd|mbps_rd_max|bps_wr|mbps_wr|mbps_wr_max|iops|iops_max|iops_rd|iops_rd_max|iops_wr|iops_wr_max|size|discard|iothread)=(.+)$/) {
my ($k, $v) = ($1, $2);
$k = 'file' if $k eq 'volume';
return undef if $res->{backup} && $res->{backup} !~ m/^(yes|no)$/;
return undef if $res->{aio} && $res->{aio} !~ m/^(native|threads)$/;
return undef if $res->{discard} && $res->{discard} !~ m/^(ignore|on)$/;
+ return undef if $res->{iothread} && $res->{iothread} !~ m/^(on)$/;
return undef if $res->{mbps_rd} && $res->{mbps};
return undef if $res->{mbps_wr} && $res->{mbps};
my ($vmid, $drive) = @_;
my $opts = '';
- foreach my $o (@qemu_drive_options, 'mbps', 'mbps_rd', 'mbps_wr', 'mbps_max', 'mbps_rd_max', 'mbps_wr_max', 'backup') {
+ foreach my $o (@qemu_drive_options, 'mbps', 'mbps_rd', 'mbps_wr', 'mbps_max', 'mbps_rd_max', 'mbps_wr_max', 'backup', 'iothread') {
$opts .= ",$o=$drive->{$o}" if $drive->{$o};
}
if ($drive->{interface} eq 'virtio') {
my $pciaddr = print_pci_addr("$drive->{interface}$drive->{index}", $bridges);
$device = "virtio-blk-pci,drive=drive-$drive->{interface}$drive->{index},id=$drive->{interface}$drive->{index}$pciaddr";
- $device .= ",iothread=iothread0" if $conf->{iothread};
+ $device .= ",iothread=iothread-$drive->{interface}$drive->{index}" if $drive->{iothread};
} elsif ($drive->{interface} eq 'scsi') {
$maxdev = ($conf->{scsihw} && ($conf->{scsihw} !~ m/^lsi/)) ? 256 : 7;
my $controller = int($drive->{index} / $maxdev);
$d->{cpus} = ($conf->{sockets} || 1) * ($conf->{cores} || 1);
$d->{cpus} = $cpucount if $d->{cpus} > $cpucount;
+ $d->{cpus} = $conf->{vcpus} if $conf->{vcpus};
$d->{name} = $conf->{name} || "VM $vmid";
$d->{maxmem} = $conf->{memory} ? $conf->{memory}*(1024*1024) : 0;
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};
push @$cmd, '/usr/bin/kvm';
push @$cmd, '-smbios', "type=1,$conf->{smbios1}";
}
- push @$cmd, '-object', "iothread,id=iothread0" if $conf->{iothread};
-
if ($q35) {
# the q35 chipset support native usb2, so we enable usb controller
# by default for this machine type
$ost eq 'wvista') {
push @$globalFlags, 'kvm-pit.lost_tick_policy=discard';
push @$cmd, '-no-hpet';
- #push @$cpuFlags , 'hv_vapic" if !$nokvm; #fixme, my win2008R2 hang at boot with this
- push @$cpuFlags , 'hv_spinlocks=0xffff' if !$nokvm;
+ 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;
+
+ } else {
+ push @$cpuFlags , 'hv_spinlocks=0xffff' if !$nokvm;
+ }
}
if ($ost eq 'win7' || $ost eq 'win8') {
die "No accelerator found!\n" if !$cpuinfo->{hvm};
}
- my $machine_type = $forcemachine || $conf->{machine};
if ($machine_type) {
push @$machineFlags, "type=${machine_type}";
}
push @$cpuFlags, '+sep' if $cpu eq 'kvm64' || $cpu eq 'kvm32';
+ if (qemu_machine_feature_enabled ($machine_type, $kvmver, 2, 3)) {
+
+ push @$cpuFlags , '+kvm_pv_unhalt' if !$nokvm;
+ push @$cpuFlags , '+kvm_pv_eoi' if !$nokvm;
+ }
+
$cpu .= "," . join(',', @$cpuFlags) if scalar(@$cpuFlags);
- # Note: enforce needs kernel 3.10, so we do not use it for now
- # push @$cmd, '-cpu', "$cpu,enforce";
- push @$cmd, '-cpu', $cpu;
+ push @$cmd, '-cpu', "$cpu,enforce";
my $memory = $conf->{memory} || $defaults->{memory};
my $static_memory = 0;
}
}
+ if($drive->{interface} eq 'virtio'){
+ push @$cmd, '-object', "iothread,id=iothread-$ds" if $drive->{iothread};
+ }
+
if ($drive->{interface} eq 'scsi') {
my $maxdev = ($scsihw !~ m/^lsi/) ? 256 : 7;
if (!$q35) {
# add pci bridges
+ if (qemu_machine_feature_enabled ($machine_type, $kvmver, 2, 3)) {
+ $bridges->{1} = 1;
+ $bridges->{2} = 1;
+ }
+
while (my ($k, $v) = each %$bridges) {
$pciaddr = print_pci_addr("pci.$k");
unshift @$devices, '-device', "pci-bridge,id=pci.$k,chassis_nr=$k$pciaddr" if $k > 0;
qemu_devicedelverify($vmid, $deviceid);
qemu_drivedel($vmid, $deviceid);
- } elsif ($deviceid =~ m/^(lsi)(\d+)$/) {
+ } elsif ($deviceid =~ m/^(scsihw)(\d+)$/) {
qemu_devicedel($vmid, $deviceid);
+ qemu_devicedelverify($vmid, $deviceid);
} elsif ($deviceid =~ m/^(scsi)(\d+)$/) {
qemu_devicedel($vmid, $deviceid);
qemu_drivedel($vmid, $deviceid);
-
+ qemu_deletescsihw($conf, $vmid, $deviceid);
+
} elsif ($deviceid =~ m/^(net)(\d+)$/) {
qemu_devicedel($vmid, $deviceid);
my ($storecfg, $vmid, $device) = @_;
my $drive = print_drive_full($storecfg, $vmid, $device);
+ $drive =~ s/\\/\\\\/g;
my $ret = vm_human_monitor_command($vmid, "drive_add auto \"$drive\"");
# If the command succeeds qemu prints: "OK"
return 1;
}
+sub qemu_deletescsihw {
+ my ($conf, $vmid, $opt) = @_;
+
+ my $device = parse_drive($opt, $conf->{$opt});
+
+ my $maxdev = ($conf->{scsihw} && ($conf->{scsihw} !~ m/^lsi/)) ? 256 : 7;
+ my $controller = int($device->{index} / $maxdev);
+
+ my $devices_list = vm_devices_list($vmid);
+ foreach my $opt (keys %{$devices_list}) {
+ if (PVE::QemuServer::valid_drivename($opt)) {
+ my $drive = PVE::QemuServer::parse_drive($opt, $conf->{$opt});
+ if($drive->{interface} eq 'scsi' && $drive->{index} < (($maxdev-1)*($controller+1))) {
+ return 1;
+ }
+ }
+ }
+
+ my $scsihwid="scsihw$controller";
+
+ vm_deviceunplug($vmid, $conf, $scsihwid);
+
+ return 1;
+}
+
sub qemu_add_pci_bridge {
my ($storecfg, $conf, $vmid, $device) = @_;
}
my $fast_plug_option = {
+ 'lock' => 1,
'name' => 1,
'onboot' => 1,
'shares' => 1,
die "skip\n" if $old_balloon_enabled != $new_balloon_enabled;
# allow manual ballooning if shares is set to zero
- if (!(defined($conf->{shares}) && ($conf->{shares} == 0))) {
+ if ((defined($conf->{shares}) && ($conf->{shares} == 0))) {
my $balloon = $conf->{pending}->{balloon} || $conf->{memory} || $defaults->{memory};
vm_mon_cmd($vmid, "balloon", value => $balloon*1024*1024);
}
if (!$statefile && (!defined($conf->{balloon}) || $conf->{balloon})) {
vm_mon_cmd_nocheck($vmid, "balloon", value => $conf->{balloon}*1024*1024)
if $conf->{balloon};
- vm_mon_cmd_nocheck($vmid, 'qom-set',
- path => "machine/peripheral/balloon0",
- property => "guest-stats-polling-interval",
- value => 2);
}
foreach my $opt (keys %$conf) {
qemu_set_link_status($vmid, $opt, 0) if $nicconf->{link_down};
}
}
+
+ vm_mon_cmd_nocheck($vmid, 'qom-set',
+ path => "machine/peripheral/balloon0",
+ property => "guest-stats-polling-interval",
+ value => 2) if (!defined($conf->{balloon}) || $conf->{balloon});
+
});
}
return $current || $default || 'pc';
}
+sub qemu_machine_feature_enabled {
+ my ($machine, $kvmver, $version_major, $version_minor) = @_;
+
+ my $current_major;
+ my $current_minor;
+
+ if ($machine && $machine =~ m/^(pc(-i440fx|-q35)?-(\d+)\.(\d+))/) {
+
+ $current_major = $3;
+ $current_minor = $4;
+
+ } elsif ($kvmver =~ m/^(\d+)\.(\d+)/) {
+
+ $current_major = $1;
+ $current_minor = $2;
+ }
+
+ return 1 if $current_major >= $version_major && $current_minor >= $version_minor;
+
+
+}
+
sub lspci {
my $devices = {};