use new proxmox-async crate

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
Dietmar Maurer
2021-11-19 17:36:06 +01:00
parent ea67cd70c9
commit 9a1b24b6b1
56 changed files with 66 additions and 1686 deletions

View File

@ -22,6 +22,8 @@ use proxmox_router::{
};
use proxmox_schema::*;
use proxmox_sys::{task_log, task_warn};
use proxmox_async::blocking::WrappedReaderStream;
use proxmox_async::stream::{AsyncReaderStream, AsyncChannelWriter};
use pxar::accessor::aio::Accessor;
use pxar::EntryKind;
@ -53,8 +55,6 @@ use pbs_datastore::fixed_index::{FixedIndexReader};
use pbs_datastore::index::IndexFile;
use pbs_datastore::manifest::{BackupManifest, CLIENT_LOG_BLOB_NAME, MANIFEST_BLOB_NAME};
use pbs_datastore::prune::compute_prune_info;
use pbs_tools::blocking::WrappedReaderStream;
use pbs_tools::stream::{AsyncReaderStream, AsyncChannelWriter};
use pbs_tools::json::{required_integer_param, required_string_param};
use pbs_config::CachedUserInfo;
use proxmox_rest_server::{WorkerTask, formatter};

View File

@ -226,7 +226,7 @@ async move {
};
if benchmark {
env.log("benchmark finished successfully");
pbs_runtime::block_in_place(|| env.remove_backup())?;
proxmox_async::runtime::block_in_place(|| env.remove_backup())?;
return Ok(());
}
@ -254,13 +254,13 @@ async move {
(Ok(_), Err(err)) => {
env.log(format!("backup ended and finish failed: {}", err));
env.log("removing unfinished backup");
pbs_runtime::block_in_place(|| env.remove_backup())?;
proxmox_async::runtime::block_in_place(|| env.remove_backup())?;
Err(err)
},
(Err(err), Err(_)) => {
env.log(format!("backup failed: {}", err));
env.log("removing failed backup");
pbs_runtime::block_in_place(|| env.remove_backup())?;
proxmox_async::runtime::block_in_place(|| env.remove_backup())?;
Err(err)
},
}

View File

@ -62,7 +62,7 @@ impl Future for UploadChunk {
let (is_duplicate, compressed_size) = match proxmox_lang::try_block! {
let mut chunk = DataBlob::from_raw(raw_data)?;
pbs_runtime::block_in_place(|| {
proxmox_async::runtime::block_in_place(|| {
chunk.verify_unencrypted(this.size as usize, &this.digest)?;
// always comput CRC at server side

View File

@ -244,7 +244,7 @@ fn apt_get_changelog(
let changelog_url = &pkg_info[0].change_log_url;
// FIXME: use 'apt-get changelog' for proxmox packages as well, once repo supports it
if changelog_url.starts_with("http://download.proxmox.com/") {
let changelog = pbs_runtime::block_on(client.get_string(changelog_url, None))
let changelog = proxmox_async::runtime::block_on(client.get_string(changelog_url, None))
.map_err(|err| format_err!("Error downloading changelog from '{}': {}", changelog_url, err))?;
Ok(json!(changelog))
@ -268,7 +268,7 @@ fn apt_get_changelog(
auth_header.insert("Authorization".to_owned(),
format!("Basic {}", base64::encode(format!("{}:{}", key, id))));
let changelog = pbs_runtime::block_on(client.get_string(changelog_url, Some(&auth_header)))
let changelog = proxmox_async::runtime::block_on(client.get_string(changelog_url, Some(&auth_header)))
.map_err(|err| format_err!("Error downloading changelog from '{}': {}", changelog_url, err))?;
Ok(json!(changelog))

View File

@ -289,7 +289,7 @@ fn download_chunk(
env.debug(format!("download chunk {:?}", path));
let data = pbs_runtime::block_in_place(|| std::fs::read(path))
let data = proxmox_async::runtime::block_in_place(|| std::fs::read(path))
.map_err(move |err| http_err!(BAD_REQUEST, "reading file {:?} failed: {}", path2, err))?;
let body = Body::from(data);

View File

@ -21,7 +21,7 @@ use proxmox_backup::config;
fn main() {
proxmox_backup::tools::setup_safe_path_env();
if let Err(err) = pbs_runtime::main(run()) {
if let Err(err) = proxmox_async::runtime::main(run()) {
eprintln!("Error: {}", err);
std::process::exit(-1);
}

View File

@ -20,5 +20,5 @@ fn main() {
let mut rpcenv = CliEnvironment::new();
rpcenv.set_auth_id(Some(format!("{}@pam", username)));
run_cli_command(cmd_def, rpcenv, Some(|future| pbs_runtime::main(future)));
run_cli_command(cmd_def, rpcenv, Some(|future| proxmox_async::runtime::main(future)));
}

View File

@ -440,7 +440,7 @@ fn main() -> Result<(), Error> {
proxmox_backup::tools::setup_safe_path_env();
pbs_runtime::main(run())
proxmox_async::runtime::main(run())
}
fn get_sync_job(id: &String) -> Result<SyncJobConfig, Error> {
@ -499,7 +499,7 @@ pub fn complete_remote_datastore_name(_arg: &str, param: &HashMap<String, String
let mut list = Vec::new();
if let Some(remote) = get_remote(param) {
if let Ok(data) = pbs_runtime::block_on(async move {
if let Ok(data) = proxmox_async::runtime::block_on(async move {
crate::api2::config::remote::scan_remote_datastores(remote).await
}) {
@ -518,7 +518,7 @@ pub fn complete_remote_datastore_group(_arg: &str, param: &HashMap<String, Strin
let mut list = Vec::new();
if let Some((remote, remote_store)) = get_remote_store(param) {
if let Ok(data) = pbs_runtime::block_on(async move {
if let Ok(data) = proxmox_async::runtime::block_on(async move {
crate::api2::config::remote::scan_remote_groups(remote.clone(), remote_store.clone()).await
}) {

View File

@ -85,7 +85,7 @@ fn main() -> Result<(), Error> {
bail!("proxy not running as backup user or group (got uid {} gid {})", running_uid, running_gid);
}
pbs_runtime::main(run())
proxmox_async::runtime::main(run())
}
@ -845,7 +845,7 @@ async fn schedule_task_log_rotate() {
if logrotate.rotate(max_size)? {
println!("rotated access log, telling daemons to re-open log file");
pbs_runtime::block_on(command_reopen_access_logfiles())?;
proxmox_async::runtime::block_on(command_reopen_access_logfiles())?;
task_log!(worker, "API access log was rotated");
} else {
task_log!(worker, "API access log was not rotated");
@ -860,7 +860,7 @@ async fn schedule_task_log_rotate() {
if logrotate.rotate(max_size)? {
println!("rotated auth log, telling daemons to re-open log file");
pbs_runtime::block_on(command_reopen_auth_logfiles())?;
proxmox_async::runtime::block_on(command_reopen_auth_logfiles())?;
task_log!(worker, "API authentication log was rotated");
} else {
task_log!(worker, "API authentication log was not rotated");

View File

@ -104,7 +104,7 @@ fn main() {
let mut rpcenv = CliEnvironment::new();
rpcenv.set_auth_id(Some(String::from("root@pam")));
if let Err(err) = pbs_runtime::main(run(&mut rpcenv)) {
if let Err(err) = proxmox_async::runtime::main(run(&mut rpcenv)) {
eprintln!("error during update: {}", err);
std::process::exit(1);
}

View File

@ -74,7 +74,7 @@ pub fn complete_datastore_group_filter(_arg: &str, param: &HashMap<String, Strin
list.push("type:vm".to_string());
if let Some(store) = param.get("store") {
let groups = pbs_runtime::block_on(async { get_backup_groups(store).await });
let groups = proxmox_async::runtime::block_on(async { get_backup_groups(store).await });
if let Ok(groups) = groups {
list.extend(groups.iter().map(|group| format!("group:{}/{}", group.backup_type, group.backup_id)));
}
@ -1135,5 +1135,5 @@ fn main() {
let mut rpcenv = CliEnvironment::new();
rpcenv.set_auth_id(Some(String::from("root@pam")));
pbs_runtime::main(run_async_cli_command(cmd_def, rpcenv));
proxmox_async::runtime::main(run_async_cli_command(cmd_def, rpcenv));
}

View File

@ -23,7 +23,7 @@ const URL_ASCIISET: percent_encoding::AsciiSet = percent_encoding::NON_ALPHANUME
macro_rules! complete_api_path {
($capability:expr) => {
|complete_me: &str, _map: &HashMap<String, String>| {
pbs_runtime::block_on(async { complete_api_path_do(complete_me, $capability).await })
proxmox_async::runtime::block_on(async { complete_api_path_do(complete_me, $capability).await })
}
};
}

View File

@ -124,7 +124,7 @@ async fn pull_index_chunks<I: IndexFile>(
let verify_and_write_channel = verify_and_write_channel.clone();
Ok::<_, Error>(async move {
let chunk_exists = pbs_runtime::block_in_place(|| {
let chunk_exists = proxmox_async::runtime::block_in_place(|| {
target.cond_touch_chunk(&info.digest, false)
})?;
if chunk_exists {
@ -136,7 +136,7 @@ async fn pull_index_chunks<I: IndexFile>(
let raw_size = chunk.raw_size() as usize;
// decode, verify and write in a separate threads to maximize throughput
pbs_runtime::block_in_place(|| {
proxmox_async::runtime::block_in_place(|| {
verify_and_write_channel.send((chunk, info.digest, info.size()))
})?;

View File

@ -231,7 +231,7 @@ pub fn check_subscription(key: String, server_id: String) -> Result<Subscription
let now = proxmox_time::epoch_i64();
let (response, challenge) = pbs_runtime::block_on(register_subscription(&key, &server_id, now))
let (response, challenge) = proxmox_async::runtime::block_on(register_subscription(&key, &server_id, now))
.map_err(|err| format_err!("Error checking subscription: {}", err))?;
parse_register_response(&response, key, server_id, now, &challenge)