all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dietmar Maurer <dietmar@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [RFC proxmox-backup 2/2] use HumanByte for traffic-control config
Date: Wed, 17 Nov 2021 10:20:53 +0100	[thread overview]
Message-ID: <20211117092053.1643823-2-dietmar@proxmox.com> (raw)
In-Reply-To: <20211117092053.1643823-1-dietmar@proxmox.com>

---
 pbs-api-types/src/traffic_control.rs | 18 +++++++++---------
 src/cached_traffic_control.rs        | 18 ++++++++++++------
 2 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/pbs-api-types/src/traffic_control.rs b/pbs-api-types/src/traffic_control.rs
index 0dd7ed58..210f53ac 100644
--- a/pbs-api-types/src/traffic_control.rs
+++ b/pbs-api-types/src/traffic_control.rs
@@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
 use proxmox_schema::{api, Schema, IntegerSchema, StringSchema, Updater};
 
 use crate::{
-    CIDR_SCHEMA, DAILY_DURATION_FORMAT,
+    HumanByte, CIDR_SCHEMA, DAILY_DURATION_FORMAT,
     PROXMOX_SAFE_ID_FORMAT, SINGLE_LINE_COMMENT_SCHEMA,
 };
 
@@ -38,19 +38,19 @@ pub const TRAFFIC_CONTROL_BURST_SCHEMA: Schema = IntegerSchema::new(
             schema: SINGLE_LINE_COMMENT_SCHEMA,
         },
         "rate-in": {
-            schema: TRAFFIC_CONTROL_RATE_SCHEMA,
+            type: HumanByte,
             optional: true,
         },
         "burst-in": {
-            schema: TRAFFIC_CONTROL_BURST_SCHEMA,
+            type: HumanByte,
             optional: true,
         },
         "rate-out": {
-            schema: TRAFFIC_CONTROL_RATE_SCHEMA,
+            type: HumanByte,
             optional: true,
         },
         "burst-out": {
-            schema: TRAFFIC_CONTROL_BURST_SCHEMA,
+            type: HumanByte,
             optional: true,
         },
         network: {
@@ -79,13 +79,13 @@ pub struct TrafficControlRule {
     /// Rule applies to Source IPs within this networks
     pub network: Vec<String>,
     #[serde(skip_serializing_if="Option::is_none")]
-    pub rate_in: Option<u64>,
+    pub rate_in: Option<HumanByte>,
     #[serde(skip_serializing_if="Option::is_none")]
-    pub burst_in: Option<u64>,
+    pub burst_in: Option<HumanByte>,
     #[serde(skip_serializing_if="Option::is_none")]
-    pub rate_out: Option<u64>,
+    pub rate_out: Option<HumanByte>,
     #[serde(skip_serializing_if="Option::is_none")]
-    pub burst_out: Option<u64>,
+    pub burst_out: Option<HumanByte>,
     // fixme: expose this?
     //    /// Bandwidth is shared accross all connections
     //    #[serde(skip_serializing_if="Option::is_none")]
diff --git a/src/cached_traffic_control.rs b/src/cached_traffic_control.rs
index 426ebba7..5c6ce042 100644
--- a/src/cached_traffic_control.rs
+++ b/src/cached_traffic_control.rs
@@ -225,7 +225,10 @@ impl TrafficControlCache {
                 Some(ref read_limiter) => {
                     match rule.rate_in {
                         Some(rate_in) => {
-                            read_limiter.update_rate(rate_in, rule.burst_in.unwrap_or(rate_in));
+                            read_limiter.update_rate(
+                                rate_in.as_u64(),
+                                rule.burst_in.unwrap_or(rate_in).as_u64(),
+                            );
                         }
                         None => entry.0 = None,
                     }
@@ -236,8 +239,8 @@ impl TrafficControlCache {
                         let limiter = create_limiter(
                             self.use_shared_memory,
                             &name,
-                            rate_in,
-                            rule.burst_in.unwrap_or(rate_in),
+                            rate_in.as_u64(),
+                            rule.burst_in.unwrap_or(rate_in).as_u64(),
                         )?;
                         entry.0 = Some(limiter);
                     }
@@ -248,7 +251,10 @@ impl TrafficControlCache {
                 Some(ref write_limiter) => {
                     match rule.rate_out {
                         Some(rate_out) => {
-                            write_limiter.update_rate(rate_out, rule.burst_out.unwrap_or(rate_out));
+                            write_limiter.update_rate(
+                                rate_out.as_u64(),
+                                rule.burst_out.unwrap_or(rate_out).as_u64(),
+                            );
                         }
                         None => entry.1 = None,
                     }
@@ -259,8 +265,8 @@ impl TrafficControlCache {
                         let limiter = create_limiter(
                             self.use_shared_memory,
                             &name,
-                            rate_out,
-                            rule.burst_out.unwrap_or(rate_out),
+                            rate_out.as_u64(),
+                            rule.burst_out.unwrap_or(rate_out).as_u64(),
                         )?;
                         entry.1 = Some(limiter);
                     }
-- 
2.30.2





      reply	other threads:[~2021-11-17  9:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-17  9:20 [pbs-devel] [RFC proxmox-backup 1/2] pbs-api-types: more flexible HumanByte type Dietmar Maurer
2021-11-17  9:20 ` Dietmar Maurer [this message]

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=20211117092053.1643823-2-dietmar@proxmox.com \
    --to=dietmar@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal