From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 26BE978711 for ; Tue, 28 Jun 2022 13:49:56 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1D273AAED for ; Tue, 28 Jun 2022 13:49:26 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 504FBAAE4 for ; Tue, 28 Jun 2022 13:49:24 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 27BC742AE4 for ; Tue, 28 Jun 2022 13:49:24 +0200 (CEST) Date: Tue, 28 Jun 2022 13:49:23 +0200 From: Wolfgang Bumiller To: Dominik Csapak Cc: pbs-devel@lists.proxmox.com Message-ID: <20220628114923.lrhsdhmq2mckm22r@casey.proxmox.com> References: <20220628111318.2648586-1-d.csapak@proxmox.com> <20220628111318.2648586-4-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220628111318.2648586-4-d.csapak@proxmox.com> X-SPAM-LEVEL: Spam detection results: 0 AWL 0.153 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment POISEN_SPAM_PILL 0.1 Meta: its spam POISEN_SPAM_PILL_2 0.1 random spam to be learned in bayes POISEN_SPAM_PILL_4 0.1 random spam to be learned in bayes SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [self.name, hierarchy.rs] Subject: Re: [pbs-devel] [PATCH proxmox-backup 2/2] partially fix #2915: 'stat' in case ReadDirEntry does not contain type X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Jun 2022 11:49:56 -0000 On Tue, Jun 28, 2022 at 01:13:18PM +0200, Dominik Csapak wrote: > readdir/getdents may return 'DT_UNKNOWN' for the file type > (which corresponds to 'None' in nix::dir::Entry), so stat the file and > check the type > > Signed-off-by: Dominik Csapak > --- > pbs-datastore/src/chunk_store.rs | 23 ++++++------- > pbs-datastore/src/hierarchy.rs | 56 ++++++++++++++++++++++++++++++++ > 2 files changed, 66 insertions(+), 13 deletions(-) > > diff --git a/pbs-datastore/src/chunk_store.rs b/pbs-datastore/src/chunk_store.rs > index c9714c1e..2c281b0c 100644 > --- a/pbs-datastore/src/chunk_store.rs > +++ b/pbs-datastore/src/chunk_store.rs > @@ -375,24 +375,21 @@ impl ChunkStore { > ), > }; > > - let file_type = match entry.file_type() { > - Some(file_type) => file_type, > - None => bail!( > - "unsupported file system type on chunk store '{}'", > - self.name > - ), > - }; > - if file_type != nix::dir::Type::File { > - continue; > - } > - > - chunk_count += 1; > - > let filename = entry.file_name(); > > let lock = self.mutex.lock(); > > if let Ok(stat) = fstatat(dirfd, filename, nix::fcntl::AtFlags::AT_SYMLINK_NOFOLLOW) { > + if match entry.file_type() { > + Some(file_type) => file_type != nix::dir::Type::File, > + None => stat.st_mode & libc::S_IFREG == 0, Should be `(stat.st_mode & libc::S_IFMT) != libc::S_IFREG`. > + } { > + drop(lock); > + continue; > + } > + > + chunk_count += 1; > + > if stat.st_atime < min_atime { > //let age = now - stat.st_atime; > //println!("UNLINK {} {:?}", age/(3600*24), filename); > diff --git a/pbs-datastore/src/hierarchy.rs b/pbs-datastore/src/hierarchy.rs > index d5007b07..a97a1d2a 100644 > --- a/pbs-datastore/src/hierarchy.rs > +++ b/pbs-datastore/src/hierarchy.rs > @@ -9,6 +9,16 @@ use pbs_api_types::{BackupNamespace, BackupType, BACKUP_DATE_REGEX, BACKUP_ID_RE > use crate::backup_info::{BackupDir, BackupGroup}; > use crate::DataStore; > > +fn dir_entry_is_path(entry: &proxmox_sys::fs::ReadDirEntry) -> Result { > + let stat = nix::sys::stat::fstatat( > + entry.parent_fd(), > + entry.file_name(), > + nix::fcntl::AtFlags::AT_SYMLINK_NOFOLLOW, > + )?; > + let is_dir = stat.st_mode & libc::S_IFDIR > 0; Should be `(stat.st_mode & libc::S_IFMT) != libc::S_IFDIR`.