all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 2/2] pxar creation: use log crate for error reporting
Date: Wed,  8 Mar 2023 11:57:48 +0100	[thread overview]
Message-ID: <20230308105748.296776-2-f.gruenbichler@proxmox.com> (raw)
In-Reply-To: <20230308105748.296776-1-f.gruenbichler@proxmox.com>

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 <f.gruenbichler@proxmox.com>
---

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<usize> {
-        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<HashSet<u64>>,
     hardlinks: HashMap<HardLinkInfo, (PathBuf, LinkOffset)>,
-    errors: ErrorReporter,
     file_copy_buffer: Vec<u8>,
 }
 
@@ -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





  reply	other threads:[~2023-03-08 10:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-08 10:57 [pbs-devel] [PATCH proxmox-backup 1/2] fix #4578: use log crate for pxar create logging Fabian Grünbichler
2023-03-08 10:57 ` Fabian Grünbichler [this message]
2023-03-27  9:35 ` [pbs-devel] applied-series: " Wolfgang Bumiller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230308105748.296776-2-f.gruenbichler@proxmox.com \
    --to=f.gruenbichler@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal