Skip to content

Commit

Permalink
Adjust width and meaning of tag-size
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Dec 16, 2024
1 parent 5ab1681 commit da93df7
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 27 deletions.
6 changes: 2 additions & 4 deletions src/bin/utils/cmds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,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)
.value_parser(clap::value_parser!(u16))
.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.")
.next_line_help(true)
)
Expand Down Expand Up @@ -152,10 +153,7 @@ impl<'a> UtilCommand<'a> for StratisPredictUsage {
}
})
.transpose()?,
sub_m
.get_one::<String>("integrity_tag_size")
.map(|s| s.parse::<u8>().map(Bytes::from))
.transpose()?,
sub_m.get_one::<u16>("integrity_tag_size").copied(),
LevelFilter::from_str(
matches
.get_one::<String>("log-level")
Expand Down
4 changes: 2 additions & 2 deletions src/bin/utils/predict_usage.rs
Original file line number Diff line number Diff line change
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<u16>,
) -> 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<u16>,
log_level: LevelFilter,
) -> Result<(), Box<dyn Error>> {
Builder::new().filter(None, log_level).init();
Expand Down
6 changes: 3 additions & 3 deletions src/dbus_api/api/manager_3_8/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ pub fn create_pool_method(f: &Factory<MTSync<TData>, TData>) -> Method<MTSync<TD
// Optional tag size 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: Integer representing tag size in bits.
//
// Rust representation: (bool, u8)
.in_arg(("tag_size", "(by)"))
// Rust representation: (bool, u16)
.in_arg(("tag_size", "(bq)"))
// 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
4 changes: 2 additions & 2 deletions src/dbus_api/api/manager_3_8/methods.rs
Original file line number Diff line number Diff line change
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, u16) = get_next_arg(&mut iter, 5)?;

let return_message = message.method_return();

Expand Down Expand Up @@ -188,7 +188,7 @@ 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 = tuple_to_option(tag_size_tuple);

let dbus_context = m.tree.get_data();
let create_result = handle_action!(block_on(dbus_context.engine.create_pool(
Expand Down
2 changes: 1 addition & 1 deletion src/engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,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<u16>,
) -> StratisResult<CreateAction<PoolUuid>>;

/// Handle a libudev event.
Expand Down
2 changes: 1 addition & 1 deletion src/engine/sim_engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl Engine for SimEngine {
blockdev_paths: &[&Path],
encryption_info: Option<&EncryptionInfo>,
_: Option<Bytes>,
_: Option<Bytes>,
_: Option<u16>,
) -> StratisResult<CreateAction<PoolUuid>> {
validate_name(name)?;
let name = Name::new(name.to_owned());
Expand Down
7 changes: 3 additions & 4 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 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<u16>,
) -> StratisResult<Backstore> {
let data_tier = DataTier::<StratBlockDev>::new(
BlockDevMgr::<StratBlockDev>::initialize(pool_uuid, devices, mda_data_size)?,
Expand Down
10 changes: 7 additions & 3 deletions src/engine/strat_engine/backstore/blockdev/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ pub fn integrity_meta_space(
total_space: Sectors,
journal_size: Sectors,
block_size: Bytes,
tag_size: Bytes,
tag_size: u16,
) -> 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)) / 8 + 7) & !7) + 4095)
& !4095,
)
.sectors()
}

#[derive(Debug)]
Expand Down Expand Up @@ -221,7 +225,7 @@ impl StratBlockDev {
&mut self,
integrity_journal_size: Sectors,
integrity_block_size: Bytes,
integrity_tag_size: Bytes,
integrity_tag_size: u16,
) -> StratisResult<bool> {
let size = BlockdevSize::new(Self::scan_blkdev_size(self.devnode())?);
let metadata_size = self.bda.dev_size();
Expand Down
2 changes: 1 addition & 1 deletion src/engine/strat_engine/backstore/blockdevmgr.rs
Original file line number Diff line number Diff line change
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: u16,
) -> StratisResult<bool> {
let bd = self
.block_devs
Expand Down
6 changes: 3 additions & 3 deletions src/engine/strat_engine/backstore/data_tier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::{

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: u16 = 64u16;

/// 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<u16>,
}

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<u16>,
) -> DataTier<v2::StratBlockDev> {
let integrity_journal_size =
integrity_journal_size.unwrap_or_else(|| DEFAULT_INTEGRITY_JOURNAL_SIZE.sectors());
Expand Down
2 changes: 1 addition & 1 deletion src/engine/strat_engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ impl Engine for StratEngine {
blockdev_paths: &[&Path],
encryption_info: Option<&EncryptionInfo>,
journal_size: Option<Bytes>,
tag_size: Option<Bytes>,
tag_size: Option<u16>,
) -> StratisResult<CreateAction<PoolUuid>> {
validate_name(name)?;
let name = Name::new(name.to_owned());
Expand Down
2 changes: 1 addition & 1 deletion src/engine/strat_engine/pool/v2.rs
Original file line number Diff line number Diff line change
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<u16>,
) -> StratisResult<(PoolUuid, StratPool)> {
let pool_uuid = PoolUuid::new_v4();

Expand Down
2 changes: 1 addition & 1 deletion src/engine/strat_engine/serde_structs.rs
Original file line number Diff line number Diff line change
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<u16>,
}

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

0 comments on commit da93df7

Please sign in to comment.