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 0D36E1FF139 for ; Tue, 24 Feb 2026 10:13:38 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 121921F52F; Tue, 24 Feb 2026 10:14:30 +0100 (CET) From: Christian Ebner To: pbs-devel@lists.proxmox.com Subject: [PATCH proxmox v3 09/10] s3-client: sync flush request counters on client instance drop Date: Tue, 24 Feb 2026 10:13:53 +0100 Message-ID: <20260224091406.169080-10-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260224091406.169080-1-c.ebner@proxmox.com> References: <20260224091406.169080-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: 1771924448521 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.050 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: IXHPWLVPFWG4ODT2DSRTSORLXXPQWL4T X-Message-ID-Hash: IXHPWLVPFWG4ODT2DSRTSORLXXPQWL4T 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: Persist the counter state to the shared memory backing file on s3 client destruction via a blocking msync call. This assures that any counter updates not yet persisted since the last asynchronous msync call are written back to the file. Signed-off-by: Christian Ebner --- proxmox-s3-client/src/client.rs | 15 +++++++++++++++ proxmox-s3-client/src/shared_request_counters.rs | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/proxmox-s3-client/src/client.rs b/proxmox-s3-client/src/client.rs index 29ddc1de..a0e9d9c4 100644 --- a/proxmox-s3-client/src/client.rs +++ b/proxmox-s3-client/src/client.rs @@ -170,6 +170,21 @@ pub struct S3Client { request_counters: Option>, } +impl Drop for S3Client { + fn drop(&mut self) { + if let Some(counters) = &self.request_counters { + SHARED_COUNTER_FLUSHER + .write() + .unwrap() + .remove_counter(&counters.path_buf()); + + if let Err(err) = counters.flush() { + tracing::error!("flushing s3 request counters failed: {err:?}"); + } + } + } +} + impl S3Client { /// Creates a new S3 client instance, connecting to the provided endpoint using https given the /// provided options. diff --git a/proxmox-s3-client/src/shared_request_counters.rs b/proxmox-s3-client/src/shared_request_counters.rs index d3f53c8e..0c668183 100644 --- a/proxmox-s3-client/src/shared_request_counters.rs +++ b/proxmox-s3-client/src/shared_request_counters.rs @@ -261,6 +261,11 @@ impl SharedRequestCounters { self.shared_memory.msync(MsFlags::MS_ASYNC) } + /// Persist in-memory contents to backing file, blocking until synced + pub fn flush(&self) -> Result<(), Error> { + self.shared_memory.msync(MsFlags::MS_SYNC) + } + /// Path of shared memory backing file pub fn path_buf(&self) -> PathBuf { self.path.clone() -- 2.47.3