all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dietmar Maurer <dietmar@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [PATCH proxmox-backup 1/5] client: pxar: handle open errors at the call sites
Date: Tue,  1 Dec 2026 10:11:07 +0100	[thread overview]
Message-ID: <20261201091111.940190-2-dietmar@proxmox.com> (raw)
In-Reply-To: <20261201091111.940190-1-dietmar@proxmox.com>

Opening an entry and opening a directory's .pxarexclude treat the same
errors differently, a missing .pxarexclude is no vanished file for
example, and open_file needed a flag to tell them apart. Handling the
errors where each is opened keeps such differences in place, and lets
a caller react to an error in its own way.

No functional change intended.

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
---
 pbs-client/src/pxar/create.rs | 90 ++++++++++++++---------------------
 1 file changed, 35 insertions(+), 55 deletions(-)

diff --git a/pbs-client/src/pxar/create.rs b/pbs-client/src/pxar/create.rs
index b1266b1fc..1d6e541ae 100644
--- a/pbs-client/src/pxar/create.rs
+++ b/pbs-client/src/pxar/create.rs
@@ -485,57 +485,31 @@ impl Archiver {
         Ok(None)
     }
 
-    /// openat() wrapper which allows but logs `EACCES` and turns `ENOENT` into `None`.
-    ///
-    /// The `existed` flag is set when iterating through a directory to note that we know the file
-    /// is supposed to exist and we should warn if it doesnt'.
-    fn open_file(
-        &mut self,
-        parent: RawFd,
-        file_name: &CStr,
-        oflags: OFlag,
-        existed: bool,
-    ) -> Result<Option<OwnedFd>, Error> {
-        // common flags we always want to use:
+    /// openat() wrapper which adds the common flags, and retries without `O_NOATIME` if that is
+    /// not permitted, for example for files owned by another user.
+    fn open_file(parent: RawFd, file_name: &CStr, oflags: OFlag) -> Result<OwnedFd, Errno> {
         let oflags = oflags | OFlag::O_CLOEXEC | OFlag::O_NOCTTY;
 
-        let mut noatime = OFlag::O_NOATIME;
-        loop {
-            return match proxmox_sys::fd::openat(
-                &parent,
-                file_name,
-                oflags | noatime,
-                Mode::empty(),
-            ) {
-                Ok(fd) => Ok(Some(fd)),
-                Err(Errno::ENOENT) => {
-                    if existed {
-                        self.report_vanished_file();
-                    }
-                    Ok(None)
-                }
-                Err(Errno::EACCES) => {
-                    warn!("failed to open file: {:?}: access denied", file_name);
-                    Ok(None)
-                }
-                Err(Errno::ESTALE) => {
-                    self.report_stale_file_handle(None);
-                    Ok(None)
-                }
-                Err(Errno::EPERM) if !noatime.is_empty() => {
-                    // Retry without O_NOATIME:
-                    noatime = OFlag::empty();
-                    continue;
-                }
-                Err(other) => Err(Error::from(other)),
-            };
+        match proxmox_sys::fd::openat(&parent, file_name, oflags | OFlag::O_NOATIME, Mode::empty())
+        {
+            Err(Errno::EPERM) => proxmox_sys::fd::openat(&parent, file_name, oflags, Mode::empty()),
+            result => result,
         }
     }
 
     fn read_pxar_excludes(&mut self, parent: RawFd) -> Result<(), Error> {
-        let fd = match self.open_file(parent, c".pxarexclude", OFlag::O_RDONLY, false)? {
-            Some(fd) => fd,
-            None => return Ok(()),
+        let fd = match Self::open_file(parent, c".pxarexclude", OFlag::O_RDONLY) {
+            Ok(fd) => fd,
+            Err(Errno::ENOENT) => return Ok(()),
+            Err(Errno::EACCES) => {
+                warn!("failed to open file: \".pxarexclude\": access denied");
+                return Ok(());
+            }
+            Err(Errno::ESTALE) => {
+                self.report_stale_file_handle(None);
+                return Ok(());
+            }
+            Err(err) => return Err(err.into()),
         };
 
         let old_pattern_count = self.patterns.len();
@@ -782,16 +756,22 @@ impl Archiver {
             OFlag::O_PATH
         };
 
-        let fd = self.open_file(
-            parent,
-            c_file_name,
-            open_mode | OFlag::O_RDONLY | OFlag::O_NOFOLLOW,
-            true,
-        )?;
-
-        let fd = match fd {
-            Some(fd) => fd,
-            None => return Ok(()),
+        let oflags = open_mode | OFlag::O_RDONLY | OFlag::O_NOFOLLOW;
+        let fd = match Self::open_file(parent, c_file_name, oflags) {
+            Ok(fd) => fd,
+            Err(Errno::ENOENT) => {
+                self.report_vanished_file();
+                return Ok(());
+            }
+            Err(Errno::EACCES) => {
+                warn!("failed to open file: {c_file_name:?}: access denied");
+                return Ok(());
+            }
+            Err(Errno::ESTALE) => {
+                self.report_stale_file_handle(None);
+                return Ok(());
+            }
+            Err(err) => return Err(err.into()),
         };
 
         let metadata = match get_metadata(
-- 
2.47.3




  reply	other threads:[~2026-12-01  9:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  9:11 [PATCH proxmox-backup 0/5] client: report or fail on files left out for lack of permission Dietmar Maurer
2026-12-01  9:11 ` Dietmar Maurer [this message]
2026-12-01  9:11 ` [PATCH proxmox-backup 2/5] client: pxar: name the directory of an unreadable .pxarexclude Dietmar Maurer
2026-12-01  9:11 ` [PATCH proxmox-backup 3/5] client: pxar: let callers see entries left out for lack of permission Dietmar Maurer
2026-12-01  9:11 ` [PATCH proxmox-backup 4/5] client: pxar: optionally fail on " Dietmar Maurer
2026-12-01  9:11 ` [PATCH proxmox-backup 5/5] client: backup: add option to fail on files that cannot be read Dietmar Maurer

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=20261201091111.940190-2-dietmar@proxmox.com \
    --to=dietmar@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal