]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/QemuServer.pm
use aio=native only with O_DIRECT (cache=none|directsync)
[qemu-server.git] / PVE / QemuServer.pm
index 33bbf600ec3ad493fc263c26e619a887b0f31a2d..baf0e64df9b8fcb5563a7b98b31beba9cd4635fb 100644 (file)
@@ -152,12 +152,6 @@ mkdir $lock_dir;
 my $pcisysfs = "/sys/bus/pci";
 
 my $confdesc = {
-    iothread => {
-       optional => 1,
-       type => 'boolean',
-       description => "Enable iothread dataplane.",
-       default => 0,
-    },
     onboot => {
        optional => 1,
        type => 'boolean',
@@ -240,7 +234,7 @@ my $confdesc = {
        optional => 1,
        type => 'string',
        description => "scsi controller model",
-       enum => [qw(lsi lsi53c810 virtio-scsi-pci megasas pvscsi)],
+       enum => [qw(lsi lsi53c810 virtio-scsi-pci virtio-scsi-single megasas pvscsi)],
        default => 'lsi',
     },
     description => {
@@ -424,7 +418,7 @@ EODESCR
        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', {
@@ -555,7 +549,7 @@ PVE::JSONSchema::register_standard_option("pve-qm-ide", $idedesc);
 my $scsidesc = {
     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 SCSI hard disk or CD-ROM (n is 0 to " . ($MAX_SCSI_DISKS - 1) . ").",
 };
 PVE::JSONSchema::register_standard_option("pve-qm-scsi", $scsidesc);
@@ -571,7 +565,7 @@ PVE::JSONSchema::register_standard_option("pve-qm-sata", $satadesc);
 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);
@@ -879,7 +873,7 @@ sub parse_hotplug_features {
     my $res = {};
 
     return $res if $data eq '0';
-    
+
     $data = $confdesc->{hotplug}->{default} if $data eq '1';
 
     foreach my $feature (PVE::Tools::split_list($data)) {
@@ -940,7 +934,7 @@ my $format_size = sub {
 # 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) = @_;
@@ -961,7 +955,7 @@ sub parse_drive {
     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';
@@ -1003,6 +997,7 @@ sub parse_drive {
     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};
@@ -1050,7 +1045,7 @@ sub print_drive {
     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};
     }
 
@@ -1148,10 +1143,10 @@ sub print_drivedevice_full {
     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);
+
+       my ($maxdev, $controller, $controller_prefix) = scsihw_infos($conf, $drive);
        my $unit = $drive->{index} % $maxdev;
        my $devicetype = 'hd';
         my $path = '';
@@ -1178,9 +1173,9 @@ sub print_drivedevice_full {
          }
 
         if (!$conf->{scsihw} || ($conf->{scsihw} =~ m/^lsi/)){
-            $device = "scsi-$devicetype,bus=scsihw$controller.0,scsi-id=$unit,drive=drive-$drive->{interface}$drive->{index},id=$drive->{interface}$drive->{index}";
+            $device = "scsi-$devicetype,bus=$controller_prefix$controller.0,scsi-id=$unit,drive=drive-$drive->{interface}$drive->{index},id=$drive->{interface}$drive->{index}";
         } else {
-            $device = "scsi-$devicetype,bus=scsihw$controller.0,channel=0,scsi-id=0,lun=$drive->{index},drive=drive-$drive->{interface}$drive->{index},id=$drive->{interface}$drive->{index}";
+            $device = "scsi-$devicetype,bus=$controller_prefix$controller.0,channel=0,scsi-id=0,lun=$drive->{index},drive=drive-$drive->{interface}$drive->{index},id=$drive->{interface}$drive->{index}";
         }
 
     } elsif ($drive->{interface} eq 'ide'){
@@ -1234,8 +1229,15 @@ sub print_drive_full {
        $opts .= ",$o=" . int($v*1024*1024) if $v;
     }
 
-    # use linux-aio by default (qemu default is threads)
-    $opts .= ",aio=native" if !$drive->{aio};
+    # aio native works only with O_DIRECT
+    if (!$drive->{aio}) {
+       if(!$drive->{cache} || $drive->{cache} eq 'none' || $drive->{cache} eq 'directsync') {
+           $opts .= ",aio=native";
+       } else {
+           $opts .= ",aio=threads";
+       }
+    }
+
 
     my $path;
     my $volid = $drive->{file};
@@ -2674,8 +2676,6 @@ sub config_to_command {
        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
@@ -2870,7 +2870,7 @@ sub config_to_command {
                push @$cpuFlags , 'hv_vapic' if !$nokvm;
                push @$cpuFlags , 'hv_time' if !$nokvm;
 
-           } else { 
+           } else {
                push @$cpuFlags , 'hv_spinlocks=0xffff' if !$nokvm;
            }
        }
@@ -3111,12 +3111,24 @@ sub config_to_command {
            }
        }
 
+       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;
-           my $controller = int($drive->{index} / $maxdev);
-           $pciaddr = print_pci_addr("scsihw$controller", $bridges);
-           push @$devices, '-device', "$scsihw,id=scsihw$controller$pciaddr" if !$scsicontroller->{$controller};
+           my ($maxdev, $controller, $controller_prefix) = scsihw_infos($conf, $drive);
+
+           $pciaddr = print_pci_addr("$controller_prefix$controller", $bridges);
+           my $scsihw_type = $scsihw =~ m/^virtio-scsi-single/ ? "virtio-scsi-pci" : $scsihw;
+
+           my $iothread = '';
+           if($conf->{scsihw} && $conf->{scsihw} eq "virtio-scsi-single" && $drive->{iothread}){
+               $iothread .= ",iothread=iothread-$controller_prefix$controller";
+               push @$cmd, '-object', "iothread,id=iothread-$controller_prefix$controller";
+           }
+
+           push @$devices, '-device', "$scsihw_type,id=$controller_prefix$controller$pciaddr$iothread" if !$scsicontroller->{$controller};
            $scsicontroller->{$controller}=1;
         }
 
@@ -3153,6 +3165,13 @@ sub config_to_command {
 
     if (!$q35) {
        # add pci bridges
+        if (qemu_machine_feature_enabled ($machine_type, $kvmver, 2, 3)) {
+          $bridges->{1} = 1;
+          $bridges->{2} = 1;
+       }
+
+       $bridges->{3} = 1 if $scsihw =~ m/^virtio-scsi-single/;
+
        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;
@@ -3268,6 +3287,8 @@ sub vm_deviceplug {
 
     } elsif ($deviceid =~ m/^(virtio)(\d+)$/) {
 
+       qemu_iothread_add($vmid, $deviceid, $device);
+
         qemu_driveadd($storecfg, $vmid, $device);
         my $devicefull = print_drivedevice_full($storecfg, $conf, $vmid, $device);
 
@@ -3279,11 +3300,19 @@ sub vm_deviceplug {
            die $err;
         }
 
-    } elsif ($deviceid =~ m/^(scsihw)(\d+)$/) {
+    } elsif ($deviceid =~ m/^(virtioscsi|scsihw)(\d+)$/) {
+
 
         my $scsihw = defined($conf->{scsihw}) ? $conf->{scsihw} : "lsi";
         my $pciaddr = print_pci_addr($deviceid);
-        my $devicefull = "$scsihw,id=$deviceid$pciaddr";
+       my $scsihw_type = $scsihw eq 'virtio-scsi-single' ? "virtio-scsi-pci" : $scsihw;
+
+        my $devicefull = "$scsihw_type,id=$deviceid$pciaddr";
+
+       if($deviceid =~ m/^virtioscsi(\d+)$/ && $device->{iothread}) {
+           qemu_iothread_add($vmid, $deviceid, $device);
+           $devicefull .= ",iothread=iothread-$deviceid";
+       }
 
         qemu_deviceadd($vmid, $devicefull);
         qemu_deviceaddverify($vmid, $deviceid);
@@ -3292,7 +3321,7 @@ sub vm_deviceplug {
 
         qemu_findorcreatescsihw($storecfg,$conf, $vmid, $device);
         qemu_driveadd($storecfg, $vmid, $device);
-        
+
        my $devicefull = print_drivedevice_full($storecfg, $conf, $vmid, $device);
        eval { qemu_deviceadd($vmid, $devicefull); };
        if (my $err = $@) {
@@ -3318,12 +3347,12 @@ sub vm_deviceplug {
        my $bridgeid = $2;
        my $pciaddr = print_pci_addr($deviceid);
        my $devicefull = "pci-bridge,id=pci.$bridgeid,chassis_nr=$bridgeid$pciaddr";
-       
+
        qemu_deviceadd($vmid, $devicefull);
        qemu_deviceaddverify($vmid, $deviceid);
 
     } else {
-       die "can't hotplug device '$deviceid'\n";       
+       die "can't hotplug device '$deviceid'\n";
     }
 
     return 1;
@@ -3347,16 +3376,24 @@ sub vm_deviceunplug {
         qemu_devicedel($vmid, $deviceid);
         qemu_devicedelverify($vmid, $deviceid);
         qemu_drivedel($vmid, $deviceid);
-   
-    } elsif ($deviceid =~ m/^(lsi)(\d+)$/) {
-    
+       qemu_iothread_del($conf, $vmid, $deviceid);
+
+    } elsif ($deviceid =~ m/^(virtioscsi|scsihw)(\d+)$/) {
+
        qemu_devicedel($vmid, $deviceid);
-    
+       qemu_devicedelverify($vmid, $deviceid);
+       qemu_iothread_del($conf, $vmid, $deviceid);
+
     } elsif ($deviceid =~ m/^(scsi)(\d+)$/) {
 
+       #qemu 2.3 segfault on drive_del with virtioscsi + iothread
+       my $device = parse_drive($deviceid, $conf->{$deviceid});
+       die "virtioscsi with iothread is not hot-unplugglable currently" if $device->{iothread};
+
         qemu_devicedel($vmid, $deviceid);
         qemu_drivedel($vmid, $deviceid);
-    
+       qemu_deletescsihw($conf, $vmid, $deviceid);
+
     } elsif ($deviceid =~ m/^(net)(\d+)$/) {
 
         qemu_devicedel($vmid, $deviceid);
@@ -3385,6 +3422,25 @@ sub qemu_devicedel {
     my $ret = vm_mon_cmd($vmid, "device_del", id => $deviceid);
 }
 
+sub qemu_iothread_add {
+    my($vmid, $deviceid, $device) = @_;
+
+    if ($device->{iothread}) {
+       my $iothreads = vm_iothreads_list($vmid);
+       qemu_objectadd($vmid, "iothread-$deviceid", "iothread") if !$iothreads->{"iothread-$deviceid"};
+    }
+}
+
+sub qemu_iothread_del {
+    my($conf, $vmid, $deviceid) = @_;
+
+    my $device = parse_drive($deviceid, $conf->{$deviceid});
+    if ($device->{iothread}) {
+       my $iothreads = vm_iothreads_list($vmid);
+       qemu_objectdel($vmid, "iothread-$deviceid") if $iothreads->{"iothread-$deviceid"};
+    }
+}
+
 sub qemu_objectadd {
     my($vmid, $objectid, $qomtype) = @_;
 
@@ -3419,12 +3475,12 @@ sub qemu_drivedel {
 
     my $ret = vm_human_monitor_command($vmid, "drive_del drive-$deviceid");
     $ret =~ s/^\s+//;
-    
+
     return 1 if $ret eq "";
-  
+
     # NB: device not found errors mean the drive was auto-deleted and we ignore the error
-    return 1 if $ret =~ m/Device \'.*?\' not found/s; 
-    
+    return 1 if $ret =~ m/Device \'.*?\' not found/s;
+
     die "deleting drive $deviceid failed : $ret\n";
 }
 
@@ -3444,7 +3500,7 @@ sub qemu_deviceaddverify {
 sub qemu_devicedelverify {
     my ($vmid, $deviceid) = @_;
 
-    # need to verify that the device is correctly removed as device_del 
+    # need to verify that the device is correctly removed as device_del
     # is async and empty return is not reliable
 
     for (my $i = 0; $i <= 5; $i++) {
@@ -3459,15 +3515,44 @@ sub qemu_devicedelverify {
 sub qemu_findorcreatescsihw {
     my ($storecfg, $conf, $vmid, $device) = @_;
 
-    my $maxdev = ($conf->{scsihw} && ($conf->{scsihw} !~ m/^lsi/)) ? 256 : 7;
-    my $controller = int($device->{index} / $maxdev);
-    my $scsihwid="scsihw$controller";
+    my ($maxdev, $controller, $controller_prefix) = scsihw_infos($conf, $device);
+
+    my $scsihwid="$controller_prefix$controller";
     my $devices_list = vm_devices_list($vmid);
 
     if(!defined($devices_list->{$scsihwid})) {
-       vm_deviceplug($storecfg, $conf, $vmid, $scsihwid);
+       vm_deviceplug($storecfg, $conf, $vmid, $scsihwid, $device);
+    }
+
+    return 1;
+}
+
+sub qemu_deletescsihw {
+    my ($conf, $vmid, $opt) = @_;
+
+    my $device = parse_drive($opt, $conf->{$opt});
+
+    if ($conf->{scsihw} && ($conf->{scsihw} eq 'virtio-scsi-single')) {
+       vm_deviceunplug($vmid, $conf, "virtioscsi$device->{index}");
+       return 1;
+    }
+
+    my ($maxdev, $controller, $controller_prefix) = scsihw_infos($conf, $device);
+
+    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;
 }
 
@@ -3498,7 +3583,7 @@ sub qemu_add_pci_bridge {
 sub qemu_set_link_status {
     my ($vmid, $device, $up) = @_;
 
-    vm_mon_cmd($vmid, "set_link", name => $device, 
+    vm_mon_cmd($vmid, "set_link", name => $device,
               up => $up ? JSON::true : JSON::false);
 }
 
@@ -3549,9 +3634,9 @@ sub qemu_memory_hotplug {
     my ($vmid, $conf, $defaults, $opt, $value) = @_;
 
     return $value if !check_running($vmid);
+
     my $memory = $conf->{memory} || $defaults->{memory};
-    $value = $defaults->{memory} if !$value; 
+    $value = $defaults->{memory} if !$value;
     return $value if $value == $memory;
 
     my $static_memory = $STATICMEM;
@@ -3769,7 +3854,7 @@ sub set_migration_caps {
 my $fast_plug_option = {
     'lock' => 1,
     'name' => 1,
-    'onboot' => 1, 
+    'onboot' => 1,
     'shares' => 1,
     'startup' => 1,
 };
@@ -3873,7 +3958,7 @@ sub vmconfig_hotplug_pending {
            } elsif ($opt eq 'balloon') {
                # enable/disable balloning device is not hotpluggable
                my $old_balloon_enabled =  !!(!defined($conf->{balloon}) || $conf->{balloon});
-               my $new_balloon_enabled =  !!(!defined($conf->{pending}->{balloon}) || $conf->{pending}->{balloon});            
+               my $new_balloon_enabled =  !!(!defined($conf->{pending}->{balloon}) || $conf->{pending}->{balloon});
                die "skip\n" if $old_balloon_enabled != $new_balloon_enabled;
 
                # allow manual ballooning if shares is set to zero
@@ -3881,9 +3966,9 @@ sub vmconfig_hotplug_pending {
                    my $balloon = $conf->{pending}->{balloon} || $conf->{memory} || $defaults->{memory};
                    vm_mon_cmd($vmid, "balloon", value => $balloon*1024*1024);
                }
-           } elsif ($opt =~ m/^net(\d+)$/) { 
+           } elsif ($opt =~ m/^net(\d+)$/) {
                # some changes can be done without hotplug
-               vmconfig_update_net($storecfg, $conf, $hotplug_features->{network}, 
+               vmconfig_update_net($storecfg, $conf, $hotplug_features->{network},
                                    $vmid, $opt, $value);
            } elsif (valid_drivename($opt)) {
                # some changes can be done without hotplug
@@ -3992,7 +4077,7 @@ sub vmconfig_update_net {
 
            die "internal error" if $opt !~ m/net(\d+)/;
            my $iface = "tap${vmid}i$1";
-               
+
            if (&$safe_num_ne($oldnet->{rate}, $newnet->{rate})) {
                PVE::Network::tap_rate_limit($iface, $newnet->{rate});
            }
@@ -4011,7 +4096,7 @@ sub vmconfig_update_net {
            return 1;
        }
     }
-    
+
     if ($hotplug) {
        vm_deviceplug($storecfg, $conf, $vmid, $opt, $newnet);
     } else {
@@ -4036,19 +4121,20 @@ sub vmconfig_update_disk {
 
            if (!drive_is_cdrom($old_drive)) {
 
-               if ($drive->{file} ne $old_drive->{file}) {  
+               if ($drive->{file} ne $old_drive->{file}) {
 
                    die "skip\n" if !$hotplug;
 
                    # unplug and register as unused
                    vm_deviceunplug($vmid, $conf, $opt);
                    vmconfig_register_unused_drive($storecfg, $vmid, $conf, $old_drive)
-       
+
                } else {
                    # update existing disk
 
                    # skip non hotpluggable value
-                   if (&$safe_num_ne($drive->{discard}, $old_drive->{discard}) || 
+                   if (&$safe_num_ne($drive->{discard}, $old_drive->{discard}) ||
+                       &$safe_string_ne($drive->{iothread}, $old_drive->{iothread}) ||
                        &$safe_string_ne($drive->{cache}, $old_drive->{cache})) {
                        die "skip\n";
                    }
@@ -4066,7 +4152,7 @@ sub vmconfig_update_disk {
                        &$safe_num_ne($drive->{iops_max}, $old_drive->{iops_max}) ||
                        &$safe_num_ne($drive->{iops_rd_max}, $old_drive->{iops_rd_max}) ||
                        &$safe_num_ne($drive->{iops_wr_max}, $old_drive->{iops_wr_max})) {
-                       
+
                        qemu_block_set_io_throttle($vmid,"drive-$opt",
                                                   ($drive->{mbps} || 0)*1024*1024,
                                                   ($drive->{mbps_rd} || 0)*1024*1024,
@@ -4082,12 +4168,12 @@ sub vmconfig_update_disk {
                                                   $drive->{iops_wr_max} || 0);
 
                    }
-                   
+
                    return 1;
                }
 
            } else { # cdrom
-               
+
                if ($drive->{file} eq 'none') {
                    vm_mon_cmd($vmid, "eject",force => JSON::true,device => "drive-$opt");
                } else {
@@ -4095,13 +4181,13 @@ sub vmconfig_update_disk {
                    vm_mon_cmd($vmid, "eject", force => JSON::true,device => "drive-$opt"); # force eject if locked
                    vm_mon_cmd($vmid, "change", device => "drive-$opt",target => "$path") if $path;
                }
-               
+
                return 1;
            }
        }
     }
 
-    die "skip\n" if !$hotplug || $opt =~ m/(ide|sata)(\d+)/;   
+    die "skip\n" if !$hotplug || $opt =~ m/(ide|sata)(\d+)/;
     # hotplug new disks
     vm_deviceplug($storecfg, $conf, $vmid, $opt, $drive);
 }
@@ -4215,7 +4301,7 @@ sub vm_start {
                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",
@@ -4338,11 +4424,11 @@ sub vm_stop_cleanup {
            my $vollist = get_vm_volumes($conf);
            PVE::Storage::deactivate_volumes($storecfg, $vollist);
        }
-       
+
        foreach my $ext (qw(mon qmp pid vnc qga)) {
            unlink "/var/run/qemu-server/${vmid}.$ext";
        }
-       
+
        vmconfig_apply_pending($vmid, $conf, $storecfg) if $apply_pending_changes;
     };
     warn $@ if $@; # avoid errors - just warn
@@ -4647,6 +4733,7 @@ sub print_pci_addr {
        balloon0 => { bus => 0, addr => 3 },
        watchdog => { bus => 0, addr => 4 },
        scsihw0 => { bus => 0, addr => 5 },
+       'pci.3' => { bus => 0, addr => 5 }, #can also be used for virtio-scsi-single bridge
        scsihw1 => { bus => 0, addr => 6 },
        ahci0 => { bus => 0, addr => 7 },
        qga0 => { bus => 0, addr => 8 },
@@ -4709,6 +4796,38 @@ sub print_pci_addr {
        'virtio13' => { bus => 2, addr => 8 },
        'virtio14' => { bus => 2, addr => 9 },
        'virtio15' => { bus => 2, addr => 10 },
+       'virtioscsi0' => { bus => 3, addr => 1 },
+       'virtioscsi1' => { bus => 3, addr => 2 },
+       'virtioscsi2' => { bus => 3, addr => 3 },
+       'virtioscsi3' => { bus => 3, addr => 4 },
+       'virtioscsi4' => { bus => 3, addr => 5 },
+       'virtioscsi5' => { bus => 3, addr => 6 },
+       'virtioscsi6' => { bus => 3, addr => 7 },
+       'virtioscsi7' => { bus => 3, addr => 8 },
+       'virtioscsi8' => { bus => 3, addr => 9 },
+       'virtioscsi9' => { bus => 3, addr => 10 },
+       'virtioscsi10' => { bus => 3, addr => 11 },
+       'virtioscsi11' => { bus => 3, addr => 12 },
+       'virtioscsi12' => { bus => 3, addr => 13 },
+       'virtioscsi13' => { bus => 3, addr => 14 },
+       'virtioscsi14' => { bus => 3, addr => 15 },
+       'virtioscsi15' => { bus => 3, addr => 16 },
+       'virtioscsi16' => { bus => 3, addr => 17 },
+       'virtioscsi17' => { bus => 3, addr => 18 },
+       'virtioscsi18' => { bus => 3, addr => 19 },
+       'virtioscsi19' => { bus => 3, addr => 20 },
+       'virtioscsi20' => { bus => 3, addr => 21 },
+       'virtioscsi21' => { bus => 3, addr => 22 },
+       'virtioscsi22' => { bus => 3, addr => 23 },
+       'virtioscsi23' => { bus => 3, addr => 24 },
+       'virtioscsi24' => { bus => 3, addr => 25 },
+       'virtioscsi25' => { bus => 3, addr => 26 },
+       'virtioscsi26' => { bus => 3, addr => 27 },
+       'virtioscsi27' => { bus => 3, addr => 28 },
+       'virtioscsi28' => { bus => 3, addr => 29 },
+       'virtioscsi29' => { bus => 3, addr => 30 },
+       'virtioscsi30' => { bus => 3, addr => 31 },
+
     };
 
     if (defined($devices->{$id}->{bus}) && defined($devices->{$id}->{addr})) {
@@ -6162,4 +6281,36 @@ sub lspci {
     return $devices;
 }
 
+sub vm_iothreads_list {
+    my ($vmid) = @_;
+
+    my $res = vm_mon_cmd($vmid, 'query-iothreads');
+
+    my $iothreads = {};
+    foreach my $iothread (@$res) {
+       $iothreads->{ $iothread->{id} } = $iothread->{"thread-id"};
+    }
+
+    return $iothreads;
+}
+
+sub scsihw_infos {
+    my ($conf, $drive) = @_;
+
+    my $maxdev = 0;
+
+    if ($conf->{scsihw} && ($conf->{scsihw} =~ m/^lsi/)) {
+        $maxdev = 7;
+    } elsif ($conf->{scsihw} && ($conf->{scsihw} eq 'virtio-scsi-single')) {
+        $maxdev = 1;
+    } else {
+        $maxdev = 256;
+    }
+
+    my $controller = int($drive->{index} / $maxdev);
+    my $controller_prefix = ($conf->{scsihw} && $conf->{scsihw} eq 'virtio-scsi-single') ? "virtioscsi" : "scsihw";
+
+    return ($maxdev, $controller, $controller_prefix);
+}
+
 1;