From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 344857D50C for ; Tue, 9 Nov 2021 07:53:10 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 97E7A2E157 for ; Tue, 9 Nov 2021 07:53:08 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id A8DDA2DF70 for ; Tue, 9 Nov 2021 07:53:01 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 1CB7742326; Tue, 9 Nov 2021 07:52:57 +0100 (CET) From: Dietmar Maurer To: pbs-devel@lists.proxmox.com Date: Tue, 9 Nov 2021 07:52:51 +0100 Message-Id: <20211109065253.980304-15-dietmar@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211109065253.980304-1-dietmar@proxmox.com> References: <20211109065253.980304-1-dietmar@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.508 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [lib.rs, memcom.rs] Subject: [pbs-devel] [PATCH proxmox-backup 7/9] traffic_control: use Memcom to track. config versions X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Nov 2021 06:53:10 -0000 Signed-off-by: Dietmar Maurer --- 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> = 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