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 841A49195 for ; Wed, 8 Mar 2023 11:58:28 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 6717F1F316 for ; Wed, 8 Mar 2023 11:57:58 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (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 firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 8 Mar 2023 11:57:57 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id C1D8E461EF for ; Wed, 8 Mar 2023 11:57:56 +0100 (CET) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pbs-devel@lists.proxmox.com Date: Wed, 8 Mar 2023 11:57:48 +0100 Message-Id: <20230308105748.296776-2-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230308105748.296776-1-f.gruenbichler@proxmox.com> References: <20230308105748.296776-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.123 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [create.rs] Subject: [pbs-devel] [PATCH proxmox-backup 2/2] pxar creation: use log crate for error reporting 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: Wed, 08 Mar 2023 10:58:28 -0000 gives a higher (runtime) control via PBS_LOG, so that users can decide themselves which messages, sources and levels are interesting for a particular use case. Signed-off-by: Fabian Grünbichler --- Notes: could also be seen as part of fixing #4578 and squashed into previous commit tried to follow a basic "can happen, but might be noteworthy" vs "should be fixed" when deciding on warn vs. error. pbs-client/src/pxar/create.rs | 47 ++++++++--------------------------- 1 file changed, 11 insertions(+), 36 deletions(-) diff --git a/pbs-client/src/pxar/create.rs b/pbs-client/src/pxar/create.rs index 4bc22bf4..613559d2 100644 --- a/pbs-client/src/pxar/create.rs +++ b/pbs-client/src/pxar/create.rs @@ -1,7 +1,7 @@ use std::collections::{HashMap, HashSet}; use std::ffi::{CStr, CString, OsStr}; use std::fmt; -use std::io::{self, Read, Write}; +use std::io::{self, Read}; use std::os::unix::ffi::OsStrExt; use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, OwnedFd, RawFd}; use std::path::{Path, PathBuf}; @@ -113,19 +113,6 @@ struct HardLinkInfo { st_ino: u64, } -/// And the error case. -struct ErrorReporter; - -impl std::io::Write for ErrorReporter { - fn write(&mut self, data: &[u8]) -> io::Result { - std::io::stderr().write(data) - } - - fn flush(&mut self) -> io::Result<()> { - std::io::stderr().flush() - } -} - struct Archiver { feature_flags: Flags, fs_feature_flags: Flags, @@ -140,7 +127,6 @@ struct Archiver { current_st_dev: libc::dev_t, device_set: Option>, hardlinks: HashMap, - errors: ErrorReporter, file_copy_buffer: Vec, } @@ -205,7 +191,6 @@ where current_st_dev: stat.st_dev, device_set, hardlinks: HashMap::new(), - errors: ErrorReporter, file_copy_buffer: vec::undefined(4 * 1024 * 1024), }; @@ -317,11 +302,7 @@ impl Archiver { Ok(None) } Err(Errno::EACCES) => { - writeln!( - self.errors, - "failed to open file: {:?}: access denied", - file_name - )?; + log::warn!("failed to open file: {:?}: access denied", file_name); Ok(None) } Err(Errno::EPERM) if !noatime.is_empty() => { @@ -351,10 +332,10 @@ impl Archiver { let line = match line { Ok(line) => line, Err(err) => { - let _ = writeln!( - self.errors, + log::warn!( "ignoring .pxarexclude after read error in {:?}: {}", - self.path, err, + self.path, + err, ); self.patterns.truncate(old_pattern_count); return Ok(()); @@ -394,7 +375,7 @@ impl Archiver { } } Err(err) => { - let _ = writeln!(self.errors, "bad pattern in {:?}: {}", self.path, err); + log::error!("bad pattern in {:?}: {}", self.path, err); } } } @@ -493,29 +474,23 @@ impl Archiver { } fn report_vanished_file(&mut self) -> Result<(), Error> { - writeln!( - self.errors, - "warning: file vanished while reading: {:?}", - self.path - )?; + log::warn!("warning: file vanished while reading: {:?}", self.path); Ok(()) } fn report_file_shrunk_while_reading(&mut self) -> Result<(), Error> { - writeln!( - self.errors, + log::warn!( "warning: file size shrunk while reading: {:?}, file will be padded with zeros!", self.path, - )?; + ); Ok(()) } fn report_file_grew_while_reading(&mut self) -> Result<(), Error> { - writeln!( - self.errors, + log::warn!( "warning: file size increased while reading: {:?}, file will be truncated!", self.path, - )?; + ); Ok(()) } -- 2.30.2