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

Dominik Csapak d.csapak at proxmox.com
Thu Jun 2 14:18:04 CEST 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         | 13 ++++++++++---
 src/api2/status.rs              |  4 ++--
 src/bin/proxmox-backup-proxy.rs |  4 ++--
 src/tools/disks/mod.rs          | 20 +-------------------
 5 files changed, 17 insertions(+), 28 deletions(-)

diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
index 952fe2e0..84219189 100644
--- a/src/api2/admin/datastore.rs
+++ b/src/api2/admin/datastore.rs
@@ -675,11 +675,11 @@ pub fn status(
     };
 
     Ok(if store_stats {
-        let storage = crate::tools::disks::disk_usage(&datastore.base_path())?;
+        let storage = proxmox_sys::fs::fs_info(&datastore.base_path())?;
         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 da394625..3554980f 100644
--- a/src/api2/node/status.rs
+++ b/src/api2/node/status.rs
@@ -1,4 +1,3 @@
-use std::path::Path;
 use std::process::Command;
 
 use anyhow::{bail, format_err, Error};
@@ -9,7 +8,9 @@ use proxmox_sys::linux::procfs;
 use proxmox_router::{ApiMethod, Permission, Router, RpcEnvironment};
 use proxmox_schema::api;
 
-use pbs_api_types::{NodePowerCommand, NODE_SCHEMA, PRIV_SYS_AUDIT, PRIV_SYS_POWER_MANAGEMENT};
+use pbs_api_types::{
+    NodePowerCommand, StorageStatus, NODE_SCHEMA, PRIV_SYS_AUDIT, PRIV_SYS_POWER_MANAGEMENT,
+};
 
 use crate::api2::types::{
     NodeCpuInformation, NodeInformation, NodeMemoryCounters, NodeStatus, NodeSwapCounters,
@@ -77,10 +78,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 55c811a5..8b97bef9 100644
--- a/src/api2/status.rs
+++ b/src/api2/status.rs
@@ -64,13 +64,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 = DataStoreStatusListItem {
             store: store.clone(),
             total: status.total as i64,
             used: status.used as i64,
-            avail: status.avail as i64,
+            avail: status.available as i64,
             history: None,
             history_start: None,
             history_delta: None,
diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs
index b45c3456..bf4b62f6 100644
--- a/src/bin/proxmox-backup-proxy.rs
+++ b/src/bin/proxmox-backup-proxy.rs
@@ -1126,7 +1126,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);
@@ -1134,7 +1134,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 568dccbf..77635fc4 100644
--- a/src/tools/disks/mod.rs
+++ b/src/tools/disks/mod.rs
@@ -19,7 +19,7 @@ use proxmox_lang::{io_bail, io_format_err};
 use proxmox_schema::api;
 use proxmox_sys::linux::procfs::{mountinfo::Device, MountInfo};
 
-use pbs_api_types::{StorageStatus, BLOCKDEVICE_NAME_REGEX};
+use pbs_api_types::BLOCKDEVICE_NAME_REGEX;
 
 mod zfs;
 pub use zfs::*;
@@ -528,24 +528,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