[pbs-devel] [PATCH proxmox-backup] fix #5622: backup client: properly handle rate/burst parameters

Dominik Csapak d.csapak at proxmox.com
Tue Jul 23 12:04:48 CEST 2024


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 at 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





More information about the pbs-devel mailing list