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 CC5021FF09F for ; Tue, 01 Dec 2026 10:11:18 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id E3D9B21435; Tue, 01 Dec 2026 10:11:17 +0100 (CET) From: Dietmar Maurer 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 Message-ID: <20261201091111.940190-2-dietmar@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261201091111.940190-1-dietmar@proxmox.com> References: <20261201091111.940190-1-dietmar@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 1 AWL -0.467 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) KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods RDNS_NONE 1.274 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record Message-ID-Hash: X2GUY563ZIUUDNCXB57RAUV7UESVPHGL X-Message-ID-Hash: X2GUY563ZIUUDNCXB57RAUV7UESVPHGL X-MailFrom: dietmar@zilli.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: 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 --- 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, 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 { 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