From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 774641FF0E0 for ; Thu, 23 Jul 2026 13:52:47 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 2444A214C1; Thu, 23 Jul 2026 13:52:47 +0200 (CEST) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: Re: [PATCH proxmox-backup v3 05/10] datastore: move lock files base path constant to central location From: Robert Obkircher To: Christian Ebner In-Reply-To: <20260721103643.333028-6-c.ebner@proxmox.com> References: <20260721103643.333028-1-c.ebner@proxmox.com> <20260721103643.333028-6-c.ebner@proxmox.com> Date: Thu, 23 Jul 2026 13:52:10 +0200 Message-Id: <178480753020.88450.17857175971964654206.b4-review@b4> X-Mailer: b4 0.16-dev X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1784807503021 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.185 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_LOW -0.7 Sender listed at https://www.dnswl.org/, low trust 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: WQFVTGP5G244AOIU5OHEXXOEURE5H4XZ X-Message-ID-Hash: WQFVTGP5G244AOIU5OHEXXOEURE5H4XZ X-MailFrom: r.obkircher@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 CC: pbs-devel@lists.proxmox.com 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: > Moves the implementation to a more central location, as it is not > only used by the datastore contents, but also by the chunk store. > > No functional changes. > > Signed-off-by: Christian Ebner > > diff --git a/pbs-datastore/src/backup_info.rs b/pbs-datastore/src/backup_info.rs > index fbef8e85a..e01ae8ab2 100644 > --- a/pbs-datastore/src/backup_info.rs > +++ b/pbs-datastore/src/backup_info.rs > @@ -1,5 +1,5 @@ > use std::fmt; > -use std::os::unix::io::{AsRawFd, RawFd}; > +use std::os::unix::io::RawFd; > use std::os::unix::prelude::OsStrExt; > use std::path::Path; > use std::path::PathBuf; > @@ -24,7 +24,7 @@ use crate::datastore::{GROUP_NOTES_FILE_NAME, GROUP_OWNER_FILE_NAME}; > use crate::manifest::{BackupManifest, MANIFEST_LOCK_NAME}; > use crate::move_journal; > use crate::s3::S3_CONTENT_PREFIX; > -use crate::{DATASTORE_LOCKS_DIR, DataBlob, DataStore, DatastoreBackend}; > +use crate::{DATASTORE_LOCKS_DIR, DataBlob, DataStore, DatastoreBackend, lock_helper}; > > pub const PROTECTED_MARKER_FILENAME: &str = ".protected"; > > @@ -1212,34 +1212,3 @@ fn lock_file_path_helper(ns: &BackupNamespace, path: PathBuf) -> PathBuf { > > to_return.join(format!("{first_eigthy}...{last_eighty}-{hash}")) > } > - > -/// Helps implement the double stat'ing procedure. It avoids certain race conditions upon lock > -/// deletion. > -/// > -/// It also creates the base directory for lock files. > -pub(crate) fn lock_helper( > - store_name: &str, > - path: &std::path::Path, > - lock_fn: F, > -) -> Result > -where > - F: Fn(&std::path::Path) -> Result, > -{ > - let mut lock_dir = Path::new(DATASTORE_LOCKS_DIR).join(store_name); > - > - if let Some(parent) = path.parent() { > - lock_dir = lock_dir.join(parent); > - }; > - > - std::fs::create_dir_all(&lock_dir)?; > - > - let lock = lock_fn(path)?; > - > - let inode = nix::sys::stat::fstat(lock.as_raw_fd())?.st_ino; > - > - if nix::sys::stat::stat(path).map_or(true, |st| inode != st.st_ino) { > - bail!("could not acquire lock, another thread modified the lock file"); > - } > - > - Ok(lock) > -} > diff --git a/pbs-datastore/src/chunk_store.rs b/pbs-datastore/src/chunk_store.rs > index cfd920dea..c06b7f29b 100644 > --- a/pbs-datastore/src/chunk_store.rs > +++ b/pbs-datastore/src/chunk_store.rs > @@ -947,7 +947,7 @@ impl ChunkStore { > timeout: Duration, > ) -> Result { > let lock_path = self.chunk_lock_path(digest); > - let guard = crate::backup_info::lock_helper(self.name(), &lock_path, |path| { > + let guard = crate::lock_helper(self.name(), &lock_path, |path| { > pbs_config::open_backup_lockfile(path, Some(timeout), true) > })?; > Ok(guard) > diff --git a/pbs-datastore/src/lib.rs b/pbs-datastore/src/lib.rs > index 0904d7da2..c17f9591b 100644 > --- a/pbs-datastore/src/lib.rs > +++ b/pbs-datastore/src/lib.rs > @@ -157,6 +157,13 @@ > > #![deny(unsafe_op_in_unsafe_fn)] > > +use std::os::unix::io::AsRawFd; > +use std::path::Path; > + > +use anyhow::{Error, bail}; > + > +use pbs_config::BackupLockGuard; > + > /// Directory path where active operations counters are saved. > pub const ACTIVE_OPERATIONS_DIR: &str = concat!( > pbs_buildcfg::PROXMOX_BACKUP_RUN_DIR_M!(), > @@ -236,3 +243,34 @@ pub use local_chunk_reader::LocalChunkReader; > > mod local_datastore_lru_cache; > pub use local_datastore_lru_cache::LocalDatastoreLruCache; > + > +/// Helps implement the double stat'ing procedure. It avoids certain race conditions upon lock > +/// deletion. > +/// > +/// It also creates the base directory for lock files. > +pub(crate) fn lock_helper( > + store_name: &str, > + path: &Path, > + lock_fn: F, > +) -> Result > +where > + F: Fn(&Path) -> Result, > +{ > + let mut lock_dir = Path::new(DATASTORE_LOCKS_DIR).join(store_name); > + > + if let Some(parent) = path.parent() { > + lock_dir = lock_dir.join(parent); > + }; > + > + std::fs::create_dir_all(&lock_dir)?; > + > + let lock = lock_fn(path)?; > + > + let inode = nix::sys::stat::fstat(lock.as_raw_fd())?.st_ino; > + > + if nix::sys::stat::stat(path).map_or(true, |st| inode != st.st_ino) { Unrelated to the move, but this should technically also compare st_dev because the inode number is not unique. -- Robert Obkircher