From: Hannes Laimer <h.laimer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v1 qemu-server 4/5] add fields inrate and outrate to net_fmt, map rate of old configs to out/inrate
Date: Fri, 11 Sep 2020 12:08:15 +0200 [thread overview]
Message-ID: <20200911100816.80543-5-h.laimer@proxmox.com> (raw)
In-Reply-To: <20200911100816.80543-1-h.laimer@proxmox.com>
Signed-off-by: Hannes Laimer <h.laimer@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
next prev parent reply other threads:[~2020-09-11 10:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-11 10:08 [pve-devel] [PATCH v1 series 0/5] limit out and inrate of network device Hannes Laimer
2020-09-11 10:08 ` [pve-devel] [PATCH v1 pve-common 1/5] replace rate with out/in-rate in setup_tc_rate_limit and tap_rate_limit Hannes Laimer
2021-02-06 14:29 ` Thomas Lamprecht
2020-09-11 10:08 ` [pve-devel] [PATCH v1 pve-common 2/5] add out/in-rate parameter to tap_plug sub, keep version with just rate param Hannes Laimer
2021-02-06 14:22 ` Thomas Lamprecht
2021-04-29 14:57 ` Thomas Lamprecht
2020-09-11 10:08 ` [pve-devel] [PATCH v1 pve-network 3/5] " Hannes Laimer
2020-09-11 10:08 ` Hannes Laimer [this message]
2020-09-11 10:08 ` [pve-devel] [PATCH v1 pve-manager 5/5] out/in-rate in network edit, keep rate to still be able to open old configs Hannes Laimer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200911100816.80543-5-h.laimer@proxmox.com \
--to=h.laimer@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.