public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup] fix #5622: backup client: properly handle rate/burst parameters
Date: Tue, 23 Jul 2024 12:04:48 +0200	[thread overview]
Message-ID: <20240723100448.1571064-1-d.csapak@proxmox.com> (raw)

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


             reply	other threads:[~2024-07-23 10:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-23 10:04 Dominik Csapak [this message]
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

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=20240723100448.1571064-1-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pbs-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 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