Skip to content

Commit

Permalink
Check MDV for total filesystem sizes in no overprovisioning case
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaublitz committed Mar 31, 2023
1 parent a24678b commit fae42f0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
8 changes: 1 addition & 7 deletions src/engine/strat_engine/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Sectors>()
+ increase
&& self.thin_pool.filesystem_logical_size_sum()? + increase
> self.thin_pool.total_fs_limit(&self.backstore)
{
Err(StratisError::Msg(format!(
Expand Down
30 changes: 22 additions & 8 deletions src/engine/strat_engine/thinpool/thinpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Sectors> {
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
Expand All @@ -668,12 +670,13 @@ impl ThinPool {
) -> StratisResult<HashMap<FilesystemUuid, StratFilesystemDiff>> {
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
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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"
))))
Expand Down

0 comments on commit fae42f0

Please sign in to comment.