public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Christian Ebner <c.ebner@proxmox.com>
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	[thread overview]
Message-ID: <20261126164920.539641-4-c.ebner@proxmox.com> (raw)
In-Reply-To: <20261126164920.539641-1-c.ebner@proxmox.com>

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 <c.ebner@proxmox.com>
---
 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<MatchEntry>,
     #[allow(clippy::type_complexity)]
     callback: Box<dyn FnMut(&Path) -> 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<FsInfo>,
+}
+
+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





      parent reply	other threads:[~2026-11-26 16:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 16:49 [PATCH proxmox-backup 0/3] fix #8373: avoid loosing fs feature flags on mountpoints Christian Ebner
2026-11-26 16:49 ` [PATCH proxmox-backup 1/3] client: pxar: refactor metadata gathering helpers into MetadataAggregator Christian Ebner
2026-11-26 16:49 ` [PATCH proxmox-backup 2/3] client: pxar: encapsulate filesystem info in FsInfo Christian Ebner
2026-11-26 16:49 ` Christian Ebner [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261126164920.539641-4-c.ebner@proxmox.com \
    --to=c.ebner@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal