restore-daemon: put blocking code into 'block_in_place'

DISK_STATE.lock() and '.resolve()' can both block since they access
the disks. Putting them into a 'block_in_place' makes tokio move it
out in its own thread to avoid that the executor isn't able to
progress any other futures in the mean time.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Dominik Csapak 2022-04-26 12:13:55 +02:00 committed by Thomas Lamprecht
parent 436a48d611
commit 4d76ab91e4
1 changed files with 7 additions and 5 deletions

View File

@ -148,8 +148,10 @@ fn list(
let path_str = OsStr::from_bytes(&path[..]); let path_str = OsStr::from_bytes(&path[..]);
let param_path_buf = Path::new(path_str); let param_path_buf = Path::new(path_str);
let query_result = proxmox_async::runtime::block_in_place(move || {
let mut disk_state = crate::DISK_STATE.lock().unwrap(); let mut disk_state = crate::DISK_STATE.lock().unwrap();
let query_result = disk_state.resolve(param_path_buf)?; disk_state.resolve(param_path_buf)
})?;
match query_result { match query_result {
ResolveResult::Path(vm_path) => { ResolveResult::Path(vm_path) => {
@ -270,10 +272,10 @@ fn extract(
let pxar = param["pxar"].as_bool().unwrap_or(true); let pxar = param["pxar"].as_bool().unwrap_or(true);
let query_result = { let query_result = proxmox_async::runtime::block_in_place(move || {
let mut disk_state = crate::DISK_STATE.lock().unwrap(); let mut disk_state = crate::DISK_STATE.lock().unwrap();
disk_state.resolve(path)? disk_state.resolve(path)
}; })?;
let vm_path = match query_result { let vm_path = match query_result {
ResolveResult::Path(vm_path) => vm_path, ResolveResult::Path(vm_path) => vm_path,