5
0
mirror of git://git.proxmox.com/git/proxmox-backup.git synced 2025-01-08 21:18:07 +03:00

wrap fs_info calls in spawn_blocking

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2022-07-11 10:41:16 +02:00
parent 36156038c9
commit 143ac7e69b
5 changed files with 31 additions and 6 deletions

View File

@ -629,7 +629,7 @@ fn get_snapshots_count(store: &Arc<DataStore>, owner: Option<&Authid>) -> Result
},
)]
/// Get datastore status.
pub fn status(
pub async fn status(
store: String,
verbose: bool,
_info: &ApiMethod,
@ -674,7 +674,7 @@ pub fn status(
};
Ok(if store_stats {
let storage = proxmox_sys::fs::fs_info(&datastore.base_path())?;
let storage = crate::tools::fs::fs_info(datastore.base_path()).await?;
DataStoreStatus {
total: storage.total,
used: storage.used,

View File

@ -43,7 +43,7 @@ impl std::convert::From<procfs::ProcFsCPUInfo> for NodeCpuInformation {
},
)]
/// Read node memory, CPU and (root) disk usage
fn get_status(
async fn get_status(
_param: Value,
_info: &ApiMethod,
_rpcenv: &mut dyn RpcEnvironment,
@ -79,7 +79,7 @@ fn get_status(
std::str::from_utf8(uname.version().as_bytes())?
);
let disk = proxmox_sys::fs::fs_info(proxmox_lang::c_str!("/"))?;
let disk = crate::tools::fs::fs_info_static(proxmox_lang::c_str!("/")).await?;
Ok(NodeStatus {
memory,

View File

@ -33,7 +33,7 @@ use crate::backup::can_access_any_namespace;
},
)]
/// List Datastore usages and estimates
pub fn datastore_status(
pub async fn datastore_status(
_param: Value,
_info: &ApiMethod,
rpcenv: &mut dyn RpcEnvironment,
@ -64,7 +64,7 @@ pub fn datastore_status(
continue;
}
};
let status = proxmox_sys::fs::fs_info(&datastore.base_path())?;
let status = crate::tools::fs::fs_info(datastore.base_path()).await?;
let mut entry = DataStoreStatusListItem {
store: store.clone(),

24
src/tools/fs.rs Normal file
View File

@ -0,0 +1,24 @@
use std::ffi::CStr;
use std::path::PathBuf;
use anyhow::{format_err, Error};
use tokio::task::spawn_blocking;
/// `proxmox_sys::fs::fs_into` wrapped in a `spawn_blocking` call.
pub async fn fs_info(path: PathBuf) -> Result<proxmox_sys::fs::FileSystemInformation, Error> {
Ok(spawn_blocking(move || proxmox_sys::fs::fs_info(&path))
.await
.map_err(|err| format_err!("error waiting for fs_info call: {err}"))??)
}
/// `proxmox_sys::fs::fs_into` wrapped in a `spawn_blocking` call.
///
/// We cannot use `&'static CStr` in the above as we get from `proxmox_lang::c_str!` because
/// `NixPath` is only implemented directly on `CStr`, not on `&CStr`.
pub async fn fs_info_static(
path: &'static CStr,
) -> Result<proxmox_sys::fs::FileSystemInformation, Error> {
Ok(spawn_blocking(move || proxmox_sys::fs::fs_info(path))
.await
.map_err(|err| format_err!("error waiting for fs_info call: {err}"))??)
}

View File

@ -11,6 +11,7 @@ use proxmox_http::{client::SimpleHttp, client::SimpleHttpOptions, ProxyConfig};
pub mod apt;
pub mod config;
pub mod disks;
pub mod fs;
mod shared_rate_limiter;
pub use shared_rate_limiter::SharedRateLimiter;