[pve-devel] [PATCH] unplug scsi controller if no more disk exist

Alexandre Derumier aderumier at odiso.com
Fri Feb 13 13:32:16 CET 2015


we need to remove scsi controller, because live migration will crash,

as on migration target node, we'll start the vm without controller if no disk exist

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

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 032cfb0..cd9b09f 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -3337,15 +3337,17 @@ sub vm_deviceunplug {
         qemu_devicedelverify($vmid, $deviceid);
         qemu_drivedel($vmid, $deviceid);
    
-    } elsif ($deviceid =~ m/^(lsi)(\d+)$/) {
+    } elsif ($deviceid =~ m/^(scsihw)(\d+)$/) {
     
 	qemu_devicedel($vmid, $deviceid);
+	qemu_devicedelverify($vmid, $deviceid);
     
     } elsif ($deviceid =~ m/^(scsi)(\d+)$/) {
 
         qemu_devicedel($vmid, $deviceid);
         qemu_drivedel($vmid, $deviceid);
-    
+	qemu_deletescsihw($conf, $vmid, $deviceid);
+
     } elsif ($deviceid =~ m/^(net)(\d+)$/) {
 
         qemu_devicedel($vmid, $deviceid);
@@ -3459,6 +3461,31 @@ sub qemu_findorcreatescsihw {
     return 1;
 }
 
+sub qemu_deletescsihw {
+    my ($conf, $vmid, $opt) = @_;
+
+    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 $scsihwid="scsihw$controller";
+
+    vm_deviceunplug($vmid, $conf, $scsihwid);
+
+    return 1;
+}
+
 sub qemu_add_pci_bridge {
     my ($storecfg, $conf, $vmid, $device) = @_;
 
-- 
1.7.10.4




More information about the pve-devel mailing list