all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Hannes Laimer <h.laimer@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup rebased 6/9] proxmox-file-restore: replace print with log macro
Date: Tue, 10 May 2022 09:01:55 +0000	[thread overview]
Message-ID: <20220510090158.33504-8-h.laimer@proxmox.com> (raw)
In-Reply-To: <20220510090158.33504-1-h.laimer@proxmox.com>

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
 proxmox-file-restore/Cargo.toml               |  1 +
 proxmox-file-restore/src/block_driver_qemu.rs |  6 +++---
 proxmox-file-restore/src/main.rs              | 19 +++++--------------
 proxmox-file-restore/src/qemu_helper.rs       | 18 ++++++++----------
 4 files changed, 17 insertions(+), 27 deletions(-)

diff --git a/proxmox-file-restore/Cargo.toml b/proxmox-file-restore/Cargo.toml
index 81eb7299..637143c7 100644
--- a/proxmox-file-restore/Cargo.toml
+++ b/proxmox-file-restore/Cargo.toml
@@ -9,6 +9,7 @@ anyhow = "1.0"
 base64 = "0.13"
 futures = "0.3"
 libc = "0.2"
+log = "0.4"
 nix = "0.19.1"
 serde = { version = "1.0", features = ["derive"] }
 serde_json = "1.0"
diff --git a/proxmox-file-restore/src/block_driver_qemu.rs b/proxmox-file-restore/src/block_driver_qemu.rs
index b9386ebc..b0b222b5 100644
--- a/proxmox-file-restore/src/block_driver_qemu.rs
+++ b/proxmox-file-restore/src/block_driver_qemu.rs
@@ -94,7 +94,7 @@ async fn cleanup_map(map: &mut HashMap<String, VMState>) -> bool {
         if res.is_err() {
             // VM is not reachable, remove from map and inform user
             to_remove.push(name.clone());
-            eprintln!(
+            log::warn!(
                 "VM '{}' (pid: {}, cid: {}) was not reachable, removing from map",
                 name, state.pid, state.cid
             );
@@ -130,7 +130,7 @@ async fn ensure_running(details: &SnapRestoreDetails) -> Result<VsockClient, Err
                     return Ok(client);
                 }
                 Err(err) => {
-                    eprintln!("stale VM detected, restarting ({})", err);
+                    log::warn!("stale VM detected, restarting ({})", err);
                     // VM is dead, restart
                     let _ = super::qemu_helper::try_kill_vm(vm.pid);
                     let vms = start_vm(vm.cid, details).await?;
@@ -229,7 +229,7 @@ impl BlockRestoreDriver for QemuBlockDriver {
                     )
                     .await
                 {
-                    eprintln!("reading file extraction stream failed - {}", err);
+                    log::error!("reading file extraction stream failed - {}", err);
                     std::process::exit(1);
                 }
             });
diff --git a/proxmox-file-restore/src/main.rs b/proxmox-file-restore/src/main.rs
index c1814897..b41a6987 100644
--- a/proxmox-file-restore/src/main.rs
+++ b/proxmox-file-restore/src/main.rs
@@ -254,7 +254,7 @@ async fn list(
         Some(ref key) => {
             let (key, _, _) =
                 decrypt_key(&key.key, &get_encryption_key_password).map_err(|err| {
-                    eprintln!("{}", format_key_source(&key.source, "encryption"));
+                    log::error!("{}", format_key_source(&key.source, "encryption"));
                     err
                 })?;
             Some(Arc::new(CryptConfig::new(key)?))
@@ -361,12 +361,6 @@ async fn list(
                type: CryptMode,
                optional: true,
            },
-           verbose: {
-               type: Boolean,
-               description: "Print verbose information",
-               optional: true,
-               default: false,
-           },
            "driver": {
                type: BlockDriverType,
                optional: true,
@@ -380,7 +374,6 @@ async fn extract(
     path: String,
     base64: bool,
     target: Option<String>,
-    verbose: bool,
     param: Value,
 ) -> Result<(), Error> {
     let repo = extract_repository_from_value(&param)?;
@@ -401,7 +394,7 @@ async fn extract(
         Some(ref key) => {
             let (key, _, _) =
                 decrypt_key(&key.key, &get_encryption_key_password).map_err(|err| {
-                    eprintln!("{}", format_key_source(&key.source, "encryption"));
+                    log::error!("{}", format_key_source(&key.source, "encryption"));
                     err
                 })?;
             Some(Arc::new(CryptConfig::new(key)?))
@@ -439,7 +432,7 @@ async fn extract(
             let archive_size = reader.archive_size();
             let reader = LocalDynamicReadAt::new(reader);
             let decoder = Accessor::new(reader, archive_size).await?;
-            extract_to_target(decoder, &path, target, verbose).await?;
+            extract_to_target(decoder, &path, target).await?;
         }
         ExtractPath::VM(file, path) => {
             let details = SnapRestoreDetails {
@@ -456,7 +449,7 @@ async fn extract(
             if let Some(mut target) = target {
                 let reader = data_extract(driver, details, file, path.clone(), true).await?;
                 let decoder = Decoder::from_tokio(reader).await?;
-                extract_sub_dir_seq(&target, decoder, verbose).await?;
+                extract_sub_dir_seq(&target, decoder).await?;
 
                 // we extracted a .pxarexclude-cli file auto-generated by the VM when encoding the
                 // archive, this file is of no use for the user, so try to remove it
@@ -481,7 +474,6 @@ async fn extract_to_target<T>(
     decoder: Accessor<T>,
     path: &[u8],
     target: Option<PathBuf>,
-    verbose: bool,
 ) -> Result<(), Error>
 where
     T: pxar::accessor::ReadAt + Clone + Send + Sync + Unpin + 'static,
@@ -495,7 +487,7 @@ where
         .ok_or_else(|| format_err!("error opening '{:?}'", path))?;
 
     if let Some(target) = target {
-        extract_sub_dir(target, decoder, OsStr::from_bytes(path), verbose).await?;
+        extract_sub_dir(target, decoder, OsStr::from_bytes(path)).await?;
     } else {
         match file.kind() {
             pxar::EntryKind::File { .. } => {
@@ -506,7 +498,6 @@ where
                     tokio::io::stdout(),
                     decoder,
                     OsStr::from_bytes(path),
-                    verbose,
                 )
                 .await?;
             }
diff --git a/proxmox-file-restore/src/qemu_helper.rs b/proxmox-file-restore/src/qemu_helper.rs
index b7d4eec7..2a5ba4f5 100644
--- a/proxmox-file-restore/src/qemu_helper.rs
+++ b/proxmox-file-restore/src/qemu_helper.rs
@@ -154,7 +154,7 @@ pub async fn start_vm(
     let mut logrotate = LogRotate::new(logfile, false, Some(16), None)?;
 
     if let Err(err) = logrotate.do_rotate() {
-        eprintln!("warning: logrotate for QEMU log file failed - {}", err);
+        log::warn!("warning: logrotate for QEMU log file failed - {}", err);
     }
 
     let mut logfd = OpenOptions::new()
@@ -292,11 +292,11 @@ pub async fn start_vm(
                     bail!("CID '{}' in use, but max attempts reached, aborting", cid);
                 }
                 // CID in use, try next higher one
-                eprintln!("CID '{}' in use by other VM, attempting next one", cid);
+                log::info!("CID '{}' in use by other VM, attempting next one", cid);
                 // skip special-meaning low values
                 cid = cid.wrapping_add(1).max(10);
             } else {
-                eprint!("{}", out);
+                log::error!("{}", out);
                 bail!("Starting VM failed. See output above for more information.");
             }
         }
@@ -312,12 +312,10 @@ pub async fn start_vm(
         if let Ok(Ok(_)) =
             time::timeout(Duration::from_secs(2), client.get("api2/json/status", None)).await
         {
-            if debug {
-                eprintln!(
-                    "Connect to '/run/proxmox-backup/file-restore-serial-{}.sock' for shell access",
-                    cid
-                )
-            }
+            log::debug!(
+                "Connect to '/run/proxmox-backup/file-restore-serial-{}.sock' for shell access",
+                cid
+            );
             return Ok((pid, cid as i32));
         }
         if kill(pid_t, None).is_err() {
@@ -333,7 +331,7 @@ pub async fn start_vm(
 
     // start failed
     if let Err(err) = try_kill_vm(pid) {
-        eprintln!("killing failed VM failed: {}", err);
+        log::error!("killing failed VM failed: {}", err);
     }
     bail!("starting VM timed out");
 }
-- 
2.30.2





  parent reply	other threads:[~2022-05-10  9:02 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-10  9:01 [pbs-devel] [PATCH-SERIES] replace print by log macro in libraries Hannes Laimer
2022-05-10  9:01 ` [pbs-devel] [PATCH proxmox-backup rebased 1/9] bins: init cli logger Hannes Laimer
2022-05-10  9:01 ` [pbs-devel] [PATCH proxmox 1/1] router: add init_cli_logger helper function Hannes Laimer
2022-05-10  9:01 ` [pbs-devel] [PATCH proxmox-backup rebased 2/9] pbs-client: replace print with log macro Hannes Laimer
2022-05-31  8:38   ` Wolfgang Bumiller
2022-05-10  9:01 ` [pbs-devel] [PATCH proxmox-backup rebased 3/9] pbs-datastore: " Hannes Laimer
2022-05-31  8:44   ` Wolfgang Bumiller
2022-05-10  9:01 ` [pbs-devel] [PATCH proxmox-backup rebased 4/9] pbs-fuse+pbs-tape: " Hannes Laimer
2022-05-10  9:01 ` [pbs-devel] [PATCH proxmox-backup rebased 5/9] proxmox-backup-client: " Hannes Laimer
2022-05-10  9:01 ` Hannes Laimer [this message]
2022-05-10  9:01 ` [pbs-devel] [PATCH proxmox-backup rebased 7/9] proxmox-rest-server: " Hannes Laimer
2022-05-10  9:01 ` [pbs-devel] [PATCH proxmox-backup rebased 8/9] " Hannes Laimer
2022-05-31  8:42   ` Wolfgang Bumiller
2022-05-10  9:01 ` [pbs-devel] [PATCH proxmox-backup rebased 9/9] docs: add note for setting verbosity level Hannes Laimer

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=20220510090158.33504-8-h.laimer@proxmox.com \
    --to=h.laimer@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