public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH proxmox-backup] fix #5622: backup client: properly handle rate/burst parameters
@ 2024-07-23 10:04 Dominik Csapak
  2024-07-23 12:48 ` Christian Ebner
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Dominik Csapak @ 2024-07-23 10:04 UTC (permalink / raw)
  To: 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 <d.csapak@proxmox.com>
---

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::<HumanByte>()?),
-        None => None,
-    };
-    let burst = match param["burst"].as_str() {
-        Some(s) => Some(s.parse::<HumanByte>()?),
-        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(&param, "archive-name")?;
 
-    let rate = match param["rate"].as_str() {
-        Some(s) => Some(s.parse::<HumanByte>()?),
-        None => None,
-    };
-    let burst = match param["burst"].as_str() {
-        Some(s) => Some(s.parse::<HumanByte>()?),
-        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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-08-09  8:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-23 10:04 [pbs-devel] [PATCH proxmox-backup] fix #5622: backup client: properly handle rate/burst parameters Dominik Csapak
2024-07-23 12:48 ` Christian Ebner
2024-07-23 12:51   ` Christian Ebner
2024-08-01 12:44 ` Christian Ebner
2024-08-01 13:14   ` Christian Ebner
2024-08-07 19:20 ` Thomas Lamprecht
2024-08-08  6:51   ` Dominik Csapak
2024-08-09  8:22 ` Dominik Csapak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal