public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: Proxmox Backup Server development discussion
	<pbs-devel@lists.proxmox.com>
Subject: Re: [pbs-devel] [PATCH proxmox-backup 2/2] partially fix #2915: 'stat' in case ReadDirEntry does not contain type
Date: Tue, 28 Jun 2022 13:47:30 +0200	[thread overview]
Message-ID: <1656416401.l5bquid3dd.astroid@nora.none> (raw)
In-Reply-To: <20220628111318.2648586-4-d.csapak@proxmox.com>

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
> 
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
>  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,

nit: since we need the stat here anyway, this could just drop the 
entry.file_type() altogether?

> +                } {
> +                    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<bool, Error> {
> +    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;
> +    Ok(is_dir)
> +}

nit: why *is_path*? everything's a path ;) this should probably be called 
`dir_entry_is_dir` or `dir_entry_is_subdir`?

we could also re-use the matching from proxmox_sys -> have a helper that 
takes an entry, returns the file_type if possible, stats otherwise (the 
parent fd and name are in the entry after all), returns the stat result 
transposed to Option<FileType> (or change the call sites to expect 
Result<FileType>), if we want to support this across the board a single 
place for the stat implementation is probably better than multiple 
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) => {
>                      match entry.file_type() {
>                          Some(nix::dir::Type::Directory) => entry, // OK
> +                        None => match dir_entry_is_path(&entry) {
> +                            Ok(true) => entry,
> +                            Ok(false) => continue,
> +                            Err(err) => {
> +                                log::info!(
> +                                    "error listing snapshots for {}: {err}",
> +                                    self.group.group()
> +                                );
> +                                continue;
> +                            }
> +                        },
>                          _ => continue,
>                      }
>                  }
> @@ -93,6 +114,17 @@ impl Iterator for ListGroups {
>                      Ok(ref entry) => {
>                          match entry.file_type() {
>                              Some(nix::dir::Type::Directory) => entry, // OK
> +                            None => match dir_entry_is_path(&entry) {
> +                                Ok(true) => entry,
> +                                Ok(false) => continue,
> +                                Err(err) => {
> +                                    log::info!(
> +                                        "error listing groups for {}: {err}",
> +                                        self.store.name()
> +                                    );
> +                                    continue;
> +                                }
> +                            },
>                              _ => continue,
>                          }
>                      }
> @@ -114,6 +146,17 @@ impl Iterator for ListGroups {
>                      Ok(ref entry) => {
>                          match entry.file_type() {
>                              Some(nix::dir::Type::Directory) => entry, // OK
> +                            None => match dir_entry_is_path(&entry) {
> +                                Ok(true) => entry,
> +                                Ok(false) => continue,
> +                                Err(err) => {
> +                                    log::info!(
> +                                        "error listing groups for {}: {err}",
> +                                        self.store.name()
> +                                    );
> +                                    continue;
> +                                }
> +                            },
>                              _ => continue,
>                          }
>                      }
> @@ -176,6 +219,19 @@ impl Iterator for ListNamespaces {
>                      Ok(ref entry) => {
>                          match entry.file_type() {
>                              Some(nix::dir::Type::Directory) => entry, // OK
> +                            None => match dir_entry_is_path(&entry) {
> +                                Ok(true) => entry,
> +                                Ok(false) => continue,
> +                                Err(err) => {
> +                                    let mut base_path = 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;
> +                                }
> +                            },
>                              _ => continue,
>                          }
>                      }
> -- 
> 2.30.2
> 
> 
> 
> _______________________________________________
> pbs-devel mailing list
> pbs-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
> 
> 
> 




  reply	other threads:[~2022-06-28 11:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-28 11:13 [pbs-devel] [PATCH proxmox/proxmox-backup] fix #2915: stat when necessary Dominik Csapak
2022-06-28 11:13 ` [pbs-devel] [PATCH proxmox 1/1] partially fix #2915: proxmox-sys: scandir: stat if file_type is unknown Dominik Csapak
2022-06-28 11:45   ` Wolfgang Bumiller
2022-06-28 11:13 ` [pbs-devel] [PATCH proxmox-backup 1/2] adapt to changed callback signature of 'scandir' Dominik Csapak
2022-06-28 11:47   ` Fabian Grünbichler
2022-06-28 11:13 ` [pbs-devel] [PATCH proxmox-backup 2/2] partially fix #2915: 'stat' in case ReadDirEntry does not contain type Dominik Csapak
2022-06-28 11:47   ` Fabian Grünbichler [this message]
2022-06-28 11:49   ` Wolfgang Bumiller
2022-06-28 11:52     ` Wolfgang Bumiller

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=1656416401.l5bquid3dd.astroid@nora.none \
    --to=f.gruenbichler@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal