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

Alexandre Derumier aderumier at odiso.com
Fri Jan 16 11:00:54 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 6d6d2f7..facae11 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -3260,15 +3260,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);
@@ -3366,6 +3368,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