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

Alexandre Derumier aderumier at odiso.com
Fri Mar 27 03:41:53 CET 2015


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

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index f55087c..9ee770a 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -3304,11 +3304,13 @@ 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 =~ m/^virtio-scsi-single/ ? "virtio-scsi-pci" : $scsihw; 
+
+        my $devicefull = "$scsihw_type,id=$deviceid$pciaddr";
 
         qemu_deviceadd($vmid, $devicefull);
         qemu_deviceaddverify($vmid, $deviceid);
@@ -3374,7 +3376,7 @@ sub vm_deviceunplug {
         qemu_drivedel($vmid, $deviceid);
 	qemu_iothread_del($conf, $vmid, $deviceid);
 
-    } elsif ($deviceid =~ m/^(scsihw)(\d+)$/) {
+    } elsif ($deviceid =~ m/^(virtioscsi|scsihw)(\d+)$/) {
     
 	qemu_devicedel($vmid, $deviceid);
 	qemu_devicedelverify($vmid, $deviceid);
@@ -3506,9 +3508,19 @@ sub qemu_devicedelverify {
 sub qemu_findorcreatescsihw {
     my ($storecfg, $conf, $vmid, $device) = @_;
 
-    my $maxdev = ($conf->{scsihw} && ($conf->{scsihw} !~ m/^lsi/)) ? 256 : 7;
+    my $maxdev = 0;
+    if ($conf->{scsihw} && ($conf->{scsihw} =~ m/^lsi/)) {
+        $maxdev = 7;
+    } elsif ($conf->{scsihw} && ($conf->{scsihw} =~ m/^virtio-scsi-single/)) {
+        $maxdev = 1;
+    } else {
+        $maxdev = 256;
+    }
+
     my $controller = int($device->{index} / $maxdev);
-    my $scsihwid="scsihw$controller";
+    my $controller_prefix = ($conf->{scsihw} && $conf->{scsihw} =~ m/^virtio-scsi-single/) ? "virtioscsi" : "scsihw";
+
+    my $scsihwid="$controller_prefix$controller";
     my $devices_list = vm_devices_list($vmid);
 
     if(!defined($devices_list->{$scsihwid})) {
@@ -3523,6 +3535,11 @@ sub qemu_deletescsihw {
 
     my $device = parse_drive($opt, $conf->{$opt});
 
+    if ($conf->{scsihw} && ($conf->{scsihw} =~ m/^virtio-scsi-single/)) {
+	vm_deviceunplug($vmid, $conf, "virtioscsi$device->{index}");
+	return 1;
+    }
+
     my $maxdev = ($conf->{scsihw} && ($conf->{scsihw} !~ m/^lsi/)) ? 256 : 7;
     my $controller = int($device->{index} / $maxdev);
 
-- 
1.7.10.4




More information about the pve-devel mailing list