[pve-devel] [PATCH 04/12] vmconfig_delete_option : implement pending changes

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


1) we write delete option in hash
    $conf->{pending}->{del}->{$opt} = 1;

[CONF]
name: test
hotplug: 1
net0: ....

qm set -delete name,hotplug

[CONF]
name: test
hotplug: 1
[PENDING]
delete: name,hotplug,net0

2) if option can be delete online,
   we delete it from conf and remove pending delete

[CONF]
hotplug: 1
net0: ...
[PENDING]
delete: hotplug,net0

3) we hot-unplug the device

[CONF]
name: test
hotplug: 1
[PENDING]
delete: hotplug

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/API2/Qemu.pm |   35 +++++++++++++++++++----------------
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index add1389..40f6eb4 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -729,29 +729,32 @@ my $vmconfig_delete_option = sub {
 	}
     }
 
-    my $unplugwarning = "";
-    if ($conf->{ostype} && $conf->{ostype} eq 'l26') {
-	$unplugwarning = "<br>verify that you have acpiphp && pci_hotplug modules loaded in your guest VM";
-    } elsif ($conf->{ostype} && $conf->{ostype} eq 'l24') {
-	$unplugwarning = "<br>kernel 2.4 don't support hotplug, please disable hotplug in options";
-    } elsif (!$conf->{ostype} || ($conf->{ostype} && $conf->{ostype} eq 'other')) {
-	$unplugwarning = "<br>verify that your guest support acpi hotplug";
-    }
-
-    if ($opt eq 'tablet') {
-	PVE::QemuServer::vm_deviceplug(undef, $conf, $vmid, $opt);
-    } else {
-        die "error hot-unplug $opt $unplugwarning" if !PVE::QemuServer::vm_deviceunplug($vmid, $conf, $opt);
-    }
-
+    #add to pending the device to delete
     if ($isDisk) {
 	my $drive = PVE::QemuServer::parse_drive($opt, $conf->{$opt});
 	&$delete_drive($conf, $storecfg, $vmid, $opt, $drive, $force);
     } else {
+	$conf->{pending}->{del}->{$opt} = 1;
+	#delete pending update if exist
+	delete $conf->{pending}->{$opt};
+    }
+    PVE::QemuServer::update_config_nolock($vmid, $conf, 1);
+
+    #online value change
+    if(&$is_hotpluggable($opt)){
 	delete $conf->{$opt};
+	delete $conf->{pending}->{del}->{$opt};
+	PVE::QemuServer::update_config_nolock($vmid, $conf, 1);
+	return;
+    }
+    
+     #unplug
+    if ($opt eq 'tablet') {
+	warn "error hotplug $opt" if !PVE::QemuServer::vm_deviceplug(undef, $conf, $vmid, $opt);
+    } else {
+        warn "error hot-unplug $opt" if !PVE::QemuServer::vm_deviceunplug($vmid, $conf, $opt);
     }
 
-    PVE::QemuServer::update_config_nolock($vmid, $conf, 1);
 };
 
 my $safe_num_ne = sub {
-- 
1.7.10.4




More information about the pve-devel mailing list