[pbs-devel] [PATCH proxmox-backup v2 1/1] partially fix #2915: 'stat' in case ReadDirEntry does not contain type
Dominik Csapak
d.csapak at proxmox.com
Tue Jun 28 15:15:14 CEST 2022
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 at proxmox.com>
---
pbs-datastore/src/chunk_store.rs | 23 ++++++----------
pbs-datastore/src/hierarchy.rs | 47 ++++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+), 14 deletions(-)
diff --git a/pbs-datastore/src/chunk_store.rs b/pbs-datastore/src/chunk_store.rs
index c9714c1e..3bebc645 100644
--- a/pbs-datastore/src/chunk_store.rs
+++ b/pbs-datastore/src/chunk_store.rs
@@ -6,7 +6,7 @@ use std::sync::{Arc, Mutex};
use anyhow::{bail, format_err, Error};
use pbs_api_types::GarbageCollectionStatus;
-use proxmox_sys::fs::{create_dir, create_path, CreateOptions};
+use proxmox_sys::fs::{create_dir, create_path, file_type_from_file_stat, CreateOptions};
use proxmox_sys::process_locker::{
ProcessLockExclusiveGuard, ProcessLockSharedGuard, ProcessLocker,
};
@@ -375,24 +375,19 @@ 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) {
+ let file_type = file_type_from_file_stat(&stat);
+ if file_type != Some(nix::dir::Type::File) {
+ 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..8609364b 100644
--- a/pbs-datastore/src/hierarchy.rs
+++ b/pbs-datastore/src/hierarchy.rs
@@ -5,6 +5,7 @@ use std::sync::Arc;
use anyhow::{bail, format_err, Error};
use pbs_api_types::{BackupNamespace, BackupType, BACKUP_DATE_REGEX, BACKUP_ID_REGEX};
+use proxmox_sys::fs::get_file_type;
use crate::backup_info::{BackupDir, BackupGroup};
use crate::DataStore;
@@ -36,6 +37,17 @@ impl Iterator for ListSnapshots {
Ok(ref entry) => {
match entry.file_type() {
Some(nix::dir::Type::Directory) => entry, // OK
+ None => match get_file_type(entry.parent_fd(), entry.file_name()) {
+ Ok(nix::dir::Type::Directory) => entry,
+ Ok(_) => continue,
+ Err(err) => {
+ log::info!(
+ "error listing snapshots for {}: {err}",
+ self.group.group()
+ );
+ continue;
+ }
+ },
_ => continue,
}
}
@@ -93,6 +105,17 @@ impl Iterator for ListGroups {
Ok(ref entry) => {
match entry.file_type() {
Some(nix::dir::Type::Directory) => entry, // OK
+ None => match get_file_type(entry.parent_fd(), entry.file_name()) {
+ Ok(nix::dir::Type::Directory) => entry,
+ Ok(_) => continue,
+ Err(err) => {
+ log::info!(
+ "error listing groups for {}: {err}",
+ self.store.name()
+ );
+ continue;
+ }
+ },
_ => continue,
}
}
@@ -114,6 +137,17 @@ impl Iterator for ListGroups {
Ok(ref entry) => {
match entry.file_type() {
Some(nix::dir::Type::Directory) => entry, // OK
+ None => match get_file_type(entry.parent_fd(), entry.file_name()) {
+ Ok(nix::dir::Type::Directory) => entry,
+ Ok(_) => continue,
+ Err(err) => {
+ log::info!(
+ "error listing groups for {}: {err}",
+ self.store.name()
+ );
+ continue;
+ }
+ },
_ => continue,
}
}
@@ -176,6 +210,19 @@ impl Iterator for ListNamespaces {
Ok(ref entry) => {
match entry.file_type() {
Some(nix::dir::Type::Directory) => entry, // OK
+ None => match get_file_type(entry.parent_fd(), entry.file_name()) {
+ Ok(nix::dir::Type::Directory) => entry,
+ Ok(_) => 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
More information about the pbs-devel
mailing list