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.

Store the IntegrityTagSpec value in the pool-level metadata.
Nothing is gained by turning the enum into bits before storing it in the
pool-level metadata.

Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Dec 16, 2024
1 parent 0a68e34 commit cb519dd
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 53 deletions.
6 changes: 4 additions & 2 deletions src/bin/utils/cmds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use log::LevelFilter;

use devicemapper::Bytes;

use stratisd::engine::IntegrityTagSpec;

use crate::utils::predict_usage;

#[cfg(feature = "systemd_compat")]
Expand Down Expand Up @@ -91,7 +93,7 @@ pool is encrypted, setting this option has no effect on the prediction."),
Arg::new("integrity_tag_size")
.long("integrity-tag-size")
.num_args(1)
.help("Size of the integrity checksums to be stored in the integrity metadata. The checksum size depends on the algorithm used for checksums. Units are bytes.")
.help("Size of the integrity tag to stored a checksum or other value for each block on a device.")
.next_line_help(true)
)
.arg(
Expand Down Expand Up @@ -154,7 +156,7 @@ impl<'a> UtilCommand<'a> for StratisPredictUsage {
.transpose()?,
sub_m
.get_one::<String>("integrity_tag_size")
.map(|s| s.parse::<u8>().map(Bytes::from))
.map(|sz| IntegrityTagSpec::try_from(sz.as_str()))
.transpose()?,
LevelFilter::from_str(
matches
Expand Down
6 changes: 3 additions & 3 deletions src/bin/utils/predict_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use serde_json::{json, Value};
use devicemapper::{Bytes, Sectors};

use stratisd::engine::{
crypt_metadata_size, integrity_meta_space, ThinPoolSizeParams, BDA,
crypt_metadata_size, integrity_meta_space, IntegrityTagSpec, ThinPoolSizeParams, BDA,
DEFAULT_INTEGRITY_BLOCK_SIZE, DEFAULT_INTEGRITY_JOURNAL_SIZE, DEFAULT_INTEGRITY_TAG_SIZE,
};

Expand Down Expand Up @@ -167,7 +167,7 @@ pub fn predict_filesystem_usage(
fn predict_pool_metadata_usage(
device_sizes: Vec<Sectors>,
journal_size: Option<Sectors>,
tag_size: Option<Bytes>,
tag_size: Option<IntegrityTagSpec>,
) -> Result<Sectors, Box<dyn Error>> {
let stratis_metadata_alloc = BDA::default().extended_size().sectors();
let stratis_avail_sizes = device_sizes
Expand Down Expand Up @@ -218,7 +218,7 @@ pub fn predict_pool_usage(
device_sizes: Vec<Bytes>,
filesystem_sizes: Option<Vec<Bytes>>,
journal_size: Option<Sectors>,
tag_size: Option<Bytes>,
tag_size: Option<IntegrityTagSpec>,
log_level: LevelFilter,
) -> Result<(), Box<dyn Error>> {
Builder::new().filter(None, log_level).init();
Expand Down
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.
// i: Integer representing tag size in bytes.
// q: Tag size specification.
//
// Rust representation: (bool, u8)
.in_arg(("tag_size", "(by)"))
// 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, u8) = 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).map(Bytes::from);
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<Bytes>,
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<Bytes>,
_: Option<IntegrityTagSpec>,
) -> StratisResult<CreateAction<PoolUuid>> {
validate_name(name)?;
let name = Name::new(name.to_owned());
Expand Down
11 changes: 5 additions & 6 deletions src/engine/strat_engine/backstore/backstore/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ use either::Either;
use serde_json::Value;

use devicemapper::{
Bytes, CacheDev, CacheDevTargetTable, CacheTargetParams, DevId, Device, DmDevice, DmFlags,
DmOptions, LinearDev, LinearDevTargetParams, LinearTargetParams, Sectors, TargetLine,
TargetTable,
CacheDev, CacheDevTargetTable, CacheTargetParams, DevId, Device, DmDevice, DmFlags, DmOptions,
LinearDev, LinearDevTargetParams, LinearTargetParams, Sectors, TargetLine, TargetTable,
};

use crate::{
Expand All @@ -34,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 @@ -439,7 +438,7 @@ impl Backstore {
mda_data_size: MDADataSize,
encryption_info: Option<&EncryptionInfo>,
integrity_journal_size: Option<Sectors>,
integrity_tag_size: Option<Bytes>,
integrity_tag_size: Option<IntegrityTagSpec>,
) -> StratisResult<Backstore> {
let data_tier = DataTier::<StratBlockDev>::new(
BlockDevMgr::<StratBlockDev>::initialize(pool_uuid, devices, mda_data_size)?,
Expand Down
16 changes: 11 additions & 5 deletions src/engine/strat_engine/backstore/blockdev/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ use crate::{
types::BDAResult,
},
types::{
Compare, DevUuid, DevicePath, Diff, PoolUuid, StateDiff, StratBlockDevDiff,
StratSigblockVersion,
Compare, DevUuid, DevicePath, Diff, IntegrityTagSpec, PoolUuid, StateDiff,
StratBlockDevDiff, StratSigblockVersion,
},
},
stratis::{StratisError, StratisResult},
Expand All @@ -51,11 +51,17 @@ pub fn integrity_meta_space(
total_space: Sectors,
journal_size: Sectors,
block_size: Bytes,
tag_size: Bytes,
tag_size: IntegrityTagSpec,
) -> Sectors {
Bytes(4096).sectors()
+ journal_size
+ Bytes::from(((*total_space.bytes() / *block_size) * *tag_size + 4095) & !4095).sectors()
+ Bytes::from(
(((((total_space.bytes() / block_size) * u128::from(tag_size.as_bits())) / 8 + 7)
& !7)
+ 4095)
& !4095,
)
.sectors()
}

#[derive(Debug)]
Expand Down Expand Up @@ -221,7 +227,7 @@ impl StratBlockDev {
&mut self,
integrity_journal_size: Sectors,
integrity_block_size: Bytes,
integrity_tag_size: Bytes,
integrity_tag_size: IntegrityTagSpec,
) -> StratisResult<bool> {
let size = BlockdevSize::new(Self::scan_blkdev_size(self.devnode())?);
let metadata_size = self.bda.dev_size();
Expand Down
4 changes: 2 additions & 2 deletions src/engine/strat_engine/backstore/blockdevmgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::{
serde_structs::{BaseBlockDevSave, Recordable},
shared::bds_to_bdas,
},
types::{DevUuid, EncryptionInfo, Name, PoolEncryptionInfo, PoolUuid},
types::{DevUuid, EncryptionInfo, IntegrityTagSpec, Name, PoolEncryptionInfo, PoolUuid},
},
stratis::{StratisError, StratisResult},
};
Expand Down Expand Up @@ -248,7 +248,7 @@ impl BlockDevMgr<v2::StratBlockDev> {
dev: DevUuid,
integrity_journal_size: Sectors,
integrity_block_size: Bytes,
integrity_tag_size: Bytes,
integrity_tag_size: IntegrityTagSpec,
) -> StratisResult<bool> {
let bd = self
.block_devs
Expand Down
8 changes: 4 additions & 4 deletions src/engine/strat_engine/backstore/data_tier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ use crate::{
},
types::BDARecordResult,
},
types::{BlockDevTier, DevUuid, Name, PoolUuid},
types::{BlockDevTier, DevUuid, IntegrityTagSpec, Name, PoolUuid},
},
stratis::StratisResult,
};

pub const DEFAULT_INTEGRITY_JOURNAL_SIZE: Bytes = Bytes(128 * IEC::Mi as u128);
pub const DEFAULT_INTEGRITY_BLOCK_SIZE: Bytes = Bytes(4 * IEC::Ki as u128);
pub const DEFAULT_INTEGRITY_TAG_SIZE: Bytes = Bytes(64u128);
pub const DEFAULT_INTEGRITY_TAG_SIZE: IntegrityTagSpec = IntegrityTagSpec::B512;

/// Handles the lowest level, base layer of this tier.
#[derive(Debug)]
Expand All @@ -48,7 +48,7 @@ pub struct DataTier<B> {
/// Integrity block size.
integrity_block_size: Option<Bytes>,
/// Integrity tag size.
integrity_tag_size: Option<Bytes>,
integrity_tag_size: Option<IntegrityTagSpec>,
}

impl DataTier<v1::StratBlockDev> {
Expand Down Expand Up @@ -125,7 +125,7 @@ impl DataTier<v2::StratBlockDev> {
pub fn new(
mut block_mgr: BlockDevMgr<v2::StratBlockDev>,
integrity_journal_size: Option<Sectors>,
integrity_tag_size: Option<Bytes>,
integrity_tag_size: Option<IntegrityTagSpec>,
) -> DataTier<v2::StratBlockDev> {
let integrity_journal_size =
integrity_journal_size.unwrap_or_else(|| DEFAULT_INTEGRITY_JOURNAL_SIZE.sectors());
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<Bytes>,
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<Bytes>,
tag_size: Option<IntegrityTagSpec>,
) -> StratisResult<(PoolUuid, StratPool)> {
let pool_uuid = PoolUuid::new_v4();

Expand Down
4 changes: 2 additions & 2 deletions src/engine/strat_engine/serde_structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use serde::{Serialize, Serializer};

use devicemapper::{Bytes, Sectors, ThinDevId};

use crate::engine::types::{DevUuid, Features, FilesystemUuid};
use crate::engine::types::{DevUuid, Features, FilesystemUuid, IntegrityTagSpec};

const MAXIMUM_STRING_SIZE: usize = 255;

Expand Down Expand Up @@ -122,7 +122,7 @@ pub struct DataTierSave {
#[serde(skip_serializing_if = "Option::is_none")]
pub integrity_block_size: Option<Bytes>,
#[serde(skip_serializing_if = "Option::is_none")]
pub integrity_tag_size: Option<Bytes>,
pub integrity_tag_size: Option<IntegrityTagSpec>,
}

#[derive(Debug, Deserialize, Eq, PartialEq, Serialize)]
Expand Down
Loading

0 comments on commit cb519dd

Please sign in to comment.