[pbs-devel] [PATCH proxmox-backup] datastore: pass relative path to group type iterator

Christian Ebner c.ebner at proxmox.com
Thu May 22 14:51:28 CEST 2025


`ListGroupsType::new_at` creates a new iterator over all groups of
give backup type with provided parent file descriptor.

The parent directory file descriptor is passed to the `read_subdir`
call, which itself uses it to open the type directory via `openat`.
This call does however ignore the passed file handle if the given
path is absolute [0], which is always the case for the type path
generated via `DataStore::type_path`.

Fix this by passing only the type name as relative path to the
`read_subdir` call, use the absolute path only for
`ListGroupType::new`.

This helps avoiding re-traversing the absolute path in the
`ListGroups` iterator, and since it is then the only callside for
`ListGroupsType::new_at`, inline the instantiation.

[0] https://linux.die.net/man/2/openat

Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---

Similar to [1], this was encountered while inspecting strace outputs
in order to investigate the garbage collection performance issues as
reported in the community forum [2].

[1] https://lore.proxmox.com/pbs-devel/20250522062140.51956-1-c.ebner@proxmox.com/T/
[2] https://forum.proxmox.com/threads/166214/

 pbs-datastore/src/hierarchy.rs | 31 +++++++++++--------------------
 1 file changed, 11 insertions(+), 20 deletions(-)

diff --git a/pbs-datastore/src/hierarchy.rs b/pbs-datastore/src/hierarchy.rs
index e0bf84419..6c1287c3e 100644
--- a/pbs-datastore/src/hierarchy.rs
+++ b/pbs-datastore/src/hierarchy.rs
@@ -1,4 +1,3 @@
-use std::os::unix::io::RawFd;
 use std::path::PathBuf;
 use std::str::FromStr;
 use std::sync::Arc;
@@ -73,17 +72,8 @@ pub struct ListGroupsType {
 
 impl ListGroupsType {
     pub fn new(store: Arc<DataStore>, ns: BackupNamespace, ty: BackupType) -> Result<Self, Error> {
-        Self::new_at(libc::AT_FDCWD, store, ns, ty)
-    }
-
-    fn new_at(
-        fd: RawFd,
-        store: Arc<DataStore>,
-        ns: BackupNamespace,
-        ty: BackupType,
-    ) -> Result<Self, Error> {
         Ok(Self {
-            dir: proxmox_sys::fs::read_subdir(fd, &store.type_path(&ns, ty))?,
+            dir: proxmox_sys::fs::read_subdir(libc::AT_FDCWD, &store.type_path(&ns, ty))?,
             store,
             ns,
             ty,
@@ -197,15 +187,16 @@ impl Iterator for ListGroups {
                     if let Ok(group_type) = BackupType::from_str(name) {
                         // found a backup group type, descend into it to scan all IDs in it
                         // by switching to the id-state branch
-                        match ListGroupsType::new_at(
-                            entry.parent_fd(),
-                            Arc::clone(&self.store),
-                            self.ns.clone(),
-                            group_type,
-                        ) {
-                            Ok(ty) => self.id_state = Some(ty),
-                            Err(err) => return Some(Err(err)),
-                        }
+                        let dir = match proxmox_sys::fs::read_subdir(entry.parent_fd(), name) {
+                            Ok(dir) => dir,
+                            Err(err) => return Some(Err(err.into())),
+                        };
+                        self.id_state = Some(ListGroupsType {
+                            dir,
+                            store: Arc::clone(&self.store),
+                            ns: self.ns.clone(),
+                            ty: group_type,
+                        });
                     }
                 }
             }
-- 
2.39.5





More information about the pbs-devel mailing list