From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 3B94F1FF13A for ; Wed, 01 Apr 2026 15:49:04 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 79BAB1D875; Wed, 1 Apr 2026 15:49:13 +0200 (CEST) From: Christian Ebner To: pbs-devel@lists.proxmox.com Subject: [PATCH proxmox v7 06/34] s3-client: sync flush request counters on client instance drop Date: Wed, 1 Apr 2026 15:47:49 +0200 Message-ID: <20260401134817.926499-7-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260401134817.926499-1-c.ebner@proxmox.com> References: <20260401134817.926499-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: 1775051261722 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.065 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: UOADVJ4GFMWP7FI5VFXPO36NYBCTMDH3 X-Message-ID-Hash: UOADVJ4GFMWP7FI5VFXPO36NYBCTMDH3 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 Reviewed-by: Hannes Laimer Tested-by: Hannes Laimer --- 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 e8e46e8c..745154bc 100644 --- a/proxmox-s3-client/src/client.rs +++ b/proxmox-s3-client/src/client.rs @@ -168,6 +168,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 b83b0aa0..58f30a91 100644 --- a/proxmox-s3-client/src/shared_request_counters.rs +++ b/proxmox-s3-client/src/shared_request_counters.rs @@ -269,6 +269,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