Skip to content

Commit

Permalink
Include crypt metadata in total_physical_used
Browse files Browse the repository at this point in the history
Use newly introduced datatier_crypt_meta_size() method where
appropriate.

Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Aug 27, 2024
1 parent fba286d commit a3e57a1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
30 changes: 20 additions & 10 deletions src/engine/strat_engine/backstore/backstore/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,17 @@ impl InternalBackstore for Backstore {
}

fn datatier_allocated_size(&self) -> Sectors {
self.data_tier.allocated()
self.allocs.iter().map(|(_, length)| *length).sum()
}

fn datatier_usable_size(&self) -> Sectors {
self.data_tier.usable_size() - self.crypt_meta_allocs.iter().map(|(_, len)| *len).sum()
self.data_tier.usable_size() - self.datatier_crypt_meta_size()
}

fn available_in_backstore(&self) -> Sectors {
self.data_tier.usable_size()
- self.allocs.iter().map(|(_, len)| *len).sum()
- self.crypt_meta_allocs.iter().map(|(_, len)| *len).sum()
- self.datatier_allocated_size()
- self.datatier_crypt_meta_size()
}

fn alloc(
Expand Down Expand Up @@ -218,12 +218,6 @@ impl InternalBackstore for Backstore {
}

impl Backstore {
/// Calculate size allocated to data and not metadata in the backstore.
#[cfg(test)]
pub fn data_alloc_size(&self) -> Sectors {
self.allocs.iter().map(|(_, length)| *length).sum()
}

/// Calculate next from all of the metadata and data allocations present in the backstore.
fn calc_next_cache(&self) -> StratisResult<Sectors> {
let mut all_allocs = if self.allocs.is_empty() {
Expand Down Expand Up @@ -858,6 +852,22 @@ impl Backstore {
self.data_tier.metadata_size()
}

/// The space for the crypt meta device is allocated for the data tier,
/// but not directly from the devices of the data tier. Although it is,
/// strictly speaking, metadata, it is not included in the
/// datatier_metadata_size() result, which only includes metadata
/// allocated directly from the data tier.
/// The space is included in the datatier_allocated() result, since it is
/// allocated from the assembled devices of the data tier.
fn datatier_crypt_meta_size(&self) -> Sectors {
self.crypt_meta_allocs.iter().map(|(_, len)| *len).sum()
}

/// Metadata size on the data tier, including crypt metadata space.
pub fn datatier_all_metadata_size(&self) -> Sectors {
self.datatier_crypt_meta_size() + self.datatier_metadata_size()
}

/// Write the given data to the data tier's devices.
pub fn save_state(&mut self, metadata: &[u8]) -> StratisResult<()> {
self.data_tier.save_state(metadata)
Expand Down
6 changes: 3 additions & 3 deletions src/engine/strat_engine/pool/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl StratPool {
}
};

let metadata_size = backstore.datatier_metadata_size();
let metadata_size = backstore.datatier_all_metadata_size();
let mut pool = StratPool {
backstore,
thin_pool: thinpool,
Expand Down Expand Up @@ -267,7 +267,7 @@ impl StratPool {
let mut needs_save = metadata.thinpool_dev.fs_limit.is_none()
|| metadata.thinpool_dev.feature_args.is_none();

let metadata_size = backstore.datatier_metadata_size();
let metadata_size = backstore.datatier_all_metadata_size();
let mut pool = StratPool {
backstore,
thin_pool: thinpool,
Expand Down Expand Up @@ -1249,7 +1249,7 @@ impl<'a> DumpState<'a> for StratPool {
}

fn dump(&mut self, _: Self::DumpInput) -> Self::State {
self.metadata_size = self.backstore.datatier_metadata_size();
self.metadata_size = self.backstore.datatier_all_metadata_size();
StratPoolState {
metadata_size: self.metadata_size.bytes(),
out_of_alloc_space: self.thin_pool.out_of_alloc_space(),
Expand Down
2 changes: 1 addition & 1 deletion src/engine/strat_engine/thinpool/thinpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2977,7 +2977,7 @@ mod tests {
.unwrap()
);
assert_eq!(
backstore.data_alloc_size(),
backstore.datatier_allocated_size(),
pool.thin_pool.data_dev().size()
+ pool.thin_pool.meta_dev().size() * 2u64
+ pool.mdv.device().size()
Expand Down

0 comments on commit a3e57a1

Please sign in to comment.