diff options
author | Alex <lx@deuxfleurs.fr> | 2025-01-04 16:07:40 +0000 |
---|---|---|
committer | Alex <lx@deuxfleurs.fr> | 2025-01-04 16:07:40 +0000 |
commit | 7bbc8fec504cbfff21210a435d36cb2051e031a9 (patch) | |
tree | 00a97eb721117870694411d14019d060ee4b3eb2 | |
parent | d2246baab7d8716f4bf3287ade6f3195fa1a949c (diff) | |
parent | 6689800986580713b4d04b1e77c1ab0cadae8c18 (diff) | |
download | garage-next-v2.tar.gz garage-next-v2.zip |
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/917
-rw-r--r-- | src/rpc/system.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/rpc/system.rs b/src/rpc/system.rs index d94d4eec..753d8c8d 100644 --- a/src/rpc/system.rs +++ b/src/rpc/system.rs @@ -807,6 +807,16 @@ impl NodeStatus { fn update_disk_usage(&mut self, meta_dir: &Path, data_dir: &DataDirEnum) { use nix::sys::statvfs::statvfs; + + // The HashMap used below requires a filesystem identifier from statfs (instead of statvfs) on FreeBSD, as + // FreeBSD's statvfs filesystem identifier is "not meaningful in this implementation" (man 3 statvfs). + + #[cfg(target_os = "freebsd")] + let get_filesystem_id = |path: &Path| match nix::sys::statfs::statfs(path) { + Ok(fs) => Some(fs.filesystem_id()), + Err(_) => None, + }; + let mount_avail = |path: &Path| match statvfs(path) { Ok(x) => { let avail = x.blocks_available() as u64 * x.fragment_size() as u64; @@ -817,6 +827,7 @@ impl NodeStatus { }; self.meta_disk_avail = mount_avail(meta_dir).map(|(_, a, t)| (a, t)); + self.data_disk_avail = match data_dir { DataDirEnum::Single(dir) => mount_avail(dir).map(|(_, a, t)| (a, t)), DataDirEnum::Multiple(dirs) => (|| { @@ -827,12 +838,25 @@ impl NodeStatus { if dir.capacity.is_none() { continue; } + + #[cfg(not(target_os = "freebsd"))] match mount_avail(&dir.path) { Some((fsid, avail, total)) => { mounts.insert(fsid, (avail, total)); } None => return None, } + + #[cfg(target_os = "freebsd")] + match get_filesystem_id(&dir.path) { + Some(fsid) => match mount_avail(&dir.path) { + Some((_, avail, total)) => { + mounts.insert(fsid, (avail, total)); + } + None => return None, + }, + None => return None, + } } Some( mounts |