From 21a47684dbe05f8c7f72039f826930785bf322b0 Mon Sep 17 00:00:00 2001 From: John Baublitz Date: Tue, 17 Oct 2023 10:57:52 -0400 Subject: [PATCH] Reserve space for crypt metadata on data tier for online reencryption in the future --- .../strat_engine/backstore/backstore/v2.rs | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/engine/strat_engine/backstore/backstore/v2.rs b/src/engine/strat_engine/backstore/backstore/v2.rs index 47f0d310205..45482f878c6 100644 --- a/src/engine/strat_engine/backstore/backstore/v2.rs +++ b/src/engine/strat_engine/backstore/backstore/v2.rs @@ -166,17 +166,14 @@ impl InternalBackstore for Backstore { } fn datatier_usable_size(&self) -> Sectors { - self.data_tier.usable_size() - - if self.encryption_info.is_some() { - crypt_metadata_size().sectors() - } else { - Sectors(0) - } + self.data_tier.usable_size() - crypt_metadata_size().sectors() } fn available_in_backstore(&self) -> Sectors { self.data_tier.usable_size() - self.next + // This subtraction needs to be maintained because for encrypted devices, next is 0 + // while it is set to after the crypt metadata size for unencrypted devices. - if self.encryption_info.is_some() { crypt_metadata_size().sectors() } else { @@ -388,12 +385,15 @@ impl Backstore { let mut data_tier = DataTier::::new( BlockDevMgr::::initialize(pool_uuid, devices, mda_data_size)?, ); - if encryption_info.is_some() { - let request = data_tier.alloc_request(&[crypt_metadata_size().sectors()])?.ok_or_else(|| { - StratisError::Msg("There was not enough space on the device to satisfy the allocation request".to_string()) + let request = data_tier + .alloc_request(&[crypt_metadata_size().sectors()])? + .ok_or_else(|| { + StratisError::Msg( + "There was not enough space on the device to satisfy the allocation request" + .to_string(), + ) })?; - data_tier.alloc_commit(request)?; - } + data_tier.alloc_commit(request)?; Ok(Backstore { data_tier, @@ -403,7 +403,11 @@ impl Backstore { cap_linear: None, handle: None, encryption_info: encryption_info.cloned(), - next: Sectors(0), + next: if encryption_info.is_some() { + Sectors(0) + } else { + crypt_metadata_size().sectors() + }, }) }