From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 9E8031FF0B3 for ; Thu, 26 Nov 2026 17:49:41 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 6C78F21711; Thu, 26 Nov 2026 17:49:41 +0100 (CET) From: Christian Ebner To: pbs-devel@lists.proxmox.com Subject: [PATCH proxmox-backup 3/3] fix #8373: client: pxar: avoid losing fs feature flags on mountpoints Date: Thu, 26 Nov 2026 17:49:20 +0100 Message-ID: <20261126164920.539641-4-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261126164920.539641-1-c.ebner@proxmox.com> References: <20261126164920.539641-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: 1795711777119 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.347 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_MED -2.3 Sender listed at https://www.dnswl.org/, medium 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: ISNCYAKXPBBRE7IZWW3FEONXRJ35OGVP X-Message-ID-Hash: ISNCYAKXPBBRE7IZWW3FEONXRJ35OGVP 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: Since commit 5667b763 ("fix #3393 (again): pxar/create: try to read xattrs/fcaps/acls by default") feature flags for filesystems the client does not have a matching magic number and therefore known set of fs feature flags, are all set as try all approach. They are then subsequently cleared on first encounter of an EOPNOTSUPP error while trying to read them for an entry. Since the same state variable in the archiver is used for this, clearing the flag on any entry on a filesystem not supporting it clears it from the global state and does not reset the flag at any point again. This also completely bypassing the fs info state updates present in add_directory(), as that already contains the state with cleared flags. In consequence, this will lead to incorrectly skipping reading the attributes gated by these flags for any subsequent entries, regardless if supported by the filesystem they are located on. To fix this and facilitate keeping track of the filesystems and their supported metadata capabilities, introduce a cache for FsInfo storing these properties using the device id as key for easy lookup and deduplication. A plain vector was chosen over a more complex type such as a HashMap in order to store them compactly while keeping an acceptable lookup time, only a small number of different filesystems is expected to be encountered for any single backup run. Each entry only needs to get the FsInfo for its device id from the cache, which is populated on demand. This has the advantage that: - Unsupported feature flags discovered on a mountpoint or bind-mounted entry never leak onto the parent filesystem. - Unsupported feature flags discovered on any entry persist for all subsequent entries on the same device. - Mountpoint skipping in add_directory() directly can use the cached FsInfo without needing to track the fs feature flags separately. Link: https://bugzilla.proxmox.com/show_bug.cgi?id=8373 Fixes: 5667b763 ("fix #3393 (again): pxar/create: try to read xattrs/fcaps/acls by default") Signed-off-by: Christian Ebner --- pbs-client/src/pxar/create.rs | 64 +++++++++++++++++------------ pbs-client/src/pxar/metadata.rs | 73 ++++++++++++++++++++++++++++++++- 2 files changed, 109 insertions(+), 28 deletions(-) diff --git a/pbs-client/src/pxar/create.rs b/pbs-client/src/pxar/create.rs index 8e49416c6..309567a63 100644 --- a/pbs-client/src/pxar/create.rs +++ b/pbs-client/src/pxar/create.rs @@ -36,7 +36,7 @@ use pbs_datastore::index::IndexFile; use crate::inject_reused_chunks::InjectChunks; use crate::pxar::Flags; use crate::pxar::look_ahead_cache::{CacheEntry, CacheEntryData, PxarLookaheadCache}; -use crate::pxar::metadata::{FsInfo, MetadataAggregator}; +use crate::pxar::metadata::{FsInfoCache, MetadataAggregator}; use crate::pxar::tools::assert_single_path_component; const CHUNK_PADDING_THRESHOLD: f64 = 0.1; @@ -136,7 +136,7 @@ pub(crate) struct PbsClientPrelude { struct Archiver { feature_flags: Flags, - fs_info: FsInfo, + fs_info_cache: FsInfoCache, patterns: Vec, #[allow(clippy::type_complexity)] callback: Box Result<(), Error> + Send>, @@ -191,7 +191,8 @@ where F: FnMut(&Path) -> Result<(), Error> + Send + 'static, { let stat = nix::sys::stat::fstat(source_dir.as_raw_fd())?; - let mut fs_info = FsInfo::from_raw(source_dir.as_raw_fd(), stat.st_dev)?; + let mut fs_info_cache = FsInfoCache::new(); + let fs_info = fs_info_cache.get_or_insert(source_dir.as_raw_fd(), stat.st_dev)?; if fs_info.is_virtual_filesystem() { bail!("refusing to backup a virtual file system"); } @@ -200,7 +201,7 @@ where source_dir.as_raw_fd(), &stat, feature_flags, - &mut fs_info, + fs_info, options.skip_e2big_xattr, ) .context("failed to get metadata for source directory")?; @@ -247,7 +248,7 @@ where let mut archiver = Archiver { feature_flags, - fs_info, + fs_info_cache, callback: Box::new(callback), patterns, catalog: writers.catalog, @@ -747,11 +748,23 @@ impl Archiver { None => return Ok(()), }; + let fs_info = match self + .fs_info_cache + .get_or_insert(fd.as_raw_fd(), stat.st_dev) + { + Ok(fs_info) => fs_info, + Err(Errno::ESTALE) => { + self.report_stale_file_handle(None); + return Ok(()); + } + Err(err) => return Err(err.into()), + }; + let metadata = match MetadataAggregator::get_metadata( fd.as_raw_fd(), stat, self.feature_flags, - &mut self.fs_info, + fs_info, self.skip_e2big_xattr, ) { Ok(metadata) => metadata, @@ -1205,22 +1218,17 @@ impl Archiver { ) -> Result<(), Error> { let dir_name = OsStr::from_bytes(c_dir_name.to_bytes()); - let old_fs_info = self.fs_info; - - let mut skip_contents = false; - if old_fs_info.st_dev != stat.st_dev { - self.fs_info = match FsInfo::from_raw(dir.as_raw_fd(), stat.st_dev) { - Ok(fs_info) => fs_info, - Err(Errno::ESTALE) => { - self.report_stale_file_handle(None); - return Ok(()); - } - Err(err) => return Err(err.into()), - }; - skip_contents = self - .fs_info - .should_skip_mountpoint(self.device_set.as_ref()); - } + let skip_contents = match self + .fs_info_cache + .get_or_insert(dir.as_raw_fd(), stat.st_dev) + { + Ok(fs_info) => fs_info.should_skip_mountpoint(self.device_set.as_ref()), + Err(Errno::ESTALE) => { + self.report_stale_file_handle(None); + return Ok(()); + } + Err(err) => return Err(err.into()), + }; if !self.cache.caching_enabled() { if let Some(ref catalog) = self.catalog { @@ -1246,8 +1254,6 @@ impl Archiver { .await }; - self.fs_info = old_fs_info; - if !self.cache.caching_enabled() { encoder.finish().await?; if let Some(ref catalog) = self.catalog { @@ -1475,6 +1481,7 @@ mod tests { use crate::pxar::OverwriteFlags; use crate::pxar::extract::Extractor; + use crate::pxar::metadata::FsInfo; use super::*; @@ -1638,14 +1645,17 @@ mod tests { nix::dir::Dir::open(testdir.as_path(), OFlag::O_DIRECTORY, Mode::empty()).unwrap(); let stat = nix::sys::stat::fstat(source_dir.as_raw_fd()).unwrap(); - let mut fs_info = FsInfo::from_raw(source_dir.as_raw_fd(), stat.st_dev).unwrap(); + let mut fs_info_cache = FsInfoCache::new(); + let fs_info = fs_info_cache + .get_or_insert(source_dir.as_raw_fd(), stat.st_dev) + .unwrap(); let feature_flags = fs_info.feature_flags(); let metadata = MetadataAggregator::get_metadata( source_dir.as_raw_fd(), &stat, feature_flags, - &mut fs_info, + fs_info, false, )?; @@ -1661,7 +1671,7 @@ mod tests { let mut archiver = Archiver { feature_flags, - fs_info, + fs_info_cache, callback: Box::new(|_| Ok(())), patterns: Vec::new(), catalog: None, diff --git a/pbs-client/src/pxar/metadata.rs b/pbs-client/src/pxar/metadata.rs index bb6351446..e18795999 100644 --- a/pbs-client/src/pxar/metadata.rs +++ b/pbs-client/src/pxar/metadata.rs @@ -419,7 +419,7 @@ fn apply_flags(flags: Flags, fd: RawFd, entry_flags: u64) -> Result<(), Error> { pub(super) struct FsInfo { magic: i64, feature_flags: Flags, - pub(super) st_dev: libc::dev_t, + st_dev: libc::dev_t, } impl FsInfo { @@ -489,6 +489,43 @@ impl FsInfo { } } +/// Cache of filesystem info per device id +#[derive(Default)] +pub(super) struct FsInfoCache { + entries: Vec, +} + +impl FsInfoCache { + pub(super) fn new() -> Self { + Self { + entries: Vec::new(), + } + } + + /// Return the cached [`FsInfo`] for given `st_dev`, gathers the info via `fd` if not present. + pub(super) fn get_or_insert( + &mut self, + fd: RawFd, + st_dev: libc::dev_t, + ) -> Result<&mut FsInfo, Errno> { + // expect the last item to be pushed to be looked up most frequently afterwards + let pos = match self + .entries + .iter() + .rposition(|fs_info| fs_info.st_dev == st_dev) + { + Some(pos) => pos, + None => { + let len = self.entries.len(); + self.entries.push(FsInfo::from_raw(fd, st_dev)?); + len + } + }; + + Ok(&mut self.entries[pos]) + } +} + pub(super) struct MetadataAggregator<'a> { fd: RawFd, feature_flags: Flags, @@ -818,3 +855,37 @@ impl<'a> MetadataAggregator<'a> { Ok(()) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn fs_info_cache_keeps_feature_flags_per_device() { + let dir = nix::dir::Dir::open(".", OFlag::O_DIRECTORY, Mode::empty()).unwrap(); + let fd = dir.as_raw_fd(); + let initial_flags = FsInfo::from_raw(fd, 0).unwrap().feature_flags; + + let mut cache = FsInfoCache::new(); + for st_dev in [1, 2, 3] { + let fs_info = cache.get_or_insert(fd, st_dev).unwrap(); + assert_eq!(fs_info.st_dev, st_dev); + fs_info.feature_flags = Flags::empty(); + } + cache.get_or_insert(fd, 4).unwrap(); + + // Flags cleared for one device must persist for that device only, regardless of the + // order the devices are looked up in. + for st_dev in [1, 4, 2, 4, 3, 1] { + let fs_info = cache.get_or_insert(fd, st_dev).unwrap(); + assert_eq!(fs_info.st_dev, st_dev); + let expected = if st_dev == 4 { + initial_flags + } else { + Flags::empty() + }; + assert_eq!(fs_info.feature_flags, expected); + } + assert_eq!(cache.entries.len(), 4); + } +} -- 2.47.3