[pbs-devel] [PATCH proxmox-backup v5 1/8] use 'fs_info' from proxmox-sys

Dominik Csapak d.csapak at proxmox.com
Wed Feb 2 10:50:12 CET 2022


as replacement for 'disk_usage' in tools. also remove that there since
we do not need it anymore

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/api2/admin/datastore.rs     |  4 ++--
 src/api2/node/status.rs         | 11 ++++++++---
 src/api2/status.rs              |  4 ++--
 src/bin/proxmox-backup-proxy.rs |  4 ++--
 src/tools/disks/mod.rs          | 21 +--------------------
 5 files changed, 15 insertions(+), 29 deletions(-)

diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
index 263ea96f..ac60c1af 100644
--- a/src/api2/admin/datastore.rs
+++ b/src/api2/admin/datastore.rs
@@ -616,7 +616,7 @@ pub fn status(
     rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<DataStoreStatus, Error> {
     let datastore = DataStore::lookup_datastore(&store)?;
-    let storage = crate::tools::disks::disk_usage(&datastore.base_path())?;
+    let storage = proxmox_sys::fs::fs_info(&datastore.base_path())?;
     let (counts, gc_status) = if verbose {
         let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
         let user_info = CachedUserInfo::new()?;
@@ -639,7 +639,7 @@ pub fn status(
     Ok(DataStoreStatus {
         total: storage.total,
         used: storage.used,
-        avail: storage.avail,
+        avail: storage.available,
         gc_status,
         counts,
     })
diff --git a/src/api2/node/status.rs b/src/api2/node/status.rs
index 9559dda6..4d48c350 100644
--- a/src/api2/node/status.rs
+++ b/src/api2/node/status.rs
@@ -1,5 +1,4 @@
 use std::process::Command;
-use std::path::Path;
 
 use anyhow::{Error, format_err, bail};
 use serde_json::Value;
@@ -9,7 +8,7 @@ use proxmox_sys::linux::procfs;
 use proxmox_router::{ApiMethod, Router, RpcEnvironment, Permission};
 use proxmox_schema::api;
 
-use pbs_api_types::{NODE_SCHEMA, NodePowerCommand, PRIV_SYS_AUDIT, PRIV_SYS_POWER_MANAGEMENT};
+use pbs_api_types::{NODE_SCHEMA, NodePowerCommand, PRIV_SYS_AUDIT, PRIV_SYS_POWER_MANAGEMENT, StorageStatus};
 
 use crate::api2::types::{
     NodeCpuInformation, NodeStatus, NodeMemoryCounters, NodeSwapCounters, NodeInformation,
@@ -77,10 +76,16 @@ fn get_status(
         uname.version()
     );
 
+    let disk = proxmox_sys::fs::fs_info(proxmox_lang::c_str!("/"))?;
+
     Ok(NodeStatus {
         memory,
         swap,
-        root: crate::tools::disks::disk_usage(Path::new("/"))?,
+        root: StorageStatus {
+            total: disk.total,
+            used: disk.used,
+            avail: disk.available,
+        },
         uptime: procfs::read_proc_uptime()?.0 as u64,
         loadavg,
         kversion,
diff --git a/src/api2/status.rs b/src/api2/status.rs
index 029529ac..58bf7333 100644
--- a/src/api2/status.rs
+++ b/src/api2/status.rs
@@ -110,13 +110,13 @@ pub fn datastore_status(
                 continue;
             }
         };
-        let status = crate::tools::disks::disk_usage(&datastore.base_path())?;
+        let status = proxmox_sys::fs::fs_info(&datastore.base_path())?;
 
         let mut entry = json!({
             "store": store,
             "total": status.total,
             "used": status.used,
-            "avail": status.avail,
+            "avail": status.available,
             "gc-status": datastore.last_gc_status(),
         });
 
diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs
index 8d0033de..8ebaba1d 100644
--- a/src/bin/proxmox-backup-proxy.rs
+++ b/src/bin/proxmox-backup-proxy.rs
@@ -1066,7 +1066,7 @@ fn check_schedule(worker_type: &str, event_str: &str, id: &str) -> bool {
 
 fn gather_disk_stats(disk_manager: Arc<DiskManage>, path: &Path, rrd_prefix: &str) {
 
-    match proxmox_backup::tools::disks::disk_usage(path) {
+    match proxmox_sys::fs::fs_info(path) {
         Ok(status) => {
             let rrd_key = format!("{}/total", rrd_prefix);
             rrd_update_gauge(&rrd_key, status.total as f64);
@@ -1074,7 +1074,7 @@ fn gather_disk_stats(disk_manager: Arc<DiskManage>, path: &Path, rrd_prefix: &st
             rrd_update_gauge(&rrd_key, status.used as f64);
         }
         Err(err) => {
-            eprintln!("read disk_usage on {:?} failed - {}", path, err);
+            eprintln!("read fs info on {:?} failed - {}", path, err);
         }
     }
 
diff --git a/src/tools/disks/mod.rs b/src/tools/disks/mod.rs
index 080e4ba6..ebc490d1 100644
--- a/src/tools/disks/mod.rs
+++ b/src/tools/disks/mod.rs
@@ -19,7 +19,7 @@ use proxmox_sys::linux::procfs::{MountInfo, mountinfo::Device};
 use proxmox_sys::{io_bail, io_format_err};
 use proxmox_schema::api;
 
-use pbs_api_types::{BLOCKDEVICE_NAME_REGEX, StorageStatus};
+use pbs_api_types::BLOCKDEVICE_NAME_REGEX;
 
 mod zfs;
 pub use zfs::*;
@@ -521,25 +521,6 @@ impl Disk {
     }
 }
 
-/// Returns disk usage information (total, used, avail)
-pub fn disk_usage(path: &std::path::Path) -> Result<StorageStatus, Error> {
-
-    let mut stat: libc::statfs64 = unsafe { std::mem::zeroed() };
-
-    use nix::NixPath;
-
-    let res = path.with_nix_path(|cstr| unsafe { libc::statfs64(cstr.as_ptr(), &mut stat) })?;
-    nix::errno::Errno::result(res)?;
-
-    let bsize = stat.f_bsize as u64;
-
-    Ok(StorageStatus{
-        total: stat.f_blocks*bsize,
-        used: (stat.f_blocks-stat.f_bfree)*bsize,
-        avail: stat.f_bavail*bsize,
-    })
-}
-
 #[api()]
 #[derive(Debug, Serialize, Deserialize)]
 #[serde(rename_all="lowercase")]
-- 
2.30.2






More information about the pbs-devel mailing list