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 4598F69392 for ; Fri, 11 Mar 2022 16:08:10 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8AAEB267A7 for ; Fri, 11 Mar 2022 16:08:09 +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 id 18CBD266F5 for ; Fri, 11 Mar 2022 16:08:05 +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 E3C1246389 for ; Fri, 11 Mar 2022 16:08:04 +0100 (CET) From: Hannes Laimer To: pbs-devel@lists.proxmox.com Date: Fri, 11 Mar 2022 15:07:52 +0000 Message-Id: <20220311150755.73338-8-h.laimer@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220311150755.73338-1-h.laimer@proxmox.com> References: <20220311150755.73338-1-h.laimer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.040 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 T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pbs-devel] [PATCH proxmox-backup 07/10] proxmox-file-restore: replace print with log macro 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: Fri, 11 Mar 2022 15:08:10 -0000 Signed-off-by: Hannes Laimer --- 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 bb1a6e02..f96bea35 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 0176f7f1..658af706 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) -> 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 { - 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 41423c9d..bb810ec9 100644 --- a/proxmox-file-restore/src/main.rs +++ b/proxmox-file-restore/src/main.rs @@ -163,7 +163,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)?)) @@ -296,12 +296,6 @@ async fn list( type: CryptMode, optional: true, }, - verbose: { - type: Boolean, - description: "Print verbose information", - optional: true, - default: false, - }, "driver": { type: BlockDriverType, optional: true, @@ -315,7 +309,6 @@ async fn extract( path: String, base64: bool, target: Option, - verbose: bool, param: Value, ) -> Result<(), Error> { let repo = extract_repository_from_value(¶m)?; @@ -336,7 +329,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)?)) @@ -374,7 +367,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 { @@ -391,7 +384,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 @@ -416,7 +409,6 @@ async fn extract_to_target( decoder: Accessor, path: &[u8], target: Option, - verbose: bool, ) -> Result<(), Error> where T: pxar::accessor::ReadAt + Clone + Send + Sync + Unpin + 'static, @@ -430,7 +422,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 { .. } => { @@ -441,7 +433,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 99c45859..c6c52cd6 100644 --- a/proxmox-file-restore/src/qemu_helper.rs +++ b/proxmox-file-restore/src/qemu_helper.rs @@ -153,7 +153,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() @@ -291,11 +291,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."); } } @@ -311,12 +311,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() { // check if QEMU process exited in between @@ -331,7 +329,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