[pve-devel] [PATCH v1 qemu-server 4/5] add fields inrate and outrate to net_fmt, map rate of old configs to out/inrate

Hannes Laimer h.laimer at proxmox.com
Fri Sep 11 12:08:15 CEST 2020


Signed-off-by: Hannes Laimer <h.laimer at proxmox.com>
---
 PVE/QemuServer.pm             | 35 +++++++++++++++++++++++++++++------
 vm-network-scripts/pve-bridge |  9 ++++++---
 2 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 2747c66..ff59d78 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -886,6 +886,18 @@ my $net_fmt = {
 	description => "Rate limit in mbps (megabytes per second) as floating point number.",
 	optional => 1,
     },
+    outrate => {
+	type => 'number',
+	minimum => 0,
+	description => "Upload rate limit in mbps (megabytes per second) as floating point number.",
+	optional => 1,
+    },
+    inrate => {
+	type => 'number',
+	minimum => 0,
+	description => "Download rate limit in mbps (megabytes per second) as floating point number.",
+	optional => 1,
+	},
     tag => {
 	type => 'integer',
 	minimum => 1, maximum => 4094,
@@ -1732,7 +1744,7 @@ sub parse_numa {
     return $res;
 }
 
-# netX: e1000=XX:XX:XX:XX:XX:XX,bridge=vmbr0,rate=<mbps>
+# netX: e1000=XX:XX:XX:XX:XX:XX,bridge=vmbr0,outrate=<mbps>,inrate=<mbps>,[rate=<mbps>]deprecated
 sub parse_net {
     my ($data) = @_;
 
@@ -3473,7 +3485,10 @@ sub config_to_command {
 	 next if !$d;
 
 	 $use_virtio = 1 if $d->{model} eq 'virtio';
-
+	# setting in/out-rate to rate if rate is set and in/out-rate is not set
+	# if in/out-rate was changed by the user, rate will always be empty
+	$d->{inrate} = $d->{rate} if !$d->{inrate} && $d->{rate};
+	$d->{outrate} = $d->{rate} if !$d->{outrate} && $d->{rate};
 	 if ($bootindex_hash->{n}) {
 	    $d->{bootindex} = $bootindex_hash->{n};
 	    $bootindex_hash->{n} += 1;
@@ -4625,6 +4640,12 @@ sub vmconfig_update_net {
 	    die "internal error" if $opt !~ m/net(\d+)/;
 	    my $iface = "tap${vmid}i$1";
 
+	    # setting out/in-rate to old rate if rate is set and both new and old out/in-rate are not set
+	    # needed for backwards-compatibility, only applies if old config has not changed since update
+            # if the out/in-rate was changed by the user rate will always be empty
+	    $newnet->{inrate} = $oldnet->{rate} if !$oldnet->{inrate} && !$newnet->{inrate} && $oldnet->{rate};
+	    $newnet->{outrate} = $oldnet->{rate} if !$oldnet->{outrate} && !$newnet->{outrate} && $oldnet->{rate};
+
 	    if (safe_string_ne($oldnet->{bridge}, $newnet->{bridge}) ||
 		safe_num_ne($oldnet->{tag}, $newnet->{tag}) ||
 		safe_string_ne($oldnet->{trunks}, $newnet->{trunks}) ||
@@ -4632,14 +4653,16 @@ sub vmconfig_update_net {
 		PVE::Network::tap_unplug($iface);
 
 		if ($have_sdn) {
-		    PVE::Network::SDN::Zones::tap_plug($iface, $newnet->{bridge}, $newnet->{tag}, $newnet->{firewall}, $newnet->{trunks}, $newnet->{rate});
+		    PVE::Network::SDN::Zones::tap_plug($iface, $newnet->{bridge}, $newnet->{tag}, $newnet->{firewall}, $newnet->{trunks}, $newnet->{outrate}, $newnet->{inrate});
 		} else {
-		    PVE::Network::tap_plug($iface, $newnet->{bridge}, $newnet->{tag}, $newnet->{firewall}, $newnet->{trunks}, $newnet->{rate});
+		    PVE::Network::tap_plug($iface, $newnet->{bridge}, $newnet->{tag}, $newnet->{firewall}, $newnet->{trunks}, $newnet->{outrate}, $newnet->{inrate});
 		}
-	    } elsif (safe_num_ne($oldnet->{rate}, $newnet->{rate})) {
+	    } elsif (safe_num_ne($oldnet->{inrate}, $newnet->{inrate}) ||
+		    safe_num_ne($oldnet->{outrate}, $newnet->{outrate})) {
+
 		# Rate can be applied on its own but any change above needs to
 		# include the rate in tap_plug since OVS resets everything.
-		PVE::Network::tap_rate_limit($iface, $newnet->{rate});
+		PVE::Network::tap_rate_limit($iface, $newnet->{outrate}, $newnet->{inrate});
 	    }
 
 	    if (safe_string_ne($oldnet->{link_down}, $newnet->{link_down})) {
diff --git a/vm-network-scripts/pve-bridge b/vm-network-scripts/pve-bridge
index d37ce33..4dfd369 100755
--- a/vm-network-scripts/pve-bridge
+++ b/vm-network-scripts/pve-bridge
@@ -42,13 +42,16 @@ die "unable to get network config '$netid'\n"
 
 my $net = PVE::QemuServer::parse_net($netconf);
 die "unable to parse network config '$netid'\n" if !$net;
-
+# setting out/in-rate to rate if rate is set and out/in-rate is not set
+# if out/int-rate was changed by the user, rate will always be empty
+$net->{outrate} = $net->{rate} if !$net->{outrate} && $net->{rate};
+$net->{inrate} = $net->{rate} if !$net->{inrate} && $net->{rate};
 if ($have_sdn) {
     PVE::Network::SDN::Zones::tap_create($iface, $net->{bridge});
-    PVE::Network::SDN::Zones::tap_plug($iface, $net->{bridge}, $net->{tag}, $net->{firewall}, $net->{trunks}, $net->{rate});
+    PVE::Network::SDN::Zones::tap_plug($iface, $net->{bridge}, $net->{tag}, $net->{firewall}, $net->{trunks}, $net->{outrate}, $net->{inrate});
 } else {
     PVE::Network::tap_create($iface, $net->{bridge});
-    PVE::Network::tap_plug($iface, $net->{bridge}, $net->{tag}, $net->{firewall}, $net->{trunks}, $net->{rate});
+    PVE::Network::tap_plug($iface, $net->{bridge}, $net->{tag}, $net->{firewall}, $net->{trunks}, $net->{outrate}, $net->{inrate});
 }
 
 exit 0;
-- 
2.20.1






More information about the pve-devel mailing list