diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index 5448fa10..eb1a4511 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -629,7 +629,7 @@ fn get_snapshots_count(store: &Arc, 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, diff --git a/src/api2/node/status.rs b/src/api2/node/status.rs index 65d1ec1b..4cf5e696 100644 --- a/src/api2/node/status.rs +++ b/src/api2/node/status.rs @@ -43,7 +43,7 @@ impl std::convert::From 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, diff --git a/src/api2/status.rs b/src/api2/status.rs index 8b97bef9..0f2e42d6 100644 --- a/src/api2/status.rs +++ b/src/api2/status.rs @@ -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(), diff --git a/src/tools/fs.rs b/src/tools/fs.rs new file mode 100644 index 00000000..4eab0d56 --- /dev/null +++ b/src/tools/fs.rs @@ -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 { + 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 { + Ok(spawn_blocking(move || proxmox_sys::fs::fs_info(path)) + .await + .map_err(|err| format_err!("error waiting for fs_info call: {err}"))??) +} diff --git a/src/tools/mod.rs b/src/tools/mod.rs index 8ac73d6e..35946bd6 100644 --- a/src/tools/mod.rs +++ b/src/tools/mod.rs @@ -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;