Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Torndown filesystem guard #3300

Merged
merged 2 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions src/engine/strat_engine/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,13 +454,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
45 changes: 36 additions & 9 deletions src/engine/strat_engine/thinpool/thinpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use std::{
cmp::{max, min, Ordering},
collections::HashMap,
collections::{HashMap, HashSet},
fmt,
thread::scope,
};
Expand Down 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 @@ -1073,8 +1076,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 @@ -1166,6 +1174,19 @@ impl ThinPool {
name: &str,
size: Sectors,
) -> StratisResult<FilesystemUuid> {
if self
.mdv
.filesystems()?
.into_iter()
.map(|fssave| fssave.name)
.collect::<HashSet<_>>()
.contains(name)
{
return Err(StratisError::Msg(format!(
"Pool {pool_name} already has a record of filesystem name {name}"
)));
}

let (fs_uuid, mut new_filesystem) =
StratFilesystem::initialize(pool_uuid, &self.thin_pool, size, self.id_gen.new_id()?)?;
let name = Name::new(name.to_owned());
Expand Down Expand Up @@ -1491,7 +1512,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