diff --git a/src/engine/strat_engine/pool.rs b/src/engine/strat_engine/pool.rs index 9c2732e441c..ef6495de242 100644 --- a/src/engine/strat_engine/pool.rs +++ b/src/engine/strat_engine/pool.rs @@ -468,13 +468,7 @@ impl StratPool { /// overprovisioning if it is determined to be the end result. fn check_overprov(&self, increase: Sectors) -> StratisResult<()> { if !self.thin_pool.overprov_enabled() - && self - .thin_pool - .filesystems() - .iter() - .map(|(_, _, fs)| fs.thindev_size()) - .sum::() - + increase + && self.thin_pool.filesystem_logical_size_sum()? + increase > self.thin_pool.total_fs_limit(&self.backstore) { Err(StratisError::Msg(format!( diff --git a/src/engine/strat_engine/thinpool/thinpool.rs b/src/engine/strat_engine/thinpool/thinpool.rs index 8b4a27ee6ce..97427d969f4 100644 --- a/src/engine/strat_engine/thinpool/thinpool.rs +++ b/src/engine/strat_engine/thinpool/thinpool.rs @@ -651,11 +651,13 @@ impl ThinPool { } /// Sum the logical size of all filesystems on the pool. - fn filesystem_logical_size_sum(&self) -> Sectors { - self.filesystems + pub fn filesystem_logical_size_sum(&self) -> StratisResult { + Ok(self + .mdv + .filesystems()? .iter() - .map(|(_, _, fs)| fs.thindev_size()) - .sum() + .map(|fssave| fssave.size) + .sum()) } /// Check all filesystems on this thin pool and return which had their sizes @@ -668,12 +670,13 @@ impl ThinPool { ) -> StratisResult> { let mut updated = HashMap::default(); let mut remaining_space = if !self.enable_overprov { + let sum = self.filesystem_logical_size_sum()?; Some(Sectors( room_for_data( backstore.datatier_usable_size(), self.thin_pool.meta_dev().size(), ) - .saturating_sub(*self.filesystem_logical_size_sum()), + .saturating_sub(*sum), )) } else { None @@ -1088,8 +1091,13 @@ impl ThinPool { let meta_growth = Sectors(new_meta_size.saturating_sub(*current_meta_size)); if !self.overprov_enabled() && meta_growth > Sectors(0) { - let total: Sectors = - self.filesystem_logical_size_sum() + INITIAL_MDV_SIZE + 2u64 * current_meta_size; + let sum = match self.filesystem_logical_size_sum() { + Ok(s) => s, + Err(e) => { + return (false, Err(e)); + } + }; + let total: Sectors = sum + INITIAL_MDV_SIZE + 2u64 * current_meta_size; match total.cmp(&backstore.datatier_usable_size()) { Ordering::Less => (), Ordering::Equal => { @@ -1519,7 +1527,13 @@ impl ThinPool { if self.enable_overprov && !enabled { let data_limit = self.total_fs_limit(backstore); - if self.filesystem_logical_size_sum() > data_limit { + let sum = match self.filesystem_logical_size_sum() { + Ok(s) => s, + Err(e) => { + return (false, Err(e)); + } + }; + if sum > data_limit { (false, Err(StratisError::Msg(format!( "Cannot disable overprovisioning on a pool that is already overprovisioned; the sum of the logical sizes of all filesystems and snapshots must be less than the data space available to the thin pool ({data_limit}) to disable overprovisioning" ))))