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 13C5F786CE for ; Tue, 28 Jun 2022 13:48:09 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0467FAA5E for ; Tue, 28 Jun 2022 13:47:39 +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 E7C82AA55 for ; Tue, 28 Jun 2022 13:47:37 +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 BBEC342AE4 for ; Tue, 28 Jun 2022 13:47:37 +0200 (CEST) Date: Tue, 28 Jun 2022 13:47:30 +0200 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox Backup Server development discussion References: <20220628111318.2648586-1-d.csapak@proxmox.com> <20220628111318.2648586-4-d.csapak@proxmox.com> In-Reply-To: <20220628111318.2648586-4-d.csapak@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.15.0 (https://github.com/astroidmail/astroid) Message-Id: <1656416401.l5bquid3dd.astroid@nora.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.020 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. [hierarchy.rs, self.name, proxmox.com] 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:48:09 -0000 On June 28, 2022 1:13 pm, 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 >=20 > 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(-) >=20 > diff --git a/pbs-datastore/src/chunk_store.rs b/pbs-datastore/src/chunk_s= tore.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 { > ), > }; > =20 > - let file_type =3D match entry.file_type() { > - Some(file_type) =3D> file_type, > - None =3D> bail!( > - "unsupported file system type on chunk store '{}'", > - self.name > - ), > - }; > - if file_type !=3D nix::dir::Type::File { > - continue; > - } > - > - chunk_count +=3D 1; > - > let filename =3D entry.file_name(); > =20 > let lock =3D self.mutex.lock(); > =20 > if let Ok(stat) =3D fstatat(dirfd, filename, nix::fcntl::AtF= lags::AT_SYMLINK_NOFOLLOW) { > + if match entry.file_type() { > + Some(file_type) =3D> file_type !=3D nix::dir::Type::= File, > + None =3D> stat.st_mode & libc::S_IFREG =3D=3D 0, nit: since we need the stat here anyway, this could just drop the=20 entry.file_type() altogether? > + } { > + drop(lock); > + continue; > + } > + > + chunk_count +=3D 1; > + > if stat.st_atime < min_atime { > //let age =3D now - stat.st_atime; > //println!("UNLINK {} {:?}", age/(3600*24), filenam= e); > 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; > =20 > +fn dir_entry_is_path(entry: &proxmox_sys::fs::ReadDirEntry) -> Result { > + let stat =3D nix::sys::stat::fstatat( > + entry.parent_fd(), > + entry.file_name(), > + nix::fcntl::AtFlags::AT_SYMLINK_NOFOLLOW, > + )?; > + let is_dir =3D stat.st_mode & libc::S_IFDIR > 0; > + Ok(is_dir) > +} nit: why *is_path*? everything's a path ;) this should probably be called=20 `dir_entry_is_dir` or `dir_entry_is_subdir`? we could also re-use the matching from proxmox_sys -> have a helper that=20 takes an entry, returns the file_type if possible, stats otherwise (the=20 parent fd and name are in the entry after all), returns the stat result=20 transposed to Option (or change the call sites to expect=20 Result), if we want to support this across the board a single=20 place for the stat implementation is probably better than multiple=20 ones.. > + > /// A iterator for all BackupDir's (Snapshots) in a BackupGroup > pub struct ListSnapshots { > group: BackupGroup, > @@ -36,6 +46,17 @@ impl Iterator for ListSnapshots { > Ok(ref entry) =3D> { > match entry.file_type() { > Some(nix::dir::Type::Directory) =3D> entry, // O= K > + None =3D> match dir_entry_is_path(&entry) { > + Ok(true) =3D> entry, > + Ok(false) =3D> continue, > + Err(err) =3D> { > + log::info!( > + "error listing snapshots for {}: {er= r}", > + self.group.group() > + ); > + continue; > + } > + }, > _ =3D> continue, > } > } > @@ -93,6 +114,17 @@ impl Iterator for ListGroups { > Ok(ref entry) =3D> { > match entry.file_type() { > Some(nix::dir::Type::Directory) =3D> entry, = // OK > + None =3D> match dir_entry_is_path(&entry) { > + Ok(true) =3D> entry, > + Ok(false) =3D> continue, > + Err(err) =3D> { > + log::info!( > + "error listing groups for {}: {e= rr}", > + self.store.name() > + ); > + continue; > + } > + }, > _ =3D> continue, > } > } > @@ -114,6 +146,17 @@ impl Iterator for ListGroups { > Ok(ref entry) =3D> { > match entry.file_type() { > Some(nix::dir::Type::Directory) =3D> entry, = // OK > + None =3D> match dir_entry_is_path(&entry) { > + Ok(true) =3D> entry, > + Ok(false) =3D> continue, > + Err(err) =3D> { > + log::info!( > + "error listing groups for {}: {e= rr}", > + self.store.name() > + ); > + continue; > + } > + }, > _ =3D> continue, > } > } > @@ -176,6 +219,19 @@ impl Iterator for ListNamespaces { > Ok(ref entry) =3D> { > match entry.file_type() { > Some(nix::dir::Type::Directory) =3D> entry, = // OK > + None =3D> match dir_entry_is_path(&entry) { > + Ok(true) =3D> entry, > + Ok(false) =3D> continue, > + Err(err) =3D> { > + let mut base_path =3D self.base_path= .to_owned(); > + if !self.ns.is_root() { > + base_path.push(self.ns.path()); > + } > + base_path.push("ns"); > + log::info!("error listing dirs in {:= ?}: {err}", base_path); > + continue; > + } > + }, > _ =3D> continue, > } > } > --=20 > 2.30.2 >=20 >=20 >=20 > _______________________________________________ > pbs-devel mailing list > pbs-devel@lists.proxmox.com > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel >=20 >=20 >=20