public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH proxmox-backup] clean up .bad file handling in sweep_unused_chunks
@ 2020-09-08 13:02 Stefan Reiter
  2020-09-10  4:37 ` Dietmar Maurer
  2020-09-10  4:38 ` [pbs-devel] applied: " Dietmar Maurer
  0 siblings, 2 replies; 3+ messages in thread
From: Stefan Reiter @ 2020-09-08 13:02 UTC (permalink / raw)
  To: pbs-devel

Code cleanup, no functional change intended.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
---
 src/backup/chunk_store.rs | 58 ++++++++++++++++-----------------------
 1 file changed, 23 insertions(+), 35 deletions(-)

diff --git a/src/backup/chunk_store.rs b/src/backup/chunk_store.rs
index 1d9de70a..7f5c0693 100644
--- a/src/backup/chunk_store.rs
+++ b/src/backup/chunk_store.rs
@@ -325,52 +325,40 @@ impl ChunkStore {
 
             if let Ok(stat) = fstatat(dirfd, filename, nix::fcntl::AtFlags::AT_SYMLINK_NOFOLLOW) {
                 if bad {
-                    match std::ffi::CString::new(&filename.to_bytes()[..64]) {
-                        Ok(orig_filename) => {
-                            match fstatat(
-                                dirfd,
-                                orig_filename.as_c_str(),
-                                nix::fcntl::AtFlags::AT_SYMLINK_NOFOLLOW)
-                            {
-                                Ok(_) => { /* do nothing */ },
-                                Err(nix::Error::Sys(nix::errno::Errno::ENOENT)) => {
-                                    // chunk hasn't been rewritten yet, keep
-                                    // .bad file around for manual recovery
-                                    continue;
-                                },
-                                Err(err) => {
-                                    // some other error, warn user and keep
-                                    // .bad file around too
+                    // filename validity checked in iterator
+                    let orig_filename = std::ffi::CString::new(&filename.to_bytes()[..64]).unwrap();
+                    match fstatat(
+                        dirfd,
+                        orig_filename.as_c_str(),
+                        nix::fcntl::AtFlags::AT_SYMLINK_NOFOLLOW)
+                    {
+                        Ok(_) => {
+                            match unlinkat(Some(dirfd), filename, UnlinkatFlags::NoRemoveDir) {
+                                Err(err) =>
                                     worker.warn(format!(
-                                        "error during stat on '{:?}' - {}",
-                                        orig_filename,
+                                        "unlinking corrupt chunk {:?} failed on store '{}' - {}",
+                                        filename,
+                                        self.name,
                                         err,
-                                    ));
-                                    continue;
+                                    )),
+                                Ok(_) => {
+                                    status.removed_bad += 1;
+                                    status.removed_bytes += stat.st_size as u64;
                                 }
                             }
                         },
+                        Err(nix::Error::Sys(nix::errno::Errno::ENOENT)) => {
+                            // chunk hasn't been rewritten yet, keep .bad file
+                        },
                         Err(err) => {
+                            // some other error, warn user and keep .bad file around too
                             worker.warn(format!(
-                                "could not get original filename from .bad file '{:?}' - {}",
-                                filename,
+                                "error during stat on '{:?}' - {}",
+                                orig_filename,
                                 err,
                             ));
-                            continue;
                         }
                     }
-
-                    if let Err(err) = unlinkat(Some(dirfd), filename, UnlinkatFlags::NoRemoveDir) {
-                        worker.warn(format!(
-                            "unlinking corrupt chunk {:?} failed on store '{}' - {}",
-                            filename,
-                            self.name,
-                            err,
-                        ));
-                    } else {
-                        status.removed_bad += 1;
-                        status.removed_bytes += stat.st_size as u64;
-                    }
                 } else if stat.st_atime < min_atime {
                     //let age = now - stat.st_atime;
                     //println!("UNLINK {}  {:?}", age/(3600*24), filename);
-- 
2.20.1





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-09-10  4:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-08 13:02 [pbs-devel] [PATCH proxmox-backup] clean up .bad file handling in sweep_unused_chunks Stefan Reiter
2020-09-10  4:37 ` Dietmar Maurer
2020-09-10  4:38 ` [pbs-devel] applied: " Dietmar Maurer

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