Skip to content

Commit

Permalink
Add a ValidatedIntegritySpec type
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Dec 19, 2024
1 parent 905d12f commit 3047996
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 74 deletions.
40 changes: 19 additions & 21 deletions src/engine/strat_engine/backstore/backstore/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ use crate::{
writing::wipe_sectors,
},
types::{
ActionAvailability, BlockDevTier, DevUuid, EncryptionInfo, IntegrityTagSpec,
KeyDescription, PoolUuid, SizedKeyMemory, UnlockMethod,
ActionAvailability, BlockDevTier, DevUuid, EncryptionInfo, KeyDescription, PoolUuid,
SizedKeyMemory, UnlockMethod, ValidatedIntegritySpec,
},
},
stratis::{StratisError, StratisResult},
Expand Down Expand Up @@ -437,13 +437,12 @@ impl Backstore {
devices: UnownedDevices,
mda_data_size: MDADataSize,
encryption_info: Option<&EncryptionInfo>,
integrity_journal_size: Option<Sectors>,
integrity_tag_spec: Option<IntegrityTagSpec>,
integrity_spec: ValidatedIntegritySpec,
) -> StratisResult<Backstore> {
let data_tier = DataTier::<StratBlockDev>::new(
BlockDevMgr::<StratBlockDev>::initialize(pool_uuid, devices, mda_data_size)?,
integrity_journal_size,
integrity_tag_spec,
integrity_spec.journal_size(),
integrity_spec.tag_spec(),
);

let mut backstore = Backstore {
Expand Down Expand Up @@ -1172,13 +1171,16 @@ mod tests {

use devicemapper::{CacheDevStatus, DataBlocks, DmOptions, IEC};

use crate::engine::strat_engine::{
backstore::devices::{ProcessedPathInfos, UnownedDevices},
cmd,
crypt::crypt_metadata_size,
metadata::device_identifiers,
ns::{unshare_mount_namespace, MemoryFilesystem},
tests::{crypt, loopbacked, real},
use crate::engine::{
strat_engine::{
backstore::devices::{ProcessedPathInfos, UnownedDevices},
cmd,
crypt::crypt_metadata_size,
metadata::device_identifiers,
ns::{unshare_mount_namespace, MemoryFilesystem},
tests::{crypt, loopbacked, real},
},
types::ValidatedIntegritySpec,
};

use super::*;
Expand Down Expand Up @@ -1255,8 +1257,7 @@ mod tests {
initdatadevs,
MDADataSize::default(),
None,
None,
None,
ValidatedIntegritySpec::default(),
)
.unwrap();

Expand Down Expand Up @@ -1354,8 +1355,7 @@ mod tests {
devices1,
MDADataSize::default(),
None,
None,
None,
ValidatedIntegritySpec::default(),
)
.unwrap();

Expand Down Expand Up @@ -1420,8 +1420,7 @@ mod tests {
"tang".to_string(),
json!({"url": env::var("TANG_URL").expect("TANG_URL env var required"), "stratis:tang:trust_url": true}),
))),
None,
None,
ValidatedIntegritySpec::default(),
)
.unwrap();
backstore.alloc(pool_uuid, &[Sectors(512)]).unwrap();
Expand Down Expand Up @@ -1496,8 +1495,7 @@ mod tests {
json!({"url": env::var("TANG_URL").expect("TANG_URL env var required"), "stratis:tang:trust_url": true}),
),
)),
None,
None,
ValidatedIntegritySpec::default(),
).unwrap();
cmd::udev_settle().unwrap();

Expand Down
17 changes: 4 additions & 13 deletions src/engine/strat_engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use tokio::{
task::{spawn_blocking, JoinHandle},
};

use devicemapper::{Bytes, DmNameBuf};
use devicemapper::DmNameBuf;

use crate::{
engine::{
Expand All @@ -40,7 +40,7 @@ use crate::{
CreateAction, DeleteAction, DevUuid, EncryptionInfo, FilesystemUuid, IntegritySpec,
LockedPoolsInfo, PoolDiff, PoolIdentifier, RenameAction, ReportType, SetUnlockAction,
StartAction, StopAction, StoppedPoolsInfo, StratFilesystemDiff, UdevEngineEvent,
UnlockMethod,
UnlockMethod, ValidatedIntegritySpec,
},
Engine, Name, Pool, PoolUuid, Report,
},
Expand Down Expand Up @@ -499,15 +499,7 @@ impl Engine for StratEngine {
) -> StratisResult<CreateAction<PoolUuid>> {
validate_name(name)?;
let name = Name::new(name.to_owned());
let rounded_journal_size = match integrity_spec.journal_size {
Some(b) => {
if b % 4096u64 != Bytes(0) {
return Err(StratisError::Msg(format!("{b} is not a multiple of 4096")));
}
Some(b.sectors())
}
None => None,
};
let integrity_spec = ValidatedIntegritySpec::try_from(integrity_spec)?;

validate_paths(blockdev_paths)?;

Expand Down Expand Up @@ -569,8 +561,7 @@ impl Engine for StratEngine {
&cloned_name,
unowned_devices,
cloned_enc_info.as_ref(),
rounded_journal_size,
integrity_spec.tag_spec,
integrity_spec,
)
})??;
pools.insert(Name::new(name.to_string()), pool_uuid, AnyPool::V2(pool));
Expand Down
67 changes: 48 additions & 19 deletions src/engine/strat_engine/pool/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ use crate::{
},
types::{
ActionAvailability, BlockDevTier, Clevis, Compare, CreateAction, DeleteAction, DevUuid,
Diff, EncryptionInfo, FilesystemUuid, GrowAction, IntegrityTagSpec, Key,
KeyDescription, Name, PoolDiff, PoolEncryptionInfo, PoolUuid, PropChangeAction,
RegenAction, RenameAction, SetCreateAction, SetDeleteAction, SizedKeyMemory,
StratFilesystemDiff, StratPoolDiff, StratSigblockVersion, UnlockMethod,
Diff, EncryptionInfo, FilesystemUuid, GrowAction, Key, KeyDescription, Name, PoolDiff,
PoolEncryptionInfo, PoolUuid, PropChangeAction, RegenAction, RenameAction,
SetCreateAction, SetDeleteAction, SizedKeyMemory, StratFilesystemDiff, StratPoolDiff,
StratSigblockVersion, UnlockMethod, ValidatedIntegritySpec,
},
},
stratis::{StratisError, StratisResult},
Expand Down Expand Up @@ -153,8 +153,7 @@ impl StratPool {
name: &str,
devices: UnownedDevices,
encryption_info: Option<&EncryptionInfo>,
journal_size: Option<Sectors>,
tag_spec: Option<IntegrityTagSpec>,
integrity_spec: ValidatedIntegritySpec,
) -> StratisResult<(PoolUuid, StratPool)> {
let pool_uuid = PoolUuid::new_v4();

Expand All @@ -166,8 +165,7 @@ impl StratPool {
devices,
MDADataSize::default(),
encryption_info,
journal_size,
tag_spec,
integrity_spec,
)?;

let thinpool = ThinPool::<Backstore>::new(
Expand Down Expand Up @@ -1308,8 +1306,13 @@ mod tests {
stratis_devices.error_on_not_empty().unwrap();

let name = "stratis-test-pool";
let (uuid, mut pool) =
StratPool::initialize(name, unowned_devices2, None, None, None).unwrap();
let (uuid, mut pool) = StratPool::initialize(
name,
unowned_devices2,
None,
ValidatedIntegritySpec::default(),
)
.unwrap();
invariant(&pool, name);

let metadata1 = pool.record(name);
Expand Down Expand Up @@ -1397,8 +1400,13 @@ mod tests {
stratis_devices.error_on_not_empty().unwrap();

let name = "stratis-test-pool";
let (uuid, mut pool) =
StratPool::initialize(name, unowned_devices, None, None, None).unwrap();
let (uuid, mut pool) = StratPool::initialize(
name,
unowned_devices,
None,
ValidatedIntegritySpec::default(),
)
.unwrap();
invariant(&pool, name);

pool.init_cache(uuid, name, cache_path, true).unwrap();
Expand Down Expand Up @@ -1438,8 +1446,13 @@ mod tests {
stratis_devices.error_on_not_empty().unwrap();

let name = "stratis-test-pool";
let (pool_uuid, mut pool) =
StratPool::initialize(name, unowned_devices1, None, None, None).unwrap();
let (pool_uuid, mut pool) = StratPool::initialize(
name,
unowned_devices1,
None,
ValidatedIntegritySpec::default(),
)
.unwrap();
invariant(&pool, name);

let fs_name = "stratis_test_filesystem";
Expand Down Expand Up @@ -1523,8 +1536,13 @@ mod tests {
let (stratis_devices, unowned_devices) = devices.unpack();
stratis_devices.error_on_not_empty().unwrap();

let (uuid, mut pool) =
StratPool::initialize(name, unowned_devices, None, None, None).unwrap();
let (uuid, mut pool) = StratPool::initialize(
name,
unowned_devices,
None,
ValidatedIntegritySpec::default(),
)
.unwrap();
invariant(&pool, name);

assert_eq!(pool.action_avail, ActionAvailability::Full);
Expand All @@ -1540,7 +1558,13 @@ mod tests {
let (stratis_devices, unowned_devices) = devices.unpack();
stratis_devices.error_on_not_empty().unwrap();

let (_, mut pool) = StratPool::initialize(name, unowned_devices, None, None, None).unwrap();
let (_, mut pool) = StratPool::initialize(
name,
unowned_devices,
None,
ValidatedIntegritySpec::default(),
)
.unwrap();
invariant(&pool, name);

assert_eq!(pool.action_avail, ActionAvailability::Full);
Expand Down Expand Up @@ -1579,8 +1603,13 @@ mod tests {
let (stratis_devices, unowned_devices) = devices.unpack();
stratis_devices.error_on_not_empty().unwrap();

let (pool_uuid, mut pool) =
StratPool::initialize(pool_name, unowned_devices, None, None, None).unwrap();
let (pool_uuid, mut pool) = StratPool::initialize(
pool_name,
unowned_devices,
None,
ValidatedIntegritySpec::default(),
)
.unwrap();

let (_, fs_uuid, _) = pool
.create_filesystems(
Expand Down
31 changes: 11 additions & 20 deletions src/engine/strat_engine/thinpool/thinpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2112,6 +2112,7 @@ mod tests {
tests::{loopbacked, real},
writing::SyncAll,
},
types::ValidatedIntegritySpec,
};

use super::*;
Expand Down Expand Up @@ -3157,8 +3158,7 @@ mod tests {
devices,
MDADataSize::default(),
None,
None,
None,
ValidatedIntegritySpec::default(),
)
.unwrap();
let size = ThinPoolSizeParams::new(backstore.datatier_usable_size()).unwrap();
Expand Down Expand Up @@ -3261,8 +3261,7 @@ mod tests {
first_devices,
MDADataSize::default(),
None,
None,
None,
ValidatedIntegritySpec::default(),
)
.unwrap();
let mut pool = ThinPool::<backstore::v2::Backstore>::new(
Expand Down Expand Up @@ -3398,8 +3397,7 @@ mod tests {
devices,
MDADataSize::default(),
None,
None,
None,
ValidatedIntegritySpec::default(),
)
.unwrap();
warn!("Available: {}", backstore.available_in_backstore());
Expand Down Expand Up @@ -3525,8 +3523,7 @@ mod tests {
devices,
MDADataSize::default(),
None,
None,
None,
ValidatedIntegritySpec::default(),
)
.unwrap();
let mut pool = ThinPool::<backstore::v2::Backstore>::new(
Expand Down Expand Up @@ -3596,8 +3593,7 @@ mod tests {
devices,
MDADataSize::default(),
None,
None,
None,
ValidatedIntegritySpec::default(),
)
.unwrap();
let mut pool = ThinPool::<backstore::v2::Backstore>::new(
Expand Down Expand Up @@ -3677,8 +3673,7 @@ mod tests {
devices,
MDADataSize::default(),
None,
None,
None,
ValidatedIntegritySpec::default(),
)
.unwrap();
let mut pool = ThinPool::<backstore::v2::Backstore>::new(
Expand Down Expand Up @@ -3745,8 +3740,7 @@ mod tests {
devices,
MDADataSize::default(),
None,
None,
None,
ValidatedIntegritySpec::default(),
)
.unwrap();
let mut pool = ThinPool::<backstore::v2::Backstore>::new(
Expand Down Expand Up @@ -3808,8 +3802,7 @@ mod tests {
devices,
MDADataSize::default(),
None,
None,
None,
ValidatedIntegritySpec::default(),
)
.unwrap();
let mut pool = ThinPool::<backstore::v2::Backstore>::new(
Expand Down Expand Up @@ -3916,8 +3909,7 @@ mod tests {
devices,
MDADataSize::default(),
None,
None,
None,
ValidatedIntegritySpec::default(),
)
.unwrap();
let mut pool = ThinPool::<backstore::v2::Backstore>::new(
Expand Down Expand Up @@ -4056,8 +4048,7 @@ mod tests {
devices,
MDADataSize::default(),
None,
None,
None,
ValidatedIntegritySpec::default(),
)
.unwrap();
let mut pool = ThinPool::<backstore::v2::Backstore>::new(
Expand Down
Loading

0 comments on commit 3047996

Please sign in to comment.