From b568bb863dfc4aaa4c4b6fb1a0492c5555f529a0 Mon Sep 17 00:00:00 2001 From: Vedad KAJTAZ Date: Sat, 4 Jan 2025 12:50:10 +0100 Subject: [PATCH 1/3] Fix #907 --- src/rpc/system.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/rpc/system.rs b/src/rpc/system.rs index d94d4eec..1a5677df 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 From 6ca99fd02c1689d34f2b80d6dd632ee54415e391 Mon Sep 17 00:00:00 2001 From: Vedad KAJTAZ Date: Sat, 4 Jan 2025 14:46:42 +0100 Subject: [PATCH 2/3] formatting --- src/rpc/system.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rpc/system.rs b/src/rpc/system.rs index 1a5677df..f4e4b9ea 100644 --- a/src/rpc/system.rs +++ b/src/rpc/system.rs @@ -843,7 +843,7 @@ impl NodeStatus { match mount_avail(&dir.path) { Some((fsid, avail, total)) => { mounts.insert(fsid, (avail, total)); - } + }, None => return None, } @@ -852,9 +852,9 @@ impl NodeStatus { Some(fsid) => match mount_avail(&dir.path) { Some((_, avail, total)) => { mounts.insert(fsid, (avail, total)); - } + }, None => return None, - } + }, None => return None, } } From 6689800986580713b4d04b1e77c1ab0cadae8c18 Mon Sep 17 00:00:00 2001 From: Vedad KAJTAZ Date: Sat, 4 Jan 2025 16:52:23 +0100 Subject: [PATCH 3/3] Formatting with --- src/rpc/system.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpc/system.rs b/src/rpc/system.rs index f4e4b9ea..753d8c8d 100644 --- a/src/rpc/system.rs +++ b/src/rpc/system.rs @@ -843,7 +843,7 @@ impl NodeStatus { match mount_avail(&dir.path) { Some((fsid, avail, total)) => { mounts.insert(fsid, (avail, total)); - }, + } None => return None, } @@ -852,7 +852,7 @@ impl NodeStatus { Some(fsid) => match mount_avail(&dir.path) { Some((_, avail, total)) => { mounts.insert(fsid, (avail, total)); - }, + } None => return None, }, None => return None,