[pbs-devel] [PATCH v2 proxmox-backup 2/2] datastore: store datastore lock on tmpfs

Gabriel Goller g.goller at proxmox.com
Wed Dec 6 14:28:34 CET 2023


Store the lockfiles that lock the whole datastore (which get created on
startup) on tmpfs in `/run/proxmox-backup/locks`.
This allows datastores to always be unmounted without having to restart.

Signed-off-by: Gabriel Goller <g.goller at proxmox.com>
---
 pbs-datastore/src/chunk_store.rs | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/pbs-datastore/src/chunk_store.rs b/pbs-datastore/src/chunk_store.rs
index fb282749..41332db3 100644
--- a/pbs-datastore/src/chunk_store.rs
+++ b/pbs-datastore/src/chunk_store.rs
@@ -18,6 +18,8 @@ use crate::file_formats::{
 };
 use crate::DataBlob;
 
+pub const DATASTORE_LOCKS_DIR: &str = "/run/proxmox-backup/locks";
+
 /// File system based chunk store
 pub struct ChunkStore {
     name: String, // used for error reporting
@@ -124,7 +126,7 @@ impl ChunkStore {
         }
 
         // create lock file with correct owner/group
-        let lockfile_path = Self::lockfile_path(&base);
+        let lockfile_path = Self::lockfile_path(name);
         proxmox_sys::fs::replace_file(lockfile_path, b"", options.clone(), false)?;
 
         // create 64*1024 subdirs
@@ -153,8 +155,9 @@ impl ChunkStore {
         Self::open(name, base, sync_level)
     }
 
-    fn lockfile_path<P: Into<PathBuf>>(base: P) -> PathBuf {
-        let mut lockfile_path: PathBuf = base.into();
+    fn lockfile_path(base: &str) -> PathBuf {
+        let mut lockfile_path: PathBuf = DATASTORE_LOCKS_DIR.into();
+        lockfile_path.push(base);
         lockfile_path.push(".lock");
         lockfile_path
     }
@@ -181,7 +184,7 @@ impl ChunkStore {
             bail!("unable to open chunk store '{name}' at {chunk_dir:?} - {err}");
         }
 
-        let lockfile_path = Self::lockfile_path(&base);
+        let lockfile_path = Self::lockfile_path(name);
 
         let locker = ProcessLocker::new(lockfile_path)?;
 
-- 
2.39.2





More information about the pbs-devel mailing list