[pve-devel] [PATCH 06/12] vm_deviceunplug : pending changes

Alexandre Derumier aderumier at odiso.com
Thu Oct 30 13:40:27 CET 2014


for disks, we set them as unused after succesfull unplug

[CONF]
virtio0: vm-disk-100-1.raw
net0: ....

[CONF]
virtio0: vm-disk-100-1.raw
unused0: vm-disk-100-1.raw
net0: ...
[PENDING]
delete: virtio0,net0

for all devices, after successfull unplug,
  we delete the device from the conf and remove the pending change

[CONF]
unused0: vm-disk-100-1.raw
[PENDING]

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

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index bf099b2..52bcd1f 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -3020,17 +3020,22 @@ sub vm_deviceplug {
 }
 
 sub vm_deviceunplug {
-    my ($vmid, $conf, $deviceid) = @_;
+    my ($vmid, $conf, $deviceid, $optvalue) = @_;
 
-    return 1 if !check_running ($vmid);
+    return 1 if !check_running($vmid);
 
     if ($deviceid eq 'tablet') {
-	qemu_devicedel($vmid, $deviceid);
+	eval { qemu_devicedel($vmid, $deviceid) };
+	$conf->{$deviceid} = $conf->{pending}->{$deviceid};
+	delete $conf->{pending}->{$deviceid};
+	PVE::QemuServer::update_config_nolock($vmid, $conf, 1);
 	return 1;
     }
 
     return 1 if !$conf->{hotplug};
 
+    return 1 if ($deviceid =~ m/^(ide|sata)(\d+)$/);
+
     my $devices_list = vm_devices_list($vmid);
     return 1 if !defined($devices_list->{$deviceid});
 
@@ -3040,6 +3045,10 @@ sub vm_deviceunplug {
         qemu_devicedel($vmid, $deviceid);
         return undef if !qemu_devicedelverify($vmid, $deviceid);
         return undef if !qemu_drivedel($vmid, $deviceid);
+
+	my $drive = PVE::QemuServer::parse_drive($deviceid, $conf->{$deviceid});
+        PVE::QemuServer::add_unused_volume($conf, $drive->{file});
+
     }
 
     if ($deviceid =~ m/^(lsi)(\d+)$/) {
@@ -3049,6 +3058,10 @@ sub vm_deviceunplug {
     if ($deviceid =~ m/^(scsi)(\d+)$/) {
         return undef if !qemu_devicedel($vmid, $deviceid);
         return undef if !qemu_drivedel($vmid, $deviceid);
+
+	my $drive = PVE::QemuServer::parse_drive($deviceid, $conf->{$deviceid});
+        PVE::QemuServer::add_unused_volume($conf, $drive->{file});
+
     }
 
     if ($deviceid =~ m/^(net)(\d+)$/) {
@@ -3057,6 +3070,13 @@ sub vm_deviceunplug {
         return undef if !qemu_netdevdel($vmid, $deviceid);
     }
 
+    if($conf->{$deviceid}){
+
+	delete $conf->{$deviceid};
+	delete $conf->{pending}->{del}->{$deviceid};
+	PVE::QemuServer::update_config_nolock($vmid, $conf, 1);
+    }
+
     return 1;
 }
 
-- 
1.7.10.4




More information about the pve-devel mailing list