[PATCH proxmox v6 07/12] s3-client: sync flush request counters on client instance drop

Christian Ebner
2026-03-19T09:41:11Z

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 <c.ebner@proxmox.com>
---
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 0ff79a63..fc883186 100644
--- a/proxmox-s3-client/src/client.rs
+++ b/proxmox-s3-client/src/client.rs
@@ -175,6 +175,21 @@ pub struct S3Client {
request_counters: Option<Arc<SharedRequestCounters>>,
}

+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 5c607f7c..2b5a0843 100644
--- a/proxmox-s3-client/src/shared_request_counters.rs
+++ b/proxmox-s3-client/src/shared_request_counters.rs
@@ -263,6 +263,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