From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id DA11C1FF137 for ; Tue, 03 Mar 2026 16:23:42 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 7D30E1B79B; Tue, 3 Mar 2026 16:24:16 +0100 (CET) From: Christian Ebner To: pbs-devel@lists.proxmox.com Subject: [PATCH proxmox-backup v4 15/22] datastore: refactor shared request counter loading into helper Date: Tue, 3 Mar 2026 16:23:10 +0100 Message-ID: <20260303152317.934256-29-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260303152317.934256-1-c.ebner@proxmox.com> References: <20260303152317.934256-1-c.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1772551387465 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.051 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy 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 Message-ID-Hash: 5VOEIODEEC7NCTA4I5WX33K5643QLM4V X-Message-ID-Hash: 5VOEIODEEC7NCTA4I5WX33K5643QLM4V X-MailFrom: c.ebner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Backup Server development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: In preparation for also setting/updating the threshold values and notification callback. Signed-off-by: Christian Ebner --- pbs-datastore/src/datastore.rs | 84 +++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 38 deletions(-) diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs index 0ae2f7b59..dac92ce3d 100644 --- a/pbs-datastore/src/datastore.rs +++ b/pbs-datastore/src/datastore.rs @@ -684,49 +684,34 @@ impl DataStore { .parse_property_string(config.backend.as_deref().unwrap_or(""))?, )?; - let (lru_store_caching, request_counters) = if DatastoreBackendType::S3 - == backend_config.ty.unwrap_or_default() - { - let mut cache_capacity = 0; - if let Ok(fs_info) = proxmox_sys::fs::fs_info(&chunk_store.base_path()) { - cache_capacity = fs_info.available / (16 * 1024 * 1024); - } - if let Some(max_cache_size) = backend_config.max_cache_size { + let (lru_store_caching, request_counters) = + if DatastoreBackendType::S3 == backend_config.ty.unwrap_or_default() { + let mut cache_capacity = 0; + if let Ok(fs_info) = proxmox_sys::fs::fs_info(&chunk_store.base_path()) { + cache_capacity = fs_info.available / (16 * 1024 * 1024); + } + if let Some(max_cache_size) = backend_config.max_cache_size { + info!( + "Got requested max cache size {max_cache_size} for store {}", + config.name + ); + let max_cache_capacity = max_cache_size.as_u64() / (16 * 1024 * 1024); + cache_capacity = cache_capacity.min(max_cache_capacity); + } + let cache_capacity = usize::try_from(cache_capacity).unwrap_or_default(); + info!( - "Got requested max cache size {max_cache_size} for store {}", + "Using datastore cache with capacity {cache_capacity} for store {}", config.name ); - let max_cache_capacity = max_cache_size.as_u64() / (16 * 1024 * 1024); - cache_capacity = cache_capacity.min(max_cache_capacity); - } - let cache_capacity = usize::try_from(cache_capacity).unwrap_or_default(); - info!( - "Using datastore cache with capacity {cache_capacity} for store {}", - config.name - ); + let cache = LocalDatastoreLruCache::new(cache_capacity, chunk_store.clone()); + let request_counters = Self::request_counters(&config, &backend_config)?; - let cache = LocalDatastoreLruCache::new(cache_capacity, chunk_store.clone()); - - let path = format!( - "{}/{}-{}-{}.shmem", - S3_CLIENT_REQUEST_COUNTER_BASE_PATH, - backend_config - .client - .as_ref() - .ok_or(format_err!("missing s3 endpoint id"))?, - backend_config - .bucket - .as_ref() - .ok_or(format_err!("missing s3 bucket"))?, - config.name, - ); - let request_counters = - SharedRequestCounters::open_shared_memory_mapped(path, pbs_config::backup_user()?)?; - (Some(cache), Some(Arc::new(request_counters))) - } else { - (None, None) - }; + (Some(cache), Some(Arc::new(request_counters))) + } else { + (None, None) + }; let thread_settings = DatastoreThreadSettings::new( tuning.default_verification_workers, @@ -748,6 +733,29 @@ impl DataStore { }) } + /// Load the shared s3 request counters for given datastore and backend config + pub fn request_counters( + config: &DataStoreConfig, + backend_config: &DatastoreBackendConfig, + ) -> Result { + let path = format!( + "{}/{}-{}-{}.shmem", + S3_CLIENT_REQUEST_COUNTER_BASE_PATH, + backend_config + .client + .as_ref() + .ok_or(format_err!("missing s3 endpoint id"))?, + backend_config + .bucket + .as_ref() + .ok_or(format_err!("missing s3 bucket"))?, + config.name, + ); + let request_counters = + SharedRequestCounters::open_shared_memory_mapped(path, pbs_config::backup_user()?)?; + Ok(request_counters) + } + // Requires obtaining a shared chunk store lock beforehand pub fn create_fixed_writer>( &self, -- 2.47.3