[PATCH proxmox-backup v2 14/25] metric collection: use blockdev_stat_for_path from proxmox_disks

Lukas Wagner
2026-03-19T09:47:13Z

This part of the gather_disk_stats helper has been moved to
proxmox_disks directly, so it makes sense to use the moved
implementation in PBS as well.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
Tested-by: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
---
src/server/metric_collection/mod.rs | 49 ++++++-----------------------
1 file changed, 10 insertions(+), 39 deletions(-)

diff --git a/src/server/metric_collection/mod.rs b/src/server/metric_collection/mod.rs
index af56eeb19..4c16bcc02 100644
--- a/src/server/metric_collection/mod.rs
+++ b/src/server/metric_collection/mod.rs
@@ -7,10 +7,11 @@ use std::{
};

use anyhow::Error;
+use log::error;
use tokio::join;

use pbs_api_types::{DataStoreConfig, Operation};
-use proxmox_disks::{zfs_dataset_stats, BlockDevStat, DiskManage};
+use proxmox_disks::{BlockDevStat, DiskManage};
use proxmox_network_api::{get_network_interfaces, IpLink};
use proxmox_sys::{
fs::FileSystemInformation,
@@ -221,7 +222,7 @@ fn collect_host_stats_sync() -> HostStats {
fn collect_disk_stats_sync() -> (DiskStat, Vec<DiskStat>) {
let disk_manager = DiskManage::new();

- let root = gather_disk_stats(disk_manager.clone(), Path::new("/"), "host");
+ let root = gather_disk_stats(disk_manager.clone(), Path::new("/"), "root".into());

let mut datastores = Vec::new();
match pbs_config::datastore::config() {
@@ -245,7 +246,7 @@ fn collect_disk_stats_sync() -> (DiskStat, Vec<DiskStat>) {
datastores.push(gather_disk_stats(
disk_manager.clone(),
Path::new(&config.absolute_path()),
- &config.name,
+ config.name.clone(),
));
}
}
@@ -257,7 +258,7 @@ fn collect_disk_stats_sync() -> (DiskStat, Vec<DiskStat>) {
(root, datastores)
}

-fn gather_disk_stats(disk_manager: Arc<DiskManage>, path: &Path, name: &str) -> DiskStat {
+fn gather_disk_stats(disk_manager: Arc<DiskManage>, path: &Path, name: String) -> DiskStat {
let usage = match proxmox_sys::fs::fs_info(path) {
Ok(status) => Some(status),
Err(err) => {
@@ -266,40 +267,10 @@ fn gather_disk_stats(disk_manager: Arc<DiskManage>, path: &Path, name: &str) ->
}
};

- let dev = match disk_manager.find_mounted_device(path) {
- Ok(None) => None,
- Ok(Some((fs_type, device, source))) => {
- let mut device_stat = None;
- match (fs_type.as_str(), source) {
- ("zfs", Some(source)) => match source.into_string() {
- Ok(dataset) => match zfs_dataset_stats(&dataset) {
- Ok(stat) => device_stat = Some(stat),
- Err(err) => eprintln!("zfs_dataset_stats({dataset:?}) failed - {err}"),
- },
- Err(source) => {
- eprintln!("zfs_pool_stats({source:?}) failed - invalid characters")
- }
- },
- _ => {
- if let Ok(disk) = disk_manager.clone().disk_by_dev_num(device.into_dev_t()) {
- match disk.read_stat() {
- Ok(stat) => device_stat = stat,
- Err(err) => eprintln!("disk.read_stat {path:?} failed - {err}"),
- }
- }
- }
- }
- device_stat
- }
- Err(err) => {
- eprintln!("find_mounted_device failed - {err}");
- None
- }
- };
+ let dev = disk_manager
+ .blockdev_stat_for_path(path)
+ .inspect_err(|err| error!("could not read blockdev stats: {err:#}"))
+ .ok();

- DiskStat {
- name: name.to_string(),
- usage,
- dev,
- }
+ DiskStat { name, usage, dev }
}
--
2.47.3