From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 0C1CB1FF2CA for ; Tue, 23 Jul 2024 12:04:48 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E05DE653; Tue, 23 Jul 2024 12:05:21 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Tue, 23 Jul 2024 12:04:48 +0200 Message-Id: <20240723100448.1571064-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.016 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment 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. [main.rs] Subject: [pbs-devel] [PATCH proxmox-backup] fix #5622: backup client: properly handle rate/burst parameters X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" the rate and burst parameters are integers, so the mapping from value with `.as_str()` will always return `None` effectively never applying any rate limit at all. To fix it, just map from u64 to HumanByte. Signed-off-by: Dominik Csapak --- Alternatively, we could introduce a new string schema to parse into HumanByte, if that's preferred. (Did not do it that way, because this fix was way faster for me and is also OK in my opinion). proxmox-backup-client/src/main.rs | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/proxmox-backup-client/src/main.rs b/proxmox-backup-client/src/main.rs index 5edb2a82..63ad47fc 100644 --- a/proxmox-backup-client/src/main.rs +++ b/proxmox-backup-client/src/main.rs @@ -764,14 +764,8 @@ async fn create_backup( verify_chunk_size(size)?; } - let rate = match param["rate"].as_str() { - Some(s) => Some(s.parse::()?), - None => None, - }; - let burst = match param["burst"].as_str() { - Some(s) => Some(s.parse::()?), - None => None, - }; + let rate = param["rate"].as_u64().map(HumanByte::from); + let burst = param["burst"].as_u64().map(HumanByte::from); let rate_limit = RateLimitConfig::with_same_inout(rate, burst); @@ -1505,14 +1499,8 @@ async fn restore( let archive_name = json::required_string_param(¶m, "archive-name")?; - let rate = match param["rate"].as_str() { - Some(s) => Some(s.parse::()?), - None => None, - }; - let burst = match param["burst"].as_str() { - Some(s) => Some(s.parse::()?), - None => None, - }; + let rate = param["rate"].as_u64().map(HumanByte::from); + let burst = param["burst"].as_u64().map(HumanByte::from); let rate_limit = RateLimitConfig::with_same_inout(rate, burst); -- 2.39.2 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel