diff options
author | Alex <alex@adnab.me> | 2023-09-11 17:29:23 +0000 |
---|---|---|
committer | Alex <alex@adnab.me> | 2023-09-11 17:29:23 +0000 |
commit | 2548a247f22a6404a2f447e9f9c47fe18e10f67a (patch) | |
tree | 79d2d2836aea81c42e04331cec05af333205dd6f /src | |
parent | fc635f7072e1def6e45123cd3abc4d267b555fc3 (diff) | |
parent | d5bb50d738a5ac9a56ed137263b520b2d4135c29 (diff) | |
download | garage-2548a247f22a6404a2f447e9f9c47fe18e10f67a.tar.gz garage-2548a247f22a6404a2f447e9f9c47fe18e10f67a.zip |
Merge pull request 'use statvfs instead of mount list to determine free data/meta space (fix #611)' (#631) from fix-free-space into main
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/631
Diffstat (limited to 'src')
-rw-r--r-- | src/rpc/Cargo.toml | 2 | ||||
-rw-r--r-- | src/rpc/system.rs | 17 |
2 files changed, 9 insertions, 10 deletions
diff --git a/src/rpc/Cargo.toml b/src/rpc/Cargo.toml index 66004bb9..0cda723e 100644 --- a/src/rpc/Cargo.toml +++ b/src/rpc/Cargo.toml @@ -24,7 +24,7 @@ hex = "0.4" tracing = "0.1" rand = "0.8" sodiumoxide = { version = "0.2.5-0", package = "kuska-sodiumoxide" } -systemstat = "0.2.3" +nix = { version = "0.27", default-features = false, features = ["fs"] } async-trait = "0.1.7" serde = { version = "1.0", default-features = false, features = ["derive", "rc"] } diff --git a/src/rpc/system.rs b/src/rpc/system.rs index b42e49fc..72ce8de9 100644 --- a/src/rpc/system.rs +++ b/src/rpc/system.rs @@ -891,15 +891,14 @@ impl NodeStatus { } fn update_disk_usage(&mut self, meta_dir: &Path, data_dir: &Path, metrics: &SystemMetrics) { - use systemstat::{Platform, System}; - let mounts = System::new().mounts().unwrap_or_default(); - - let mount_avail = |path: &Path| { - mounts - .iter() - .filter(|x| path.starts_with(&x.fs_mounted_on)) - .max_by_key(|x| x.fs_mounted_on.len()) - .map(|x| (x.avail.as_u64(), x.total.as_u64())) + use nix::sys::statvfs::statvfs; + let mount_avail = |path: &Path| match statvfs(path) { + Ok(x) => { + let avail = x.blocks_available() * x.fragment_size(); + let total = x.blocks() * x.fragment_size(); + Some((avail, total)) + } + Err(_) => None, }; self.meta_disk_avail = mount_avail(meta_dir); |