From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id BA50574F6A for ; Thu, 2 Jun 2022 14:18:15 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B0EED4455 for ; Thu, 2 Jun 2022 14:18:15 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 91DDC43FA for ; Thu, 2 Jun 2022 14:18:12 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 61D25439FF for ; Thu, 2 Jun 2022 14:18:12 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Thu, 2 Jun 2022 14:18:04 +0200 Message-Id: <20220602121811.3472729-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220602121811.3472729-1-d.csapak@proxmox.com> References: <20220602121811.3472729-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.111 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [mod.rs, datastore.rs, status.rs, proxmox-backup-proxy.rs, status.total] Subject: [pbs-devel] [PATCH proxmox-backup v7 1/8] use 'fs_info' from proxmox-sys X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Jun 2022 12:18:15 -0000 as replacement for 'disk_usage' in tools. also remove that there since we do not need it anymore Signed-off-by: Dominik Csapak --- 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, 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, 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 { - 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