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 A87E985150 for ; Fri, 17 Dec 2021 09:10:34 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8AA7C28739 for ; Fri, 17 Dec 2021 09:10:04 +0100 (CET) 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 869B2286DE for ; Fri, 17 Dec 2021 09:10:01 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 60AD04539A for ; Fri, 17 Dec 2021 09:10:01 +0100 (CET) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Fri, 17 Dec 2021 09:09:55 +0100 Message-Id: <20211217081000.1061796-5-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211217081000.1061796-1-d.csapak@proxmox.com> References: <20211217081000.1061796-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.172 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [status.total, proxmox-backup-proxy.rs, status.rs, mod.rs, datastore.rs] Subject: [pbs-devel] [PATCH proxmox-backup v3 1/6] 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: Fri, 17 Dec 2021 08:10:34 -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 | 10 ++++++++-- src/api2/status.rs | 4 ++-- src/bin/proxmox-backup-proxy.rs | 4 ++-- src/tools/disks/mod.rs | 21 +-------------------- 5 files changed, 15 insertions(+), 28 deletions(-) diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index b653f906..029153b3 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -612,7 +612,7 @@ pub fn status( rpcenv: &mut dyn RpcEnvironment, ) -> Result { 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()?; @@ -635,7 +635,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..fb394fbf 100644 --- a/src/api2/node/status.rs +++ b/src/api2/node/status.rs @@ -9,7 +9,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 +77,16 @@ fn get_status( uname.version() ); + let disk = proxmox_sys::fs::fs_info(Path::new("/"))?; + 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 7f50914b..9424340c 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 07a53687..fbc5f65c 100644 --- a/src/bin/proxmox-backup-proxy.rs +++ b/src/bin/proxmox-backup-proxy.rs @@ -1055,7 +1055,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); @@ -1063,7 +1063,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 867aa624..30d9568f 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 { - - 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