[pve-devel] [PATCH 4/4] dynamic bridge rate/vlan change on nic update

Alexandre Derumier aderumier at odiso.com
Tue Mar 5 10:22:18 CET 2013


if model change : we try to unplug like before
if bridge/nat change : we try to unplug like before

else if bridge, but rate/vlan/bridge change, we dynamicly change them without need hotplug

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

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 1597e68..d807693 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -16,6 +16,7 @@ use PVE::QemuMigrate;
 use PVE::RPCEnvironment;
 use PVE::AccessControl;
 use PVE::INotify;
+use PVE::Network;
 
 use Data::Dumper; # fixme: remove
 
@@ -749,11 +750,34 @@ my $vmconfig_update_disk = sub {
 my $vmconfig_update_net = sub {
     my ($rpcenv, $authuser, $conf, $storecfg, $vmid, $opt, $value) = @_;
 
-    if ($conf->{$opt}) {
-	#if online update, then unplug first
-	die "error hot-unplug $opt for update" if !PVE::QemuServer::vm_deviceunplug($vmid, $conf, $opt);
-    }
+    if ($conf->{$opt} && PVE::QemuServer::check_running($vmid)) {
+	my $oldnet = PVE::QemuServer::parse_net($conf->{$opt});
+	my $newnet = PVE::QemuServer::parse_net($value);
+
+	if($oldnet->{model} ne $newnet->{model}){
+	    #if model change, we try to hot-unplug
+            die "error hot-unplug $opt for update" if !PVE::QemuServer::vm_deviceunplug($vmid, $conf, $opt);
+	}else{
+		
+	    if($newnet->{bridge} && $oldnet->{bridge}){
+		my $iface = "tap".$vmid."i".$1 if $opt =~ m/net(\d+)/;
 
+		if($newnet->{rate} ne $oldnet->{rate}){
+		    PVE::Network::tap_rate_limit($iface, $newnet->{rate});
+		}
+
+		if(($newnet->{bridge} ne $oldnet->{bridge}) || ($newnet->{tag} ne $oldnet->{tag})){
+		    eval{PVE::Network::tap_unplug($iface, $oldnet->{bridge}, $oldnet->{tag});};
+		    PVE::Network::tap_plug($iface, $newnet->{bridge}, $newnet->{tag});
+		}
+
+	    }else{
+		#if bridge/nat mode change, we try to hot-unplug
+		die "error hot-unplug $opt for update" if !PVE::QemuServer::vm_deviceunplug($vmid, $conf, $opt);
+	    }
+	}
+	
+    }
     $conf->{$opt} = $value;
     PVE::QemuServer::update_config_nolock($vmid, $conf, 1);
     $conf = PVE::QemuServer::load_config($vmid); # update/reload
-- 
1.7.10.4




More information about the pve-devel mailing list