depend on proxmox 0.11.6 (changed make_tmp_file() return type)

(cherry picked from commit bfd357c5a1)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Dietmar Maurer 2021-07-14 13:37:26 +02:00 committed by Thomas Lamprecht
parent c26f4ef385
commit 36551172f3
2 changed files with 13 additions and 19 deletions

View File

@ -76,7 +76,7 @@ crossbeam-channel = "0.5"
pathpatterns = "0.1.2" pathpatterns = "0.1.2"
pxar = { version = "0.10.1", features = [ "tokio-io" ] } pxar = { version = "0.10.1", features = [ "tokio-io" ] }
proxmox = { version = "0.11.5", features = [ "sortable-macro", "api-macro", "cli", "router", "tfa" ] } proxmox = { version = "0.11.6", features = [ "sortable-macro", "api-macro", "cli", "router", "tfa" ] }
proxmox-acme-rs = "0.2.1" proxmox-acme-rs = "0.2.1"
proxmox-fuse = "0.1.1" proxmox-fuse = "0.1.1"
proxmox-http = { version = "0.2.1", features = [ "client", "http-helpers", "websocket" ] } proxmox-http = { version = "0.2.1", features = [ "client", "http-helpers", "websocket" ] }

View File

@ -1,7 +1,7 @@
//! Helper to start a QEMU VM for single file restore. //! Helper to start a QEMU VM for single file restore.
use std::fs::{File, OpenOptions}; use std::fs::{File, OpenOptions};
use std::io::prelude::*; use std::io::prelude::*;
use std::os::unix::io::{AsRawFd, FromRawFd}; use std::os::unix::io::AsRawFd;
use std::path::PathBuf; use std::path::PathBuf;
use std::time::Duration; use std::time::Duration;
@ -11,10 +11,7 @@ use tokio::time;
use nix::sys::signal::{kill, Signal}; use nix::sys::signal::{kill, Signal};
use nix::unistd::Pid; use nix::unistd::Pid;
use proxmox::tools::{ use proxmox::tools::fs::{create_path, file_read_string, make_tmp_file, CreateOptions};
fd::Fd,
fs::{create_path, file_read_string, make_tmp_file, CreateOptions},
};
use proxmox_backup::backup::backup_user; use proxmox_backup::backup::backup_user;
use proxmox_backup::client::{VsockClient, DEFAULT_VSOCK_PORT}; use proxmox_backup::client::{VsockClient, DEFAULT_VSOCK_PORT};
@ -83,14 +80,14 @@ pub fn try_kill_vm(pid: i32) -> Result<(), Error> {
Ok(()) 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 std::ffi::CString;
use tokio::fs::File; 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())?; make_tmp_file("/tmp/file-restore-qemu.initramfs.tmp", CreateOptions::new())?;
nix::unistd::unlink(&tmp_path)?; 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 { let initramfs = if debug {
buildcfg::PROXMOX_BACKUP_INITRAMFS_DBG_FN buildcfg::PROXMOX_BACKUP_INITRAMFS_DBG_FN
@ -98,7 +95,7 @@ async fn create_temp_initramfs(ticket: &str, debug: bool) -> Result<(Fd, String)
buildcfg::PROXMOX_BACKUP_INITRAMFS_FN 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?; let mut base = File::open(initramfs).await?;
tokio::io::copy(&mut base, &mut f).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?; .await?;
tools::cpio::append_trailer(&mut f).await?; tools::cpio::append_trailer(&mut f).await?;
// forget the tokio file, we close the file descriptor via the returned Fd let tmp_file = f.into_std().await;
std::mem::forget(f); let path = format!("/dev/fd/{}", &tmp_file.as_raw_fd());
let path = format!("/dev/fd/{}", &tmp_fd.0); Ok((tmp_file, path))
Ok((tmp_fd, path))
} }
pub async fn start_vm( pub async fn start_vm(
@ -145,9 +141,9 @@ pub async fn start_vm(
validate_img_existance(debug)?; validate_img_existance(debug)?;
let pid; 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)?; 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?; let (_ramfs_pid, ramfs_path) = create_temp_initramfs(ticket, debug).await?;
@ -195,7 +191,7 @@ pub async fn start_vm(
}, },
"-daemonize", "-daemonize",
"-pidfile", "-pidfile",
&format!("/dev/fd/{}", pid_fd.as_raw_fd()), &format!("/dev/fd/{}", pid_file.as_raw_fd()),
"-name", "-name",
PBS_VM_NAME, PBS_VM_NAME,
]; ];
@ -282,8 +278,6 @@ pub async fn start_vm(
// at this point QEMU is already daemonized and running, so if anything fails we // 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 // 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 // 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(); let mut pidstr = String::new();
pid_file.read_to_string(&mut pidstr)?; pid_file.read_to_string(&mut pidstr)?;
pid = pidstr.trim_end().parse().map_err(|err| { pid = pidstr.trim_end().parse().map_err(|err| {