use HumanByte for traffic-control config

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Dietmar Maurer 2021-11-18 08:29:22 +01:00 committed by Thomas Lamprecht
parent 42ba4cd399
commit 118515dbd0
2 changed files with 21 additions and 15 deletions

View File

@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
use proxmox_schema::{api, Schema, IntegerSchema, StringSchema, Updater}; use proxmox_schema::{api, Schema, IntegerSchema, StringSchema, Updater};
use crate::{ use crate::{
CIDR_SCHEMA, DAILY_DURATION_FORMAT, HumanByte, CIDR_SCHEMA, DAILY_DURATION_FORMAT,
PROXMOX_SAFE_ID_FORMAT, SINGLE_LINE_COMMENT_SCHEMA, 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, schema: SINGLE_LINE_COMMENT_SCHEMA,
}, },
"rate-in": { "rate-in": {
schema: TRAFFIC_CONTROL_RATE_SCHEMA, type: HumanByte,
optional: true, optional: true,
}, },
"burst-in": { "burst-in": {
schema: TRAFFIC_CONTROL_BURST_SCHEMA, type: HumanByte,
optional: true, optional: true,
}, },
"rate-out": { "rate-out": {
schema: TRAFFIC_CONTROL_RATE_SCHEMA, type: HumanByte,
optional: true, optional: true,
}, },
"burst-out": { "burst-out": {
schema: TRAFFIC_CONTROL_BURST_SCHEMA, type: HumanByte,
optional: true, optional: true,
}, },
network: { network: {
@ -79,13 +79,13 @@ pub struct TrafficControlRule {
/// Rule applies to Source IPs within this networks /// Rule applies to Source IPs within this networks
pub network: Vec<String>, pub network: Vec<String>,
#[serde(skip_serializing_if="Option::is_none")] #[serde(skip_serializing_if="Option::is_none")]
pub rate_in: Option<u64>, pub rate_in: Option<HumanByte>,
#[serde(skip_serializing_if="Option::is_none")] #[serde(skip_serializing_if="Option::is_none")]
pub burst_in: Option<u64>, pub burst_in: Option<HumanByte>,
#[serde(skip_serializing_if="Option::is_none")] #[serde(skip_serializing_if="Option::is_none")]
pub rate_out: Option<u64>, pub rate_out: Option<HumanByte>,
#[serde(skip_serializing_if="Option::is_none")] #[serde(skip_serializing_if="Option::is_none")]
pub burst_out: Option<u64>, pub burst_out: Option<HumanByte>,
// fixme: expose this? // fixme: expose this?
// /// Bandwidth is shared accross all connections // /// Bandwidth is shared accross all connections
// #[serde(skip_serializing_if="Option::is_none")] // #[serde(skip_serializing_if="Option::is_none")]

View File

@ -224,7 +224,10 @@ impl TrafficControlCache {
Some(ref read_limiter) => { Some(ref read_limiter) => {
match rule.rate_in { match rule.rate_in {
Some(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, None => entry.0 = None,
} }
@ -235,8 +238,8 @@ impl TrafficControlCache {
let limiter = create_limiter( let limiter = create_limiter(
self.use_shared_memory, self.use_shared_memory,
&name, &name,
rate_in, rate_in.as_u64(),
rule.burst_in.unwrap_or(rate_in), rule.burst_in.unwrap_or(rate_in).as_u64(),
)?; )?;
entry.0 = Some(limiter); entry.0 = Some(limiter);
} }
@ -247,7 +250,10 @@ impl TrafficControlCache {
Some(ref write_limiter) => { Some(ref write_limiter) => {
match rule.rate_out { match rule.rate_out {
Some(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, None => entry.1 = None,
} }
@ -258,8 +264,8 @@ impl TrafficControlCache {
let limiter = create_limiter( let limiter = create_limiter(
self.use_shared_memory, self.use_shared_memory,
&name, &name,
rate_out, rate_out.as_u64(),
rule.burst_out.unwrap_or(rate_out), rule.burst_out.unwrap_or(rate_out).as_u64(),
)?; )?;
entry.1 = Some(limiter); entry.1 = Some(limiter);
} }