[pbs-devel] [PATCH proxmox-backup 7/9] traffic_control: use Memcom to track. config versions

Dietmar Maurer dietmar at proxmox.com
Tue Nov 9 07:52:51 CET 2021


Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 pbs-config/src/lib.rs             |  2 +-
 pbs-config/src/memcom.rs          | 14 ++++++++++++++
 pbs-config/src/traffic_control.rs | 11 +++++++++--
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/pbs-config/src/lib.rs b/pbs-config/src/lib.rs
index 930b5f7b..bc3b19f0 100644
--- a/pbs-config/src/lib.rs
+++ b/pbs-config/src/lib.rs
@@ -16,7 +16,7 @@ pub mod traffic_control;
 pub mod user;
 pub mod verify;
 
-pub(crate) mod memcom;
+pub mod memcom;
 
 use anyhow::{format_err, Error};
 
diff --git a/pbs-config/src/memcom.rs b/pbs-config/src/memcom.rs
index 4ab07ec9..7b82798b 100644
--- a/pbs-config/src/memcom.rs
+++ b/pbs-config/src/memcom.rs
@@ -23,6 +23,8 @@ pub struct Memcom {
 struct Head {
     // User (user.cfg) cache generation/version.
     user_cache_generation: AtomicUsize,
+    // Traffic control (traffic-control.cfg) generation/version.
+    traffic_control_generation: AtomicUsize,
 }
 
 static INSTANCE: OnceCell<Arc<Memcom>> = OnceCell::new();
@@ -81,4 +83,16 @@ impl Memcom {
             .user_cache_generation
             .fetch_add(1, Ordering::AcqRel);
     }
+
+    /// Returns the traffic control generation number.
+    pub fn traffic_control_generation(&self) -> usize {
+        self.head().traffic_control_generation.load(Ordering::Acquire)
+    }
+
+    /// Increase the traffic control generation number.
+    pub fn increase_traffic_control_generation(&self) {
+        self.head()
+            .traffic_control_generation
+            .fetch_add(1, Ordering::AcqRel);
+    }
 }
diff --git a/pbs-config/src/traffic_control.rs b/pbs-config/src/traffic_control.rs
index 1c04f589..816bc7a2 100644
--- a/pbs-config/src/traffic_control.rs
+++ b/pbs-config/src/traffic_control.rs
@@ -10,9 +10,9 @@ use pbs_api_types::{TrafficControlRule, TRAFFIC_CONTROL_ID_SCHEMA};
 
 use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin};
 
+use crate::memcom::Memcom;
 use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard};
 
-
 lazy_static! {
     /// Static [`SectionConfig`] to access parser/writer functions.
     pub static ref CONFIG: SectionConfig = init();
@@ -55,7 +55,14 @@ pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
 /// Save the configuration file
 pub fn save_config(config: &SectionConfigData) -> Result<(), Error> {
     let raw = CONFIG.write(TRAFFIC_CONTROL_CFG_FILENAME, &config)?;
-    replace_backup_config(TRAFFIC_CONTROL_CFG_FILENAME, raw.as_bytes())
+    replace_backup_config(TRAFFIC_CONTROL_CFG_FILENAME, raw.as_bytes())?;
+
+    // increase traffic control generation
+    // We use this in TrafficControlCache
+    let memcom = Memcom::new()?;
+    memcom.increase_traffic_control_generation();
+
+    Ok(())
 }
 
 
-- 
2.30.2






More information about the pbs-devel mailing list