clean up .bad file handling in sweep_unused_chunks

Code cleanup, no functional change intended.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
This commit is contained in:
Stefan Reiter 2020-09-08 15:02:46 +02:00 committed by Dietmar Maurer
parent 3cddfb29be
commit 597427afaf
1 changed files with 23 additions and 35 deletions

View File

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