From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id A5FA460FA7 for ; Fri, 11 Sep 2020 12:08:56 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 06D39239B8 for ; Fri, 11 Sep 2020 12:08:25 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 6F8F62395B for ; Fri, 11 Sep 2020 12:08:23 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 2DEC144B60 for ; Fri, 11 Sep 2020 12:08:23 +0200 (CEST) From: Hannes Laimer To: pve-devel@lists.proxmox.com Date: Fri, 11 Sep 2020 12:08:15 +0200 Message-Id: <20200911100816.80543-5-h.laimer@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200911100816.80543-1-h.laimer@proxmox.com> References: <20200911100816.80543-1-h.laimer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [qemuserver.pm] 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 X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Sep 2020 10:08:56 -0000 Signed-off-by: Hannes Laimer --- 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= +# netX: e1000=XX:XX:XX:XX:XX:XX,bridge=vmbr0,outrate=,inrate=,[rate=]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