Skip to content

Commit

Permalink
Reserve space for crypt metadata on data tier for online reencryption…
Browse files Browse the repository at this point in the history
… in the future
  • Loading branch information
jbaublitz committed Oct 26, 2023
1 parent 10efda8 commit 21a4768
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/engine/strat_engine/backstore/backstore/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -388,12 +385,15 @@ impl Backstore {
let mut data_tier = DataTier::<StratBlockDev>::new(
BlockDevMgr::<StratBlockDev>::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,
Expand All @@ -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()
},
})
}

Expand Down

0 comments on commit 21a4768

Please sign in to comment.