Skip to content

Commit

Permalink
Make D-Bus signature for integrity tag spec a string
Browse files Browse the repository at this point in the history
Define an enum to represent the tag size.

At present it should have the default which is 512 bits.

It should also allow 0, which the user can specify to avoid
pre-allocating for integrity.

Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Dec 16, 2024
1 parent 2cb14ae commit 0a7d047
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 33 deletions.
9 changes: 5 additions & 4 deletions src/dbus_api/api/manager_3_8/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ pub fn create_pool_method(f: &Factory<MTSync<TData>, TData>) -> Method<MTSync<TD
//
// Rust representation: (bool, u64)
.in_arg(("journal_size", "(bt)"))
// Optional tag size for integrity metadata reservation.
// Optional tag size or specification for integrity metadata
// reservation.
// b: true if the size should be specified.
// false if the default should be used.
// q: Integer representing tag size in bits.
// q: Tag size specification.
//
// Rust representation: (bool, u16)
.in_arg(("tag_size", "(bq)"))
// Rust representation: (bool, String)
.in_arg(("tag_size_spec", "(bs)"))
// In order from left to right:
// b: true if a pool was created and object paths were returned
// o: Object path for Pool
Expand Down
17 changes: 13 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, KeyDescription, Name, PoolIdentifier, PoolUuid, StartAction,
UnlockMethod,
CreateAction, EncryptionInfo, IntegrityTagSpec, KeyDescription, Name, PoolIdentifier,
PoolUuid, StartAction, UnlockMethod,
},
stratis::StratisError,
};
Expand Down Expand Up @@ -158,7 +158,7 @@ pub fn create_pool(m: &MethodInfo<'_, MTSync<TData>, TData>) -> MethodResult {
Some(get_next_arg(&mut iter, 3)?),
);
let journal_size_tuple: (bool, u64) = get_next_arg(&mut iter, 4)?;
let tag_size_tuple: (bool, u16) = get_next_arg(&mut iter, 5)?;
let tag_size_tuple: (bool, String) = get_next_arg(&mut iter, 5)?;

let return_message = message.method_return();

Expand Down Expand Up @@ -188,7 +188,16 @@ pub fn create_pool(m: &MethodInfo<'_, MTSync<TData>, TData>) -> MethodResult {
};

let journal_size = tuple_to_option(journal_size_tuple).map(Bytes::from);
let tag_size = tuple_to_option(tag_size_tuple);
let tag_size = match tuple_to_option(tag_size_tuple)
.map(|s| IntegrityTagSpec::try_from(s.as_str()))
.transpose()
{
Ok(s) => s,
Err(e) => {
let (rc, rs) = engine_to_dbus_err_tuple(&e);
return Ok(vec![return_message.append3(default_return, rc, rs)]);
}
};

let dbus_context = m.tree.get_data();
let create_result = handle_action!(block_on(dbus_context.engine.create_pool(
Expand Down
13 changes: 7 additions & 6 deletions src/engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ use crate::{
structures::{AllLockReadGuard, AllLockWriteGuard, SomeLockReadGuard, SomeLockWriteGuard},
types::{
ActionAvailability, BlockDevTier, Clevis, CreateAction, DeleteAction, DevUuid,
EncryptionInfo, FilesystemUuid, GrowAction, Key, KeyDescription, LockedPoolsInfo,
MappingCreateAction, MappingDeleteAction, Name, PoolDiff, PoolEncryptionInfo,
PoolIdentifier, PoolUuid, RegenAction, RenameAction, ReportType, SetCreateAction,
SetDeleteAction, SetUnlockAction, StartAction, StopAction, StoppedPoolsInfo,
StratFilesystemDiff, StratSigblockVersion, UdevEngineEvent, UnlockMethod,
EncryptionInfo, FilesystemUuid, GrowAction, IntegrityTagSpec, Key, KeyDescription,
LockedPoolsInfo, MappingCreateAction, MappingDeleteAction, Name, PoolDiff,
PoolEncryptionInfo, PoolIdentifier, PoolUuid, RegenAction, RenameAction, ReportType,
SetCreateAction, SetDeleteAction, SetUnlockAction, StartAction, StopAction,
StoppedPoolsInfo, StratFilesystemDiff, StratSigblockVersion, UdevEngineEvent,
UnlockMethod,
},
},
stratis::StratisResult,
Expand Down Expand Up @@ -382,7 +383,7 @@ pub trait Engine: Debug + Report + Send + Sync {
blockdev_paths: &[&Path],
encryption_info: Option<&EncryptionInfo>,
journal_size: Option<Bytes>,
tag_size: Option<u16>,
tag_size: Option<IntegrityTagSpec>,
) -> StratisResult<CreateAction<PoolUuid>>;

/// Handle a libudev event.
Expand Down
4 changes: 2 additions & 2 deletions src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ pub use self::{
structures::{AllLockReadGuard, ExclusiveGuard, SharedGuard, Table},
types::{
ActionAvailability, BlockDevTier, ClevisInfo, CreateAction, DeleteAction, DevUuid, Diff,
EncryptionInfo, EngineAction, FilesystemUuid, GrowAction, KeyDescription, Lockable,
LockedPoolInfo, LockedPoolsInfo, MappingCreateAction, MappingDeleteAction,
EncryptionInfo, EngineAction, FilesystemUuid, GrowAction, IntegrityTagSpec, KeyDescription,
Lockable, LockedPoolInfo, LockedPoolsInfo, MappingCreateAction, MappingDeleteAction,
MaybeInconsistent, Name, PoolDiff, PoolEncryptionInfo, PoolIdentifier, PoolUuid,
PropChangeAction, RenameAction, ReportType, SetCreateAction, SetDeleteAction,
SetUnlockAction, StartAction, StopAction, StoppedPoolInfo, StoppedPoolsInfo,
Expand Down
8 changes: 4 additions & 4 deletions src/engine/sim_engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ use crate::{
},
types::{
CreateAction, DeleteAction, DevUuid, EncryptionInfo, Features, FilesystemUuid,
LockedPoolsInfo, Name, PoolDevice, PoolDiff, PoolIdentifier, PoolUuid, RenameAction,
ReportType, SetUnlockAction, StartAction, StopAction, StoppedPoolInfo,
StoppedPoolsInfo, StratFilesystemDiff, UdevEngineEvent, UnlockMethod,
IntegrityTagSpec, LockedPoolsInfo, Name, PoolDevice, PoolDiff, PoolIdentifier,
PoolUuid, RenameAction, ReportType, SetUnlockAction, StartAction, StopAction,
StoppedPoolInfo, StoppedPoolsInfo, StratFilesystemDiff, UdevEngineEvent, UnlockMethod,
},
StratSigblockVersion,
},
Expand Down Expand Up @@ -132,7 +132,7 @@ impl Engine for SimEngine {
blockdev_paths: &[&Path],
encryption_info: Option<&EncryptionInfo>,
_: Option<Bytes>,
_: Option<u16>,
_: Option<IntegrityTagSpec>,
) -> StratisResult<CreateAction<PoolUuid>> {
validate_name(name)?;
let name = Name::new(name.to_owned());
Expand Down
8 changes: 4 additions & 4 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, KeyDescription, PoolUuid,
SizedKeyMemory, UnlockMethod,
ActionAvailability, BlockDevTier, DevUuid, EncryptionInfo, IntegrityTagSpec,
KeyDescription, PoolUuid, SizedKeyMemory, UnlockMethod,
},
},
stratis::{StratisError, StratisResult},
Expand Down Expand Up @@ -438,12 +438,12 @@ impl Backstore {
mda_data_size: MDADataSize,
encryption_info: Option<&EncryptionInfo>,
integrity_journal_size: Option<Sectors>,
integrity_tag_size: Option<u16>,
integrity_tag_size: Option<IntegrityTagSpec>,
) -> StratisResult<Backstore> {
let data_tier = DataTier::<StratBlockDev>::new(
BlockDevMgr::<StratBlockDev>::initialize(pool_uuid, devices, mda_data_size)?,
integrity_journal_size,
integrity_tag_size,
integrity_tag_size.map(|v| v.as_bits()),
);

let mut backstore = Backstore {
Expand Down
9 changes: 5 additions & 4 deletions src/engine/strat_engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ use crate::{
SomeLockWriteGuard, Table,
},
types::{
CreateAction, DeleteAction, DevUuid, EncryptionInfo, FilesystemUuid, LockedPoolsInfo,
PoolDiff, PoolIdentifier, RenameAction, ReportType, SetUnlockAction, StartAction,
StopAction, StoppedPoolsInfo, StratFilesystemDiff, UdevEngineEvent, UnlockMethod,
CreateAction, DeleteAction, DevUuid, EncryptionInfo, FilesystemUuid, IntegrityTagSpec,
LockedPoolsInfo, PoolDiff, PoolIdentifier, RenameAction, ReportType, SetUnlockAction,
StartAction, StopAction, StoppedPoolsInfo, StratFilesystemDiff, UdevEngineEvent,
UnlockMethod,
},
Engine, Name, Pool, PoolUuid, Report,
},
Expand Down Expand Up @@ -495,7 +496,7 @@ impl Engine for StratEngine {
blockdev_paths: &[&Path],
encryption_info: Option<&EncryptionInfo>,
journal_size: Option<Bytes>,
tag_size: Option<u16>,
tag_size: Option<IntegrityTagSpec>,
) -> StratisResult<CreateAction<PoolUuid>> {
validate_name(name)?;
let name = Name::new(name.to_owned());
Expand Down
10 changes: 5 additions & 5 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, Key, KeyDescription, Name, PoolDiff,
PoolEncryptionInfo, PoolUuid, PropChangeAction, RegenAction, RenameAction,
SetCreateAction, SetDeleteAction, SizedKeyMemory, StratFilesystemDiff, StratPoolDiff,
StratSigblockVersion, UnlockMethod,
Diff, EncryptionInfo, FilesystemUuid, GrowAction, IntegrityTagSpec, Key,
KeyDescription, Name, PoolDiff, PoolEncryptionInfo, PoolUuid, PropChangeAction,
RegenAction, RenameAction, SetCreateAction, SetDeleteAction, SizedKeyMemory,
StratFilesystemDiff, StratPoolDiff, StratSigblockVersion, UnlockMethod,
},
},
stratis::{StratisError, StratisResult},
Expand Down Expand Up @@ -154,7 +154,7 @@ impl StratPool {
devices: UnownedDevices,
encryption_info: Option<&EncryptionInfo>,
journal_size: Option<Sectors>,
tag_size: Option<u16>,
tag_size: Option<IntegrityTagSpec>,
) -> StratisResult<(PoolUuid, StratPool)> {
let pool_uuid = PoolUuid::new_v4();

Expand Down
40 changes: 40 additions & 0 deletions src/engine/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,3 +481,43 @@ pub enum StratSigblockVersion {
V1 = 1,
V2 = 2,
}

/// A way to specify an integrity tag size. It is possible for the specification
/// to be non-numeric but translatable to some number of bits.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub enum IntegrityTagSpec {
B0,
B32,
B512,
}

impl IntegrityTagSpec {
pub fn as_bits(self) -> u16 {
match self {
IntegrityTagSpec::B0 => 0u16,
IntegrityTagSpec::B32 => 32u16,
IntegrityTagSpec::B512 => 512u16,
}
}
}

impl TryFrom<&str> for IntegrityTagSpec {
type Error = StratisError;

fn try_from(s: &str) -> StratisResult<IntegrityTagSpec> {
if let Ok(val) = s.parse::<u16>() {
match val {
0 => Ok(IntegrityTagSpec::B0),
32 => Ok(IntegrityTagSpec::B32),
512 => Ok(IntegrityTagSpec::B512),
_ => Err(StratisError::Msg(format!(
"{s} is not a currently supported tag size specification"
))),
}
} else {
Err(StratisError::Msg(format!(
"{s} is not a currently supported tag size specification"
)))
}
}
}

0 comments on commit 0a7d047

Please sign in to comment.