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 CBE9E602F0 for ; Tue, 8 Sep 2020 15:02:56 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id BFA809D7F for ; Tue, 8 Sep 2020 15:02:56 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 83FF59D74 for ; Tue, 8 Sep 2020 15:02:55 +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 522D344A97 for ; Tue, 8 Sep 2020 15:02:55 +0200 (CEST) From: Stefan Reiter To: pbs-devel@lists.proxmox.com Date: Tue, 8 Sep 2020 15:02:46 +0200 Message-Id: <20200908130246.8065-1-s.reiter@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.056 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup] clean up .bad file handling in sweep_unused_chunks 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, 08 Sep 2020 13:02:56 -0000 Code cleanup, no functional change intended. Signed-off-by: Stefan Reiter --- 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