[pve-devel] [PATCH 2/2] dynamic rate limit change on network update

Alexandre Derumier aderumier at odiso.com
Mon Mar 4 16:23:44 CET 2013


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

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 1597e68..50a75c7 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
 
@@ -750,10 +751,19 @@ my $vmconfig_update_net = sub {
     my ($rpcenv, $authuser, $conf, $storecfg, $vmid, $opt, $value) = @_;
 
     if ($conf->{$opt}) {
+	my $oldnet = PVE::QemuServer::parse_net($conf->{$opt});
+	my $newnet = PVE::QemuServer::parse_net($value);
+
+	if(($newnet->{rate} && $newnet->{rate} ne $oldnet->{rate}) || ($oldnet->{rate} && !$newnet->{rate})){
+	    if($opt =~ m/net(\d+)/){
+		my $iface = "tap".$vmid."i".$1;
+		PVE::Network::tap_rate_limit($iface, $newnet->{rate});
+	    }
+	}
+
 	#if online update, then unplug first
 	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