[pbs-devel] [PATCH proxmox-backup v6 10/21] store: split insert_chunk into wrapper + unsafe locked implementation

Christian Ebner c.ebner at proxmox.com
Fri Nov 14 14:18:50 CET 2025


From: Fabian Grünbichler <f.gruenbichler at proxmox.com>

to allow calling it with the chunk store Mutex already held, to synchronize the
LRU cache and the chunk store inserts.

Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
 pbs-datastore/src/chunk_store.rs | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/pbs-datastore/src/chunk_store.rs b/pbs-datastore/src/chunk_store.rs
index a7ae4fca5..085816f42 100644
--- a/pbs-datastore/src/chunk_store.rs
+++ b/pbs-datastore/src/chunk_store.rs
@@ -587,9 +587,22 @@ impl ChunkStore {
 
         //println!("DIGEST {}", hex::encode(digest));
 
-        let (chunk_path, digest_str) = self.chunk_path(digest);
+        let _lock = self.mutex.lock();
 
-        let lock = self.mutex.lock();
+        // Safety: lock acquired above
+        unsafe { self.insert_chunk_nolock(chunk, digest) }
+    }
+
+    /// Safety: requires holding the chunk store mutex!
+    pub(crate) unsafe fn insert_chunk_nolock(
+        &self,
+        chunk: &DataBlob,
+        digest: &[u8; 32],
+    ) -> Result<(bool, u64), Error> {
+        // unwrap: only `None` in unit tests
+        assert!(self.locker.is_some());
+
+        let (chunk_path, digest_str) = self.chunk_path(digest);
 
         let raw_data = chunk.raw_data();
         let encoded_size = raw_data.len() as u64;
@@ -665,8 +678,6 @@ impl ChunkStore {
                 .map_err(|err| format_err!("fsync failed: {err}"))?;
         }
 
-        drop(lock);
-
         Ok((false, encoded_size))
     }
 
-- 
2.47.3





More information about the pbs-devel mailing list