Skip to content

Commit

Permalink
Use IntegritySpec struct to manage spec
Browse files Browse the repository at this point in the history
Combine both current specs in the struct.

The default of both fields is None.

Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Dec 20, 2024
1 parent e3c98b3 commit bf85af1
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 101 deletions.
5 changes: 2 additions & 3 deletions src/dbus_api/api/manager_3_0/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
util::{engine_to_dbus_err_tuple, get_next_arg, tuple_to_option},
},
engine::{
CreateAction, DeleteAction, EncryptionInfo, EngineAction, KeyDescription,
CreateAction, DeleteAction, EncryptionInfo, EngineAction, IntegritySpec, KeyDescription,
MappingCreateAction, MappingDeleteAction, PoolIdentifier, PoolUuid, SetUnlockAction,
UnlockMethod,
},
Expand Down Expand Up @@ -328,8 +328,7 @@ pub fn create_pool(m: &MethodInfo<'_, MTSync<TData>, TData>) -> MethodResult {
name,
&devs.map(Path::new).collect::<Vec<&Path>>(),
EncryptionInfo::from_options((key_desc, clevis_info)).as_ref(),
None,
None,
IntegritySpec::default(),
)));
match create_result {
Ok(pool_uuid_action) => match pool_uuid_action {
Expand Down
5 changes: 2 additions & 3 deletions src/dbus_api/api/manager_3_5/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
types::{DbusErrorEnum, TData, OK_STRING},
util::{engine_to_dbus_err_tuple, get_next_arg, tuple_to_option},
},
engine::{CreateAction, EncryptionInfo, KeyDescription, PoolIdentifier},
engine::{CreateAction, EncryptionInfo, IntegritySpec, KeyDescription, PoolIdentifier},
stratis::StratisError,
};

Expand Down Expand Up @@ -65,8 +65,7 @@ pub fn create_pool(m: &MethodInfo<'_, MTSync<TData>, TData>) -> MethodResult {
name,
&devs.map(Path::new).collect::<Vec<&Path>>(),
EncryptionInfo::from_options((key_desc, clevis_info)).as_ref(),
None,
None,
IntegritySpec::default(),
)));
match create_result {
Ok(pool_uuid_action) => match pool_uuid_action {
Expand Down
10 changes: 6 additions & 4 deletions src/dbus_api/api/manager_3_8/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use crate::{
util::{engine_to_dbus_err_tuple, get_next_arg, tuple_to_option},
},
engine::{
CreateAction, EncryptionInfo, IntegrityTagSpec, KeyDescription, Name, PoolIdentifier,
PoolUuid, StartAction, UnlockMethod,
CreateAction, EncryptionInfo, IntegritySpec, IntegrityTagSpec, KeyDescription, Name,
PoolIdentifier, PoolUuid, StartAction, UnlockMethod,
},
stratis::StratisError,
};
Expand Down Expand Up @@ -206,8 +206,10 @@ pub fn create_pool(m: &MethodInfo<'_, MTSync<TData>, TData>) -> MethodResult {
name,
&devs.map(Path::new).collect::<Vec<&Path>>(),
EncryptionInfo::from_options((key_desc, clevis_info)).as_ref(),
journal_size,
tag_spec,
IntegritySpec {
journal_size,
tag_spec
},
)));
match create_result {
Ok(pool_uuid_action) => match pool_uuid_action {
Expand Down
5 changes: 2 additions & 3 deletions src/engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
structures::{AllLockReadGuard, AllLockWriteGuard, SomeLockReadGuard, SomeLockWriteGuard},
types::{
ActionAvailability, BlockDevTier, Clevis, CreateAction, DeleteAction, DevUuid,
EncryptionInfo, FilesystemUuid, GrowAction, IntegrityTagSpec, Key, KeyDescription,
EncryptionInfo, FilesystemUuid, GrowAction, IntegritySpec, Key, KeyDescription,
LockedPoolsInfo, MappingCreateAction, MappingDeleteAction, Name, PoolDiff,
PoolEncryptionInfo, PoolIdentifier, PoolUuid, RegenAction, RenameAction, ReportType,
SetCreateAction, SetDeleteAction, SetUnlockAction, StartAction, StopAction,
Expand Down Expand Up @@ -382,8 +382,7 @@ pub trait Engine: Debug + Report + Send + Sync {
name: &str,
blockdev_paths: &[&Path],
encryption_info: Option<&EncryptionInfo>,
journal_size: Option<Bytes>,
tag_spec: Option<IntegrityTagSpec>,
integrity_spec: IntegritySpec,
) -> StratisResult<CreateAction<PoolUuid>>;

/// Handle a libudev event.
Expand Down
8 changes: 4 additions & 4 deletions src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ pub use self::{
structures::{AllLockReadGuard, ExclusiveGuard, SharedGuard, Table},
types::{
ActionAvailability, BlockDevTier, ClevisInfo, CreateAction, DeleteAction, DevUuid, Diff,
EncryptionInfo, EngineAction, FilesystemUuid, GrowAction, IntegrityTagSpec, KeyDescription,
Lockable, LockedPoolInfo, LockedPoolsInfo, MappingCreateAction, MappingDeleteAction,
MaybeInconsistent, Name, PoolDiff, PoolEncryptionInfo, PoolIdentifier, PoolUuid,
PropChangeAction, RenameAction, ReportType, SetCreateAction, SetDeleteAction,
EncryptionInfo, EngineAction, FilesystemUuid, GrowAction, IntegritySpec, IntegrityTagSpec,
KeyDescription, Lockable, LockedPoolInfo, LockedPoolsInfo, MappingCreateAction,
MappingDeleteAction, MaybeInconsistent, Name, PoolDiff, PoolEncryptionInfo, PoolIdentifier,
PoolUuid, PropChangeAction, RenameAction, ReportType, SetCreateAction, SetDeleteAction,
SetUnlockAction, StartAction, StopAction, StoppedPoolInfo, StoppedPoolsInfo,
StratBlockDevDiff, StratFilesystemDiff, StratPoolDiff, StratSigblockVersion, StratisUuid,
ThinPoolDiff, ToDisplay, UdevEngineEvent, UnlockMethod,
Expand Down
95 changes: 52 additions & 43 deletions src/engine/sim_engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ use futures::executor::block_on;
use serde_json::{json, Value};
use tokio::sync::RwLock;

use devicemapper::Bytes;

use crate::{
engine::{
engine::{Engine, HandleEvents, KeyActions, Pool, Report},
Expand All @@ -27,9 +25,9 @@ use crate::{
},
types::{
CreateAction, DeleteAction, DevUuid, EncryptionInfo, Features, FilesystemUuid,
IntegrityTagSpec, LockedPoolsInfo, Name, PoolDevice, PoolDiff, PoolIdentifier,
PoolUuid, RenameAction, ReportType, SetUnlockAction, StartAction, StopAction,
StoppedPoolInfo, StoppedPoolsInfo, StratFilesystemDiff, UdevEngineEvent, UnlockMethod,
IntegritySpec, LockedPoolsInfo, Name, PoolDevice, PoolDiff, PoolIdentifier, PoolUuid,
RenameAction, ReportType, SetUnlockAction, StartAction, StopAction, StoppedPoolInfo,
StoppedPoolsInfo, StratFilesystemDiff, UdevEngineEvent, UnlockMethod,
},
StratSigblockVersion,
},
Expand Down Expand Up @@ -131,8 +129,7 @@ impl Engine for SimEngine {
name: &str,
blockdev_paths: &[&Path],
encryption_info: Option<&EncryptionInfo>,
_: Option<Bytes>,
_: Option<IntegrityTagSpec>,
_: IntegritySpec,
) -> StratisResult<CreateAction<PoolUuid>> {
validate_name(name)?;
let name = Name::new(name.to_owned());
Expand Down Expand Up @@ -444,8 +441,7 @@ mod tests {
"name",
strs_to_paths!(["/dev/one", "/dev/two", "/dev/three"]),
None,
None,
None
IntegritySpec::default(),
))
.unwrap()
.changed()
Expand All @@ -457,11 +453,15 @@ mod tests {
/// Destroying a pool with devices should succeed
fn destroy_pool_w_devices() {
let engine = SimEngine::default();
let uuid =
test_async!(engine.create_pool("name", strs_to_paths!(["/s/d"]), None, None, None))
.unwrap()
.changed()
.unwrap();
let uuid = test_async!(engine.create_pool(
"name",
strs_to_paths!(["/s/d"]),
None,
IntegritySpec::default()
))
.unwrap()
.changed()
.unwrap();
assert!(test_async!(engine.destroy_pool(uuid)).is_ok());
}

Expand All @@ -470,11 +470,15 @@ mod tests {
fn destroy_pool_w_filesystem() {
let engine = SimEngine::default();
let pool_name = "pool_name";
let uuid =
test_async!(engine.create_pool(pool_name, strs_to_paths!(["/s/d"]), None, None, None))
.unwrap()
.changed()
.unwrap();
let uuid = test_async!(engine.create_pool(
pool_name,
strs_to_paths!(["/s/d"]),
None,
IntegritySpec::default()
))
.unwrap()
.changed()
.unwrap();
{
let mut pool = test_async!(engine.get_mut_pool(PoolIdentifier::Uuid(uuid))).unwrap();
pool.create_filesystems(pool_name, uuid, &[("test", None, None)])
Expand All @@ -490,9 +494,9 @@ mod tests {
let name = "name";
let engine = SimEngine::default();
let devices = strs_to_paths!(["/s/d"]);
test_async!(engine.create_pool(name, devices, None, None, None)).unwrap();
test_async!(engine.create_pool(name, devices, None, IntegritySpec::default())).unwrap();
assert_matches!(
test_async!(engine.create_pool(name, devices, None, None, None)),
test_async!(engine.create_pool(name, devices, None, IntegritySpec::default())),
Ok(CreateAction::Identity)
);
}
Expand All @@ -502,13 +506,18 @@ mod tests {
fn create_pool_name_collision_different_args() {
let name = "name";
let engine = SimEngine::default();
test_async!(engine.create_pool(name, strs_to_paths!(["/s/d"]), None, None, None)).unwrap();
test_async!(engine.create_pool(
name,
strs_to_paths!(["/s/d"]),
None,
IntegritySpec::default()
))
.unwrap();
assert!(test_async!(engine.create_pool(
name,
strs_to_paths!(["/dev/one", "/dev/two", "/dev/three"]),
None,
None,
None,
IntegritySpec::default(),
))
.is_err());
}
Expand All @@ -519,15 +528,20 @@ mod tests {
let path = "/s/d";
let engine = SimEngine::default();
assert_matches!(
test_async!(engine.create_pool("name", strs_to_paths!([path, path]), None, None, None))
.unwrap()
.changed()
.map(
|uuid| test_async!(engine.get_pool(PoolIdentifier::Uuid(uuid)))
.unwrap()
.blockdevs()
.len()
),
test_async!(engine.create_pool(
"name",
strs_to_paths!([path, path]),
None,
IntegritySpec::default()
))
.unwrap()
.changed()
.map(
|uuid| test_async!(engine.get_pool(PoolIdentifier::Uuid(uuid)))
.unwrap()
.blockdevs()
.len()
),
Some(1)
);
}
Expand All @@ -551,8 +565,7 @@ mod tests {
name,
strs_to_paths!(["/dev/one", "/dev/two", "/dev/three"]),
None,
None,
None,
IntegritySpec::default(),
))
.unwrap()
.changed()
Expand All @@ -571,8 +584,7 @@ mod tests {
"old_name",
strs_to_paths!(["/dev/one", "/dev/two", "/dev/three"]),
None,
None,
None,
IntegritySpec::default(),
))
.unwrap()
.changed()
Expand All @@ -592,8 +604,7 @@ mod tests {
"old_name",
strs_to_paths!(["/dev/one", "/dev/two", "/dev/three"]),
None,
None,
None,
IntegritySpec::default(),
))
.unwrap()
.changed()
Expand All @@ -602,8 +613,7 @@ mod tests {
new_name,
strs_to_paths!(["/dev/four", "/dev/five", "/dev/six"]),
None,
None,
None,
IntegritySpec::default(),
))
.unwrap();
assert!(test_async!(engine.rename_pool(uuid, new_name)).is_err());
Expand All @@ -618,8 +628,7 @@ mod tests {
new_name,
strs_to_paths!(["/dev/one", "/dev/two", "/dev/three"]),
None,
None,
None,
IntegritySpec::default(),
))
.unwrap();
assert_matches!(
Expand Down
Loading

0 comments on commit bf85af1

Please sign in to comment.