[pve-devel] [PATCH 2/2] implement virtio-scsi iothread hotplug

Alexandre Derumier aderumier at odiso.com
Mon Mar 23 06:29:34 CET 2015


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

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 9d5ff20..b081041 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -3296,11 +3296,14 @@ sub vm_deviceplug {
 	    die $err;
         }
 
-    } elsif ($deviceid =~ m/^(scsihw)(\d+)$/) {
+    } elsif ($deviceid =~ m/^(scsihw)(scsi)?(\d+)$/) {
+
+	qemu_iothread_add($vmid, $deviceid, $device);
 
         my $scsihw = defined($conf->{scsihw}) ? $conf->{scsihw} : "lsi";
         my $pciaddr = print_pci_addr($deviceid);
         my $devicefull = "$scsihw,id=$deviceid$pciaddr";
+	$devicefull .= ",iothread=iothread-$deviceid" if $device->{iothread};
 
         qemu_deviceadd($vmid, $devicefull);
         qemu_deviceaddverify($vmid, $deviceid);
@@ -3366,10 +3369,11 @@ sub vm_deviceunplug {
         qemu_drivedel($vmid, $deviceid);
 	qemu_iothread_del($conf, $vmid, $deviceid);
 
-    } elsif ($deviceid =~ m/^(scsihw)(\d+)$/) {
+    } elsif ($deviceid =~ m/^(scsihw)(scsi)?(\d+)$/) {
     
 	qemu_devicedel($vmid, $deviceid);
 	qemu_devicedelverify($vmid, $deviceid);
+	qemu_iothread_del($conf, $vmid, $deviceid);
     
     } elsif ($deviceid =~ m/^(scsi)(\d+)$/) {
 
@@ -3499,12 +3503,18 @@ 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 $controller = undef;
+    if($conf->{scsihw} && $conf->{scsihw} =~ m/^virtio-scsi-pci/ && $device->{iothread}){
+	$controller = "$device->{interface}$device->{index}";
+    } else {
+	$controller = int($device->{index} / $maxdev);
+    }
+
     my $scsihwid="scsihw$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;
@@ -3516,14 +3526,21 @@ sub qemu_deletescsihw {
     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 $controller = undef;
+    if($conf->{scsihw} && $conf->{scsihw} =~ m/^virtio-scsi-pci/ && $device->{iothread}){
+	$controller = "$device->{interface}$device->{index}";
+    } else {
+	$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->{iothread} &&
+		   $drive->{index} < (($maxdev-1)*($controller+1))) {
+		    return 1;
+		}
 	    }
 	}
     }
-- 
1.7.10.4




More information about the pve-devel mailing list