src/restore.rs: implement with_runtime

This commit is contained in:
Dietmar Maurer 2020-07-07 08:13:14 +02:00
parent b960af0485
commit 2b00dbce03

View File

@ -5,6 +5,7 @@ use std::convert::TryInto;
use anyhow::{format_err, bail, Error}; use anyhow::{format_err, bail, Error};
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
use tokio::runtime::Runtime;
use proxmox_backup::tools::runtime::{get_runtime, block_in_place}; use proxmox_backup::tools::runtime::{get_runtime, block_in_place};
use proxmox_backup::backup::*; use proxmox_backup::backup::*;
@ -22,7 +23,7 @@ pub struct ImageAccessInfo {
pub(crate) struct ProxmoxRestore { pub(crate) struct ProxmoxRestore {
setup: BackupSetup, setup: BackupSetup,
runtime: Arc<tokio::runtime::Runtime>, runtime: Arc<Runtime>,
pub crypt_config: Option<Arc<CryptConfig>>, pub crypt_config: Option<Arc<CryptConfig>>,
pub client: OnceCell<Arc<BackupReader>>, pub client: OnceCell<Arc<BackupReader>>,
chunk_reader: OnceCell<RemoteChunkReader>, chunk_reader: OnceCell<RemoteChunkReader>,
@ -32,11 +33,11 @@ pub(crate) struct ProxmoxRestore {
impl ProxmoxRestore { impl ProxmoxRestore {
pub fn new(setup: BackupSetup) -> Result<Self, Error> { /// Create a new instance, using the specified Runtime
///
// keep a reference to the runtime - else the runtime can be dropped /// We keep a reference to the runtime - else the runtime can be
// and further connections fails. /// dropped and further connections fails.
let runtime = get_runtime(); pub fn with_runtime(setup: BackupSetup, runtime: Arc<Runtime>) -> Result<Self, Error> {
let crypt_config = match setup.keyfile { let crypt_config = match setup.keyfile {
None => None, None => None,
@ -62,6 +63,11 @@ impl ProxmoxRestore {
}) })
} }
pub fn new(setup: BackupSetup) -> Result<Self, Error> {
let runtime = get_runtime();
Self::with_runtime(setup, runtime)
}
pub async fn connect(&self) -> Result<libc::c_int, Error> { pub async fn connect(&self) -> Result<libc::c_int, Error> {
let options = HttpClientOptions::new() let options = HttpClientOptions::new()