[pve-devel] [PATCH 6/9] implement virtio-scsi iothread

Alexandre Derumier aderumier at odiso.com
Fri Jan 16 11:00:58 CET 2015


iothread can only be enabled by virtio-scsi-pci,

currently we use 1 controller for all virtio-scsi.

This patch create 1 virtio-scsi-pci controller for each virtio-scsi drive with iothread enable

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/QemuServer.pm |   47 ++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 42 insertions(+), 5 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 927e79c..6d96018 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -546,7 +546,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=yes]',
     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);
@@ -1113,7 +1113,8 @@ sub print_drivedevice_full {
 	$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 $controller = find_scsihw_controller($conf, $drive);
 	my $unit = $drive->{index} % $maxdev;
 	my $devicetype = 'hd';
         my $path = '';
@@ -3017,10 +3018,16 @@ sub config_to_command {
 
         if ($drive->{interface} eq 'scsi') {
 
-	    my $maxdev = ($scsihw !~ m/^lsi/) ? 256 : 7;
-	    my $controller = int($drive->{index} / $maxdev);
+	    my $controller = find_scsihw_controller($conf, $drive);
+
+	    my $iothread = '';
+	    if($conf->{scsihw} && $conf->{scsihw} =~ m/^virtio-scsi-pci/ && $drive->{iothread}){
+		$iothread .= ",iothread=iothread-scsihw$controller";
+		push @$cmd, '-object', "iothread,id=iothread-scsihw$controller";
+	    }
+
 	    $pciaddr = print_pci_addr("scsihw$controller", $bridges);
-	    push @$devices, '-device', "$scsihw,id=scsihw$controller$pciaddr" if !$scsicontroller->{$controller};
+	    push @$devices, '-device', "$scsihw,id=scsihw$controller$pciaddr$iothread" if !$scsicontroller->{$controller};
 	    $scsicontroller->{$controller}=1;
         }
 
@@ -4586,6 +4593,22 @@ sub print_pci_addr {
 	'virtio13' => { bus => 2, addr => 8 },
 	'virtio14' => { bus => 2, addr => 9 },
 	'virtio15' => { bus => 2, addr => 10 },
+	'scsihwscsi0' => { bus => 2, addr => 11 },
+	'scsihwscsi1' => { bus => 2, addr => 12 },
+	'scsihwscsi2' => { bus => 2, addr => 13 },
+	'scsihwscsi3' => { bus => 2, addr => 14 },
+	'scsihwscsi4' => { bus => 2, addr => 15 },
+	'scsihwscsi5' => { bus => 2, addr => 16 },
+	'scsihwscsi6' => { bus => 2, addr => 17 },
+	'scsihwscsi7' => { bus => 2, addr => 18 },
+	'scsihwscsi8' => { bus => 2, addr => 19 },
+	'scsihwscsi9' => { bus => 2, addr => 20 },
+	'scsihwscsi10' => { bus => 2, addr => 21 },
+	'scsihwscsi11' => { bus => 2, addr => 22 },
+	'scsihwscsi12' => { bus => 2, addr => 23 },
+	'scsihwscsi13' => { bus => 2, addr => 24 },
+	'scsihwscsi14' => { bus => 2, addr => 25 },
+
     };
 
     if (defined($devices->{$id}->{bus}) && defined($devices->{$id}->{addr})) {
@@ -6011,4 +6034,18 @@ sub vm_iothreads_list {
     return $iothreads;
 }
 
+sub find_scsihw_controller {
+    my($conf, $drive) = @_;
+
+    my $maxdev = ($conf->{scsihw} && ($conf->{scsihw} !~ m/^lsi/)) ? 256 : 7;
+    my $controller = undef;
+
+    if($conf->{scsihw} && $conf->{scsihw} =~ m/^virtio-scsi-pci/ && $drive->{iothread}){
+	$controller = "$drive->{interface}$drive->{index}";
+    } else {
+	$controller = int($drive->{index} / $maxdev);
+    }
+
+    return $controller;
+}
 1;
-- 
1.7.10.4



More information about the pve-devel mailing list