multi-hdd support (fix #218) #625

Merged
lx merged 26 commits from multihdd into next 2023-09-11 10:52:02 +00:00
Showing only changes of commit 2f112ac682 - Show all commits

View file

@ -911,12 +911,30 @@ impl NodeStatus {
self.data_disk_avail = match data_dir { self.data_disk_avail = match data_dir {
DataDirEnum::Single(dir) => mount_avail(dir), DataDirEnum::Single(dir) => mount_avail(dir),
DataDirEnum::Multiple(dirs) => { DataDirEnum::Multiple(dirs) => {
dirs.iter() // Take mounts corresponding to all specified data directories that
.map(|d| mount_avail(&d.path)) // can be used for writing data
.fold(Some((0, 0)), |acc, cur| match (acc, cur) { let mounts = dirs
(Some((x, y)), Some((a, b))) => Some((x + a, y + b)), .iter()
_ => None, .filter(|dir| dir.capacity.is_some())
.map(|dir| {
mounts
.iter()
.filter(|mnt| dir.path.starts_with(&mnt.fs_mounted_on))
.max_by_key(|mnt| mnt.fs_mounted_on.len())
}) })
.collect::<Vec<_>>();
if mounts.iter().any(|x| x.is_none()) {
None // could not get info for at least one mount
} else {
// dedup mounts in case several data directories are on the same filesystem
let mut mounts = mounts.iter().map(|x| x.unwrap()).collect::<Vec<_>>();
mounts.sort_by(|x, y| x.fs_mounted_on.cmp(&y.fs_mounted_on));
mounts.dedup_by(|x, y| x.fs_mounted_on == y.fs_mounted_on);
// calculate sum of available and total space
Some(mounts.iter().fold((0, 0), |(x, y), mnt| {
(x + mnt.avail.as_u64(), y + mnt.total.as_u64())
}))
}
} }
}; };