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

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


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

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 6d96018..f9d6955 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -3195,12 +3195,14 @@ sub vm_deviceplug {
 	    die $err;
         }
 
-    } elsif ($deviceid =~ m/^(scsihw)(\d+)$/) {
+    } elsif ($deviceid =~ m/^(scsihw)(scsi)?(\d+)$/) {
 
         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_iothread_add($vmid, $deviceid, $device);
         qemu_deviceadd($vmid, $devicefull);
         qemu_deviceaddverify($vmid, $deviceid);
 
@@ -3267,10 +3269,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+)$/) {
 
@@ -3398,8 +3401,7 @@ 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 $controller = find_scsihw_controller($conf, $device);
     my $scsihwid="scsihw$controller";
     my $devices_list = vm_devices_list($vmid);
 
@@ -3416,20 +3418,26 @@ 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 $controller = find_scsihw_controller($conf, $device);
+    my $scsihwid = "scsihw$controller";
+
+    if($conf->{scsihw} && $conf->{scsihw} =~ m/^virtio-scsi-pci/ && $device->{iothread}){
+	vm_deviceunplug($vmid, $conf, $scsihwid);
+	return 1;
+    }
 
     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;
+	    if($drive->{interface} eq 'scsi') {
+		my $controller = find_scsihw_controller($conf, $drive);
+		next if $controller =~ m/^scsi(\d+)/;
+		return 1 if $drive->{index} < (($maxdev-1)*($controller+1));
 	    }
 	}
     }
 
-    my $scsihwid="scsihw$controller";
-
     vm_deviceunplug($vmid, $conf, $scsihwid);
 
     return 1;
-- 
1.7.10.4




More information about the pve-devel mailing list