[pve-devel] [PATCH 7/7] add vmconfig_write_pending_option

Alexandre Derumier aderumier at odiso.com
Tue Nov 18 13:39:52 CET 2014


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

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index dfea063..7ed6d04 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -1403,6 +1403,15 @@ sub vm_is_volid_owner {
     return undef;
 }
 
+sub vmconfig_write_pending_option {
+    my ($vmid, $conf, $opt) = @_;
+
+    $conf->{$opt} = $conf->{pending}->{$opt};
+    delete $conf->{pending}->{$opt};
+    PVE::QemuServer::update_config_nolock($vmid, $conf, 1);
+
+}
+
 sub vmconfig_delete_pending_option {
     my ($conf, $key) = @_;
 
@@ -3515,25 +3524,21 @@ sub vmconfig_hotplug_pending {
 
 	    if($conf->{pending}->{$opt} == 1){
 		if(PVE::QemuServer::vm_deviceplug(undef, $conf, $vmid, $opt, $conf->{pending}->{$opt})){
-		    $conf->{$opt} = $conf->{pending}->{$opt};
-		    delete $conf->{pending}->{$opt};
+		    vmconfig_write_pending_option($vmid, $conf, $opt); 
 		}
 	    } elsif($conf->{pending}->{$opt} == 0){
 		if(PVE::QemuServer::vm_deviceunplug($vmid, $conf, $opt)){
-		    $conf->{$opt} = $conf->{pending}->{$opt};
-		    delete $conf->{pending}->{$opt};
+		    vmconfig_write_pending_option($vmid, $conf, $opt); 
 		}
 	    }
 	} elsif($opt eq 'cores'){
 	    if(PVE::QemuServer::qemu_cpu_hotplug($vmid, $conf, $conf->{pending}->{$opt})){
-		$conf->{$opt} = $conf->{pending}->{$opt};
-		delete $conf->{pending}->{$opt};
+		vmconfig_write_pending_option($vmid, $conf, $opt); 
 	    }
         }
 
     }
 
-    update_config_nolock($vmid, $conf, 1);
     $conf = load_config($vmid); # update/reload
 
 }
@@ -3640,9 +3645,7 @@ sub vmconfig_update_net {
                     PVE::Network::tap_plug($iface, $newnet->{bridge}, $newnet->{tag}, $newnet->{firewall});
                 }
 
-                $conf->{$opt} = $conf->{pending}->{$opt};
-                delete $conf->{pending}->{$opt};
-                PVE::QemuServer::update_config_nolock($vmid, $conf, 1);
+		vmconfig_write_pending_option($vmid, $conf, $opt);
                 return;
 
             }else{
@@ -3661,9 +3664,7 @@ sub vmconfig_update_net {
     if($conf->{pending}->{$opt}){
         my $net = PVE::QemuServer::parse_net($conf->{pending}->{$opt});
         if(PVE::QemuServer::vm_deviceplug($storecfg, $conf, $vmid, $opt, $net, $conf->{pending}->{$opt})){
-	    $conf->{$opt} = $conf->{pending}->{$opt};
-	    delete $conf->{pending}->{$opt};
-	    PVE::QemuServer::update_config_nolock($vmid, $conf, 1);
+	    vmconfig_write_pending_option($vmid, $conf, $opt);
 	}
     }
 
@@ -3728,8 +3729,7 @@ sub vmconfig_update_disk {
 							   $drive->{iops_wr_max} || 0);
 
 		    }
-		    $conf->{$opt} = $conf->{pending}->{$opt};
-		    delete $conf->{pending}->{$opt};
+		    vmconfig_write_pending_option($vmid, $conf, $opt);
 		    return;
 		}
 	    }
@@ -3748,12 +3748,10 @@ sub vmconfig_update_disk {
 		PVE::QemuServer::vm_mon_cmd($vmid, "change",device => "drive-$opt",target => "$path") if $path;
 	    }
 	}
-	$conf->{$opt} = $conf->{pending}->{$opt};
-	delete $conf->{pending}->{$opt};	
+	vmconfig_write_pending_option($vmid, $conf, $opt);
 
     } elsif (PVE::QemuServer::vm_deviceplug($storecfg, $conf, $vmid, $opt, $drive, $pendingvalue)){
-            $conf->{$opt} = $conf->{pending}->{$opt};
-            delete $conf->{pending}->{$opt};
+	vmconfig_write_pending_option($vmid, $conf, $opt);
     }
 
 };
-- 
1.7.10.4




More information about the pve-devel mailing list