From 18b14958c049b926949c5323a9ecbd186a56e76d Mon Sep 17 00:00:00 2001 From: mulhern Date: Sun, 15 Dec 2024 23:47:37 -0500 Subject: [PATCH] Make D-Bus signature for integrity tag spec a string 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 --- src/bin/utils/cmds.rs | 21 +++++++---- src/bin/utils/predict_usage.rs | 10 +++--- src/dbus_api/api/manager_3_8/api.rs | 9 ++--- src/dbus_api/api/manager_3_8/methods.rs | 19 +++++++--- src/engine/engine.rs | 13 +++---- src/engine/mod.rs | 6 ++-- src/engine/sim_engine/engine.rs | 8 ++--- .../strat_engine/backstore/backstore/v2.rs | 13 ++++--- .../strat_engine/backstore/blockdev/v2.rs | 18 ++++++---- .../strat_engine/backstore/blockdevmgr.rs | 6 ++-- .../strat_engine/backstore/data_tier.rs | 24 ++++++------- src/engine/strat_engine/backstore/mod.rs | 2 +- src/engine/strat_engine/engine.rs | 9 ++--- src/engine/strat_engine/mod.rs | 2 +- src/engine/strat_engine/pool/v2.rs | 10 +++--- src/engine/strat_engine/serde_structs.rs | 4 +-- src/engine/types/mod.rs | 36 ++++++++++++++++++- 17 files changed, 135 insertions(+), 75 deletions(-) diff --git a/src/bin/utils/cmds.rs b/src/bin/utils/cmds.rs index 58ce808de0..f80d074c40 100644 --- a/src/bin/utils/cmds.rs +++ b/src/bin/utils/cmds.rs @@ -8,14 +8,17 @@ use std::{ str::FromStr, }; -use clap::{Arg, ArgAction, Command}; +use clap::{builder::PossibleValuesParser, Arg, ArgAction, Command}; #[cfg(feature = "systemd_compat")] use clap::builder::Str; use log::LevelFilter; +use strum::VariantNames; use devicemapper::Bytes; +use stratisd::engine::{IntegrityTagSpec, DEFAULT_INTEGRITY_TAG_SPEC}; + use crate::utils::predict_usage; #[cfg(feature = "systemd_compat")] @@ -88,10 +91,12 @@ pool is encrypted, setting this option has no effect on the prediction."), .next_line_help(true) ) .arg( - Arg::new("integrity_tag_size") - .long("integrity-tag-size") + Arg::new("integrity_tag_spec") + .long("integrity-tag-spec") .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.") + .value_parser(PossibleValuesParser::new(IntegrityTagSpec::VARIANTS)) + .default_value(DEFAULT_INTEGRITY_TAG_SPEC.as_ref()) + .help("Integrity tag specification defining the size of the tag to store a checksum or other value for each block on a device.") .next_line_help(true) ) .arg( @@ -153,9 +158,11 @@ impl<'a> UtilCommand<'a> for StratisPredictUsage { }) .transpose()?, sub_m - .get_one::("integrity_tag_size") - .map(|s| s.parse::().map(Bytes::from)) - .transpose()?, + .get_one::("integrity_tag_spec") + .map(|sz| { + IntegrityTagSpec::try_from(sz.as_str()).expect("parser ensures valid value") + }) + .expect("default specified by parser"), LevelFilter::from_str( matches .get_one::("log-level") diff --git a/src/bin/utils/predict_usage.rs b/src/bin/utils/predict_usage.rs index 1c9d602f05..27add2f2b9 100644 --- a/src/bin/utils/predict_usage.rs +++ b/src/bin/utils/predict_usage.rs @@ -14,8 +14,8 @@ use serde_json::{json, Value}; use devicemapper::{Bytes, Sectors}; use stratisd::engine::{ - crypt_metadata_size, integrity_meta_space, ThinPoolSizeParams, BDA, - DEFAULT_INTEGRITY_BLOCK_SIZE, DEFAULT_INTEGRITY_JOURNAL_SIZE, DEFAULT_INTEGRITY_TAG_SIZE, + crypt_metadata_size, integrity_meta_space, IntegrityTagSpec, ThinPoolSizeParams, BDA, + DEFAULT_INTEGRITY_BLOCK_SIZE, DEFAULT_INTEGRITY_JOURNAL_SIZE, }; // 2^FS_SIZE_START_POWER is the logical size of the smallest Stratis @@ -167,7 +167,7 @@ pub fn predict_filesystem_usage( fn predict_pool_metadata_usage( device_sizes: Vec, journal_size: Option, - tag_size: Option, + tag_size: IntegrityTagSpec, ) -> Result> { let stratis_metadata_alloc = BDA::default().extended_size().sectors(); let stratis_avail_sizes = device_sizes @@ -179,7 +179,7 @@ fn predict_pool_metadata_usage( s, journal_size.unwrap_or(DEFAULT_INTEGRITY_JOURNAL_SIZE.sectors()), DEFAULT_INTEGRITY_BLOCK_SIZE, - tag_size.unwrap_or(DEFAULT_INTEGRITY_TAG_SIZE), + tag_size, ); info!( "Deduction for stratis metadata: {:}", @@ -218,7 +218,7 @@ pub fn predict_pool_usage( device_sizes: Vec, filesystem_sizes: Option>, journal_size: Option, - tag_size: Option, + tag_size: IntegrityTagSpec, log_level: LevelFilter, ) -> Result<(), Box> { Builder::new().filter(None, log_level).init(); diff --git a/src/dbus_api/api/manager_3_8/api.rs b/src/dbus_api/api/manager_3_8/api.rs index 37067df11c..a7a0658a07 100644 --- a/src/dbus_api/api/manager_3_8/api.rs +++ b/src/dbus_api/api/manager_3_8/api.rs @@ -60,13 +60,14 @@ pub fn create_pool_method(f: &Factory, TData>) -> Method, 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(); @@ -188,7 +188,18 @@ pub fn create_pool(m: &MethodInfo<'_, MTSync, 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(&StratisError::Msg(format!( + "Failed to parse integrity tag specification: {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( diff --git a/src/engine/engine.rs b/src/engine/engine.rs index ed16f88e6e..8ffdfe51cf 100644 --- a/src/engine/engine.rs +++ b/src/engine/engine.rs @@ -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, @@ -382,7 +383,7 @@ pub trait Engine: Debug + Report + Send + Sync { blockdev_paths: &[&Path], encryption_info: Option<&EncryptionInfo>, journal_size: Option, - tag_size: Option, + tag_size: Option, ) -> StratisResult>; /// Handle a libudev event. diff --git a/src/engine/mod.rs b/src/engine/mod.rs index 468fac880b..5281cbe2cb 100644 --- a/src/engine/mod.rs +++ b/src/engine/mod.rs @@ -16,13 +16,13 @@ pub use self::{ crypt_metadata_size, get_dm, get_dm_init, integrity_meta_space, register_clevis_token, set_up_crypt_logging, unshare_mount_namespace, StaticHeader, StaticHeaderResult, StratEngine, StratKeyActions, ThinPoolSizeParams, BDA, CLEVIS_TANG_TRUST_URL, - DEFAULT_INTEGRITY_BLOCK_SIZE, DEFAULT_INTEGRITY_JOURNAL_SIZE, DEFAULT_INTEGRITY_TAG_SIZE, + DEFAULT_INTEGRITY_BLOCK_SIZE, DEFAULT_INTEGRITY_JOURNAL_SIZE, DEFAULT_INTEGRITY_TAG_SPEC, }, 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, diff --git a/src/engine/sim_engine/engine.rs b/src/engine/sim_engine/engine.rs index 09c408b044..e6c84678ba 100644 --- a/src/engine/sim_engine/engine.rs +++ b/src/engine/sim_engine/engine.rs @@ -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, }, @@ -132,7 +132,7 @@ impl Engine for SimEngine { blockdev_paths: &[&Path], encryption_info: Option<&EncryptionInfo>, _: Option, - _: Option, + _: Option, ) -> StratisResult> { validate_name(name)?; let name = Name::new(name.to_owned()); diff --git a/src/engine/strat_engine/backstore/backstore/v2.rs b/src/engine/strat_engine/backstore/backstore/v2.rs index 5be778c441..fe87952070 100644 --- a/src/engine/strat_engine/backstore/backstore/v2.rs +++ b/src/engine/strat_engine/backstore/backstore/v2.rs @@ -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::{ @@ -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}, @@ -439,12 +438,12 @@ impl Backstore { mda_data_size: MDADataSize, encryption_info: Option<&EncryptionInfo>, integrity_journal_size: Option, - integrity_tag_size: Option, + integrity_tag_spec: Option, ) -> StratisResult { let data_tier = DataTier::::new( BlockDevMgr::::initialize(pool_uuid, devices, mda_data_size)?, integrity_journal_size, - integrity_tag_size, + integrity_tag_spec, ); let mut backstore = Backstore { diff --git a/src/engine/strat_engine/backstore/blockdev/v2.rs b/src/engine/strat_engine/backstore/blockdev/v2.rs index 06c5a745f3..9dd759d017 100644 --- a/src/engine/strat_engine/backstore/blockdev/v2.rs +++ b/src/engine/strat_engine/backstore/blockdev/v2.rs @@ -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}, @@ -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)] @@ -221,7 +227,7 @@ impl StratBlockDev { &mut self, integrity_journal_size: Sectors, integrity_block_size: Bytes, - integrity_tag_size: Bytes, + integrity_tag_spec: IntegrityTagSpec, ) -> StratisResult { let size = BlockdevSize::new(Self::scan_blkdev_size(self.devnode())?); let metadata_size = self.bda.dev_size(); @@ -253,7 +259,7 @@ impl StratBlockDev { size.sectors(), integrity_journal_size, integrity_block_size, - integrity_tag_size, + integrity_tag_spec, ) - self .integrity_meta_allocs .iter() diff --git a/src/engine/strat_engine/backstore/blockdevmgr.rs b/src/engine/strat_engine/backstore/blockdevmgr.rs index 6a1807886e..2e1213df7a 100644 --- a/src/engine/strat_engine/backstore/blockdevmgr.rs +++ b/src/engine/strat_engine/backstore/blockdevmgr.rs @@ -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}, }; @@ -248,7 +248,7 @@ impl BlockDevMgr { dev: DevUuid, integrity_journal_size: Sectors, integrity_block_size: Bytes, - integrity_tag_size: Bytes, + integrity_tag_spec: IntegrityTagSpec, ) -> StratisResult { let bd = self .block_devs @@ -258,7 +258,7 @@ impl BlockDevMgr { bd.grow( integrity_journal_size, integrity_block_size, - integrity_tag_size, + integrity_tag_spec, ) } diff --git a/src/engine/strat_engine/backstore/data_tier.rs b/src/engine/strat_engine/backstore/data_tier.rs index 4f74f1d573..a66f35fc44 100644 --- a/src/engine/strat_engine/backstore/data_tier.rs +++ b/src/engine/strat_engine/backstore/data_tier.rs @@ -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_SPEC: IntegrityTagSpec = IntegrityTagSpec::B512; /// Handles the lowest level, base layer of this tier. #[derive(Debug)] @@ -48,7 +48,7 @@ pub struct DataTier { /// Integrity block size. integrity_block_size: Option, /// Integrity tag size. - integrity_tag_size: Option, + integrity_tag_spec: Option, } impl DataTier { @@ -64,7 +64,7 @@ impl DataTier { segments: AllocatedAbove { inner: vec![] }, integrity_journal_size: None, integrity_block_size: None, - integrity_tag_size: None, + integrity_tag_spec: None, } } @@ -125,12 +125,12 @@ impl DataTier { pub fn new( mut block_mgr: BlockDevMgr, integrity_journal_size: Option, - integrity_tag_size: Option, + integrity_tag_spec: Option, ) -> DataTier { let integrity_journal_size = integrity_journal_size.unwrap_or_else(|| DEFAULT_INTEGRITY_JOURNAL_SIZE.sectors()); let integrity_block_size = DEFAULT_INTEGRITY_BLOCK_SIZE; - let integrity_tag_size = integrity_tag_size.unwrap_or(DEFAULT_INTEGRITY_TAG_SIZE); + let integrity_tag_spec = integrity_tag_spec.unwrap_or(DEFAULT_INTEGRITY_TAG_SPEC); for (_, bd) in block_mgr.blockdevs_mut() { // NOTE: over-allocates integrity metadata slightly. Some of the // total size of the device will not make use of the integrity @@ -139,7 +139,7 @@ impl DataTier { bd.total_size().sectors(), integrity_journal_size, integrity_block_size, - integrity_tag_size, + integrity_tag_spec, )); } DataTier { @@ -147,7 +147,7 @@ impl DataTier { segments: AllocatedAbove { inner: vec![] }, integrity_journal_size: Some(integrity_journal_size), integrity_block_size: Some(integrity_block_size), - integrity_tag_size: Some(integrity_tag_size), + integrity_tag_spec: Some(integrity_tag_spec), } } @@ -178,7 +178,7 @@ impl DataTier { bd.total_size().sectors(), self.integrity_journal_size.expect("Must be some in V2"), self.integrity_block_size.expect("Must be some in V2"), - self.integrity_tag_size.expect("Must be some in V2"), + self.integrity_tag_spec.expect("Must be some in V2"), )); } Ok(uuids) @@ -218,7 +218,7 @@ impl DataTier { dev, self.integrity_journal_size.expect("Must be Some in V2"), self.integrity_block_size.expect("Must be Some in V2"), - self.integrity_tag_size.expect("Must be Some in V2"), + self.integrity_tag_spec.expect("Must be Some in V2"), ) } } @@ -251,7 +251,7 @@ where segments, integrity_journal_size: data_tier_save.integrity_journal_size, integrity_block_size: data_tier_save.integrity_block_size, - integrity_tag_size: data_tier_save.integrity_tag_size, + integrity_tag_spec: data_tier_save.integrity_tag_spec, }) } @@ -344,7 +344,7 @@ where }, integrity_journal_size: self.integrity_journal_size, integrity_block_size: self.integrity_block_size, - integrity_tag_size: self.integrity_tag_size, + integrity_tag_spec: self.integrity_tag_spec, } } } diff --git a/src/engine/strat_engine/backstore/mod.rs b/src/engine/strat_engine/backstore/mod.rs index 3311b24253..7b4ab59dea 100644 --- a/src/engine/strat_engine/backstore/mod.rs +++ b/src/engine/strat_engine/backstore/mod.rs @@ -15,7 +15,7 @@ mod shared; pub use self::{ blockdev::v2::integrity_meta_space, data_tier::{ - DEFAULT_INTEGRITY_BLOCK_SIZE, DEFAULT_INTEGRITY_JOURNAL_SIZE, DEFAULT_INTEGRITY_TAG_SIZE, + DEFAULT_INTEGRITY_BLOCK_SIZE, DEFAULT_INTEGRITY_JOURNAL_SIZE, DEFAULT_INTEGRITY_TAG_SPEC, }, devices::{find_stratis_devs_by_uuid, get_devno_from_path, ProcessedPathInfos, UnownedDevices}, }; diff --git a/src/engine/strat_engine/engine.rs b/src/engine/strat_engine/engine.rs index ceb7788df4..fc7961a9ab 100644 --- a/src/engine/strat_engine/engine.rs +++ b/src/engine/strat_engine/engine.rs @@ -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, }, @@ -495,7 +496,7 @@ impl Engine for StratEngine { blockdev_paths: &[&Path], encryption_info: Option<&EncryptionInfo>, journal_size: Option, - tag_size: Option, + tag_size: Option, ) -> StratisResult> { validate_name(name)?; let name = Name::new(name.to_owned()); diff --git a/src/engine/strat_engine/mod.rs b/src/engine/strat_engine/mod.rs index 1a1c12fd08..8222a54725 100644 --- a/src/engine/strat_engine/mod.rs +++ b/src/engine/strat_engine/mod.rs @@ -31,7 +31,7 @@ pub use self::pool::inspection as pool_inspection; pub use self::{ backstore::{ integrity_meta_space, DEFAULT_INTEGRITY_BLOCK_SIZE, DEFAULT_INTEGRITY_JOURNAL_SIZE, - DEFAULT_INTEGRITY_TAG_SIZE, + DEFAULT_INTEGRITY_TAG_SPEC, }, crypt::{ crypt_metadata_size, register_clevis_token, set_up_crypt_logging, CLEVIS_TANG_TRUST_URL, diff --git a/src/engine/strat_engine/pool/v2.rs b/src/engine/strat_engine/pool/v2.rs index 1b57ccffd0..b6d306a1b1 100644 --- a/src/engine/strat_engine/pool/v2.rs +++ b/src/engine/strat_engine/pool/v2.rs @@ -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}, @@ -154,7 +154,7 @@ impl StratPool { devices: UnownedDevices, encryption_info: Option<&EncryptionInfo>, journal_size: Option, - tag_size: Option, + tag_size: Option, ) -> StratisResult<(PoolUuid, StratPool)> { let pool_uuid = PoolUuid::new_v4(); diff --git a/src/engine/strat_engine/serde_structs.rs b/src/engine/strat_engine/serde_structs.rs index bb23225b44..c773029e2e 100644 --- a/src/engine/strat_engine/serde_structs.rs +++ b/src/engine/strat_engine/serde_structs.rs @@ -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; @@ -122,7 +122,7 @@ pub struct DataTierSave { #[serde(skip_serializing_if = "Option::is_none")] pub integrity_block_size: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub integrity_tag_size: Option, + pub integrity_tag_spec: Option, } #[derive(Debug, Deserialize, Eq, PartialEq, Serialize)] diff --git a/src/engine/types/mod.rs b/src/engine/types/mod.rs index 287400c496..292e471411 100644 --- a/src/engine/types/mod.rs +++ b/src/engine/types/mod.rs @@ -16,7 +16,7 @@ use std::{ use libudev::EventType; use serde::{Deserialize, Serialize}; use serde_json::Value; -use strum_macros::{self, EnumString, FromRepr, VariantNames}; +use strum_macros::{self, AsRefStr, EnumString, FromRepr, VariantNames}; use uuid::Uuid; pub use crate::engine::{ @@ -481,3 +481,37 @@ 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, + Serialize, + Deserialize, + VariantNames, + EnumString, + AsRefStr, +)] +pub enum IntegrityTagSpec { + #[strum(serialize = "0b")] + B0, + #[strum(serialize = "32b")] + B32, + #[strum(serialize = "512b")] + B512, +} + +impl IntegrityTagSpec { + pub fn as_bits(self) -> u16 { + match self { + IntegrityTagSpec::B0 => 0u16, + IntegrityTagSpec::B32 => 32u16, + IntegrityTagSpec::B512 => 512u16, + } + } +}