diff --git a/src/engine/strat_engine/backstore/backstore/v2.rs b/src/engine/strat_engine/backstore/backstore/v2.rs index 3249ddfacc..3dc00489c8 100644 --- a/src/engine/strat_engine/backstore/backstore/v2.rs +++ b/src/engine/strat_engine/backstore/backstore/v2.rs @@ -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( @@ -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 { let mut all_allocs = if self.allocs.is_empty() { @@ -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) diff --git a/src/engine/strat_engine/pool/v2.rs b/src/engine/strat_engine/pool/v2.rs index 2a45991d76..107581ea4b 100644 --- a/src/engine/strat_engine/pool/v2.rs +++ b/src/engine/strat_engine/pool/v2.rs @@ -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, @@ -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, @@ -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(), diff --git a/src/engine/strat_engine/thinpool/thinpool.rs b/src/engine/strat_engine/thinpool/thinpool.rs index 74f25af1e7..5c380d6dad 100644 --- a/src/engine/strat_engine/thinpool/thinpool.rs +++ b/src/engine/strat_engine/thinpool/thinpool.rs @@ -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()