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 BA1CA75F8E for ; Wed, 14 Jul 2021 13:41:52 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A7473107F0 for ; Wed, 14 Jul 2021 13:41:52 +0200 (CEST) Received: from elsa.proxmox.com (unknown [94.136.29.99]) by firstgate.proxmox.com (Proxmox) with ESMTP id AEF57107E4 for ; Wed, 14 Jul 2021 13:41:49 +0200 (CEST) Received: by elsa.proxmox.com (Postfix, from userid 0) id 8405BAE0B3F; Wed, 14 Jul 2021 13:41:49 +0200 (CEST) From: Dietmar Maurer To: pbs-devel@lists.proxmox.com Date: Wed, 14 Jul 2021 13:41:48 +0200 Message-Id: <20210714114148.1333612-1-dietmar@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.500 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 RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS 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] depend on proxmox 0.11.6 (changed make_tmp_file() return type) 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, 14 Jul 2021 11:41:52 -0000 --- Cargo.toml | 2 +- src/bin/proxmox_file_restore/qemu_helper.rs | 30 +++++++++------------ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2804632c..e01b94d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -86,7 +86,7 @@ pathpatterns = "0.1.2" pxar = { version = "0.10.1", features = [ "tokio-io" ] } #pxar = { path = "../pxar", features = [ "tokio-io" ] } -proxmox = { version = "0.11.5", features = [ "sortable-macro", "api-macro" ] } +proxmox = { version = "0.11.6", features = [ "sortable-macro", "api-macro" ] } #proxmox = { git = "git://git.proxmox.com/git/proxmox", version = "0.1.2", features = [ "sortable-macro", "api-macro" ] } #proxmox = { path = "../proxmox/proxmox", features = [ "sortable-macro", "api-macro" ] } proxmox-acme-rs = "0.2.1" diff --git a/src/bin/proxmox_file_restore/qemu_helper.rs b/src/bin/proxmox_file_restore/qemu_helper.rs index 8ab372a1..83e772cb 100644 --- a/src/bin/proxmox_file_restore/qemu_helper.rs +++ b/src/bin/proxmox_file_restore/qemu_helper.rs @@ -1,7 +1,7 @@ //! Helper to start a QEMU VM for single file restore. use std::fs::{File, OpenOptions}; use std::io::prelude::*; -use std::os::unix::io::{AsRawFd, FromRawFd}; +use std::os::unix::io::AsRawFd; use std::path::PathBuf; use std::time::Duration; @@ -11,10 +11,7 @@ use tokio::time; use nix::sys::signal::{kill, Signal}; use nix::unistd::Pid; -use proxmox::tools::{ - fd::Fd, - fs::{create_path, file_read_string, make_tmp_file, CreateOptions}, -}; +use proxmox::tools::fs::{create_path, file_read_string, make_tmp_file, CreateOptions}; use proxmox_backup::backup::backup_user; use proxmox_backup::client::{VsockClient, DEFAULT_VSOCK_PORT}; @@ -83,14 +80,14 @@ pub fn try_kill_vm(pid: i32) -> Result<(), Error> { Ok(()) } -async fn create_temp_initramfs(ticket: &str, debug: bool) -> Result<(Fd, String), Error> { +async fn create_temp_initramfs(ticket: &str, debug: bool) -> Result<(File, String), Error> { use std::ffi::CString; use tokio::fs::File; - let (tmp_fd, tmp_path) = + let (tmp_file, tmp_path) = make_tmp_file("/tmp/file-restore-qemu.initramfs.tmp", CreateOptions::new())?; nix::unistd::unlink(&tmp_path)?; - tools::fd_change_cloexec(tmp_fd.0, false)?; + tools::fd_change_cloexec(tmp_file.as_raw_fd(), false)?; let initramfs = if debug { pbs_buildcfg::PROXMOX_BACKUP_INITRAMFS_DBG_FN @@ -98,7 +95,7 @@ async fn create_temp_initramfs(ticket: &str, debug: bool) -> Result<(Fd, String) pbs_buildcfg::PROXMOX_BACKUP_INITRAMFS_FN }; - let mut f = File::from_std(unsafe { std::fs::File::from_raw_fd(tmp_fd.0) }); + let mut f = File::from_std(tmp_file); let mut base = File::open(initramfs).await?; tokio::io::copy(&mut base, &mut f).await?; @@ -118,11 +115,10 @@ async fn create_temp_initramfs(ticket: &str, debug: bool) -> Result<(Fd, String) .await?; tools::cpio::append_trailer(&mut f).await?; - // forget the tokio file, we close the file descriptor via the returned Fd - std::mem::forget(f); + let tmp_file = f.into_std().await; + let path = format!("/dev/fd/{}", &tmp_file.as_raw_fd()); - let path = format!("/dev/fd/{}", &tmp_fd.0); - Ok((tmp_fd, path)) + Ok((tmp_file, path)) } pub async fn start_vm( @@ -145,9 +141,9 @@ pub async fn start_vm( validate_img_existance(debug)?; let pid; - let (pid_fd, pid_path) = make_tmp_file("/tmp/file-restore-qemu.pid.tmp", CreateOptions::new())?; + let (mut pid_file, pid_path) = make_tmp_file("/tmp/file-restore-qemu.pid.tmp", CreateOptions::new())?; nix::unistd::unlink(&pid_path)?; - tools::fd_change_cloexec(pid_fd.0, false)?; + tools::fd_change_cloexec(pid_file.as_raw_fd(), false)?; let (_ramfs_pid, ramfs_path) = create_temp_initramfs(ticket, debug).await?; @@ -194,7 +190,7 @@ pub async fn start_vm( ), "-daemonize", "-pidfile", - &format!("/dev/fd/{}", pid_fd.as_raw_fd()), + &format!("/dev/fd/{}", pid_file.as_raw_fd()), "-name", PBS_VM_NAME, ]; @@ -281,8 +277,6 @@ pub async fn start_vm( // at this point QEMU is already daemonized and running, so if anything fails we // technically leave behind a zombie-VM... this shouldn't matter, as it will stop // itself soon enough (timer), and the following operations are unlikely to fail - let mut pid_file = unsafe { File::from_raw_fd(pid_fd.as_raw_fd()) }; - std::mem::forget(pid_fd); // FD ownership is now in pid_fd/File let mut pidstr = String::new(); pid_file.read_to_string(&mut pidstr)?; pid = pidstr.trim_end().parse().map_err(|err| { -- 2.30.2