Skip to content

Commit c2f2231

Browse files
committed
Add a ValidatedIntegritySpec type
Use ValidatedIntegritySpec for serialization and to pass to methods invoked by engine's create_pool method. Signed-off-by: mulhern <[email protected]>
1 parent bf85af1 commit c2f2231

File tree

15 files changed

+195
-194
lines changed

15 files changed

+195
-194
lines changed

src/bin/utils/cmds.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ use strum::VariantNames;
1818
use devicemapper::Bytes;
1919

2020
use stratisd::engine::{
21-
IntegrityTagSpec, DEFAULT_INTEGRITY_JOURNAL_SIZE, DEFAULT_INTEGRITY_TAG_SPEC,
21+
IntegritySpec, IntegrityTagSpec, ValidatedIntegritySpec, DEFAULT_INTEGRITY_JOURNAL_SIZE,
22+
DEFAULT_INTEGRITY_TAG_SPEC,
2223
};
2324

2425
use crate::utils::predict_usage;
@@ -149,24 +150,23 @@ impl<'a> UtilCommand<'a> for StratisPredictUsage {
149150
sub_m
150151
.get_many::<u128>("filesystem-size")
151152
.map(|szs| szs.map(|n| Bytes(*n)).collect::<Vec<_>>()),
152-
sub_m
153-
.get_one::<u64>("integrity_journal_size")
154-
.map(|n| Bytes::from(*n))
155-
.map(|b| {
156-
if b % 4096u64 != Bytes(0) {
157-
Err(format!("Value {b} is not aligned to 4096"))
158-
} else {
159-
Ok(b.sectors())
160-
}
161-
})
162-
.transpose()?
163-
.expect("default specified by parser"),
164-
sub_m
165-
.get_one::<String>("integrity_tag_spec")
166-
.map(|sz| {
167-
IntegrityTagSpec::try_from(sz.as_str()).expect("parser ensures valid value")
168-
})
169-
.expect("default specified by parser"),
153+
ValidatedIntegritySpec::try_from(IntegritySpec {
154+
journal_size: Some(
155+
sub_m
156+
.get_one::<u64>("integrity_journal_size")
157+
.map(|n| Bytes::from(*n))
158+
.expect("default specified by parser"),
159+
),
160+
tag_spec: Some(
161+
sub_m
162+
.get_one::<String>("integrity_tag_spec")
163+
.map(|sz| {
164+
IntegrityTagSpec::try_from(sz.as_str())
165+
.expect("parser ensures valid value")
166+
})
167+
.expect("default specified by parser"),
168+
),
169+
})?,
170170
LevelFilter::from_str(
171171
matches
172172
.get_one::<String>("log-level")

src/bin/utils/predict_usage.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ use serde_json::{json, Value};
1414
use devicemapper::{Bytes, Sectors};
1515

1616
use stratisd::engine::{
17-
crypt_metadata_size, integrity_meta_space, IntegrityTagSpec, ThinPoolSizeParams, BDA,
18-
DEFAULT_INTEGRITY_BLOCK_SIZE,
17+
crypt_metadata_size, integrity_meta_space, ThinPoolSizeParams, ValidatedIntegritySpec, BDA,
1918
};
2019

2120
// 2^FS_SIZE_START_POWER is the logical size of the smallest Stratis
@@ -166,17 +165,15 @@ pub fn predict_filesystem_usage(
166165

167166
fn predict_pool_metadata_usage(
168167
device_sizes: Vec<Sectors>,
169-
journal_size: Sectors,
170-
tag_spec: IntegrityTagSpec,
168+
integrity_spec: ValidatedIntegritySpec,
171169
) -> Result<Sectors, Box<dyn Error>> {
172170
let stratis_metadata_alloc = BDA::default().extended_size().sectors();
173171
let stratis_avail_sizes = device_sizes
174172
.iter()
175173
.map(|&s| {
176174
info!("Total size of device: {:}", s);
177175

178-
let integrity_deduction =
179-
integrity_meta_space(s, journal_size, DEFAULT_INTEGRITY_BLOCK_SIZE, tag_spec);
176+
let integrity_deduction = integrity_meta_space(s, integrity_spec);
180177
info!(
181178
"Deduction for stratis metadata: {:}",
182179
stratis_metadata_alloc
@@ -213,8 +210,7 @@ pub fn predict_pool_usage(
213210
overprovisioned: bool,
214211
device_sizes: Vec<Bytes>,
215212
filesystem_sizes: Option<Vec<Bytes>>,
216-
journal_size: Sectors,
217-
tag_spec: IntegrityTagSpec,
213+
integrity_spec: ValidatedIntegritySpec,
218214
log_level: LevelFilter,
219215
) -> Result<(), Box<dyn Error>> {
220216
Builder::new().filter(None, log_level).init();
@@ -226,7 +222,7 @@ pub fn predict_pool_usage(
226222
let device_sizes = device_sizes.iter().map(|s| s.sectors()).collect::<Vec<_>>();
227223
let total_size: Sectors = device_sizes.iter().cloned().sum();
228224

229-
let non_metadata_size = predict_pool_metadata_usage(device_sizes, journal_size, tag_spec)?;
225+
let non_metadata_size = predict_pool_metadata_usage(device_sizes, integrity_spec)?;
230226

231227
let size_params = ThinPoolSizeParams::new(non_metadata_size)?;
232228
let total_non_data = 2usize * size_params.meta_size() + size_params.mdv_size();

src/engine/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ pub use self::{
1616
crypt_metadata_size, get_dm, get_dm_init, integrity_meta_space, register_clevis_token,
1717
set_up_crypt_logging, unshare_mount_namespace, StaticHeader, StaticHeaderResult,
1818
StratEngine, StratKeyActions, ThinPoolSizeParams, BDA, CLEVIS_TANG_TRUST_URL,
19-
DEFAULT_INTEGRITY_BLOCK_SIZE, DEFAULT_INTEGRITY_JOURNAL_SIZE, DEFAULT_INTEGRITY_TAG_SPEC,
2019
},
2120
structures::{AllLockReadGuard, ExclusiveGuard, SharedGuard, Table},
2221
types::{
@@ -27,7 +26,8 @@ pub use self::{
2726
PoolUuid, PropChangeAction, RenameAction, ReportType, SetCreateAction, SetDeleteAction,
2827
SetUnlockAction, StartAction, StopAction, StoppedPoolInfo, StoppedPoolsInfo,
2928
StratBlockDevDiff, StratFilesystemDiff, StratPoolDiff, StratSigblockVersion, StratisUuid,
30-
ThinPoolDiff, ToDisplay, UdevEngineEvent, UnlockMethod,
29+
ThinPoolDiff, ToDisplay, UdevEngineEvent, UnlockMethod, ValidatedIntegritySpec,
30+
DEFAULT_INTEGRITY_JOURNAL_SIZE, DEFAULT_INTEGRITY_TAG_SPEC,
3131
},
3232
};
3333

src/engine/sim_engine/engine.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use crate::{
2828
IntegritySpec, LockedPoolsInfo, Name, PoolDevice, PoolDiff, PoolIdentifier, PoolUuid,
2929
RenameAction, ReportType, SetUnlockAction, StartAction, StopAction, StoppedPoolInfo,
3030
StoppedPoolsInfo, StratFilesystemDiff, UdevEngineEvent, UnlockMethod,
31+
ValidatedIntegritySpec,
3132
},
3233
StratSigblockVersion,
3334
},
@@ -129,13 +130,15 @@ impl Engine for SimEngine {
129130
name: &str,
130131
blockdev_paths: &[&Path],
131132
encryption_info: Option<&EncryptionInfo>,
132-
_: IntegritySpec,
133+
integrity_spec: IntegritySpec,
133134
) -> StratisResult<CreateAction<PoolUuid>> {
134135
validate_name(name)?;
135136
let name = Name::new(name.to_owned());
136137

137138
validate_paths(blockdev_paths)?;
138139

140+
ValidatedIntegritySpec::try_from(integrity_spec)?;
141+
139142
if let Some(key_desc) = encryption_info.and_then(|ei| ei.key_description()) {
140143
if !self.key_handler.contains_key(key_desc) {
141144
return Err(StratisError::Msg(format!(

src/engine/strat_engine/backstore/backstore/v2.rs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ use crate::{
3333
writing::wipe_sectors,
3434
},
3535
types::{
36-
ActionAvailability, BlockDevTier, DevUuid, EncryptionInfo, IntegrityTagSpec,
37-
KeyDescription, PoolUuid, SizedKeyMemory, UnlockMethod,
36+
ActionAvailability, BlockDevTier, DevUuid, EncryptionInfo, KeyDescription, PoolUuid,
37+
SizedKeyMemory, UnlockMethod, ValidatedIntegritySpec,
3838
},
3939
},
4040
stratis::{StratisError, StratisResult},
@@ -437,13 +437,11 @@ impl Backstore {
437437
devices: UnownedDevices,
438438
mda_data_size: MDADataSize,
439439
encryption_info: Option<&EncryptionInfo>,
440-
integrity_journal_size: Option<Sectors>,
441-
integrity_tag_spec: Option<IntegrityTagSpec>,
440+
integrity_spec: ValidatedIntegritySpec,
442441
) -> StratisResult<Backstore> {
443442
let data_tier = DataTier::<StratBlockDev>::new(
444443
BlockDevMgr::<StratBlockDev>::initialize(pool_uuid, devices, mda_data_size)?,
445-
integrity_journal_size,
446-
integrity_tag_spec,
444+
integrity_spec,
447445
);
448446

449447
let mut backstore = Backstore {
@@ -1172,13 +1170,16 @@ mod tests {
11721170

11731171
use devicemapper::{CacheDevStatus, DataBlocks, DmOptions, IEC};
11741172

1175-
use crate::engine::strat_engine::{
1176-
backstore::devices::{ProcessedPathInfos, UnownedDevices},
1177-
cmd,
1178-
crypt::crypt_metadata_size,
1179-
metadata::device_identifiers,
1180-
ns::{unshare_mount_namespace, MemoryFilesystem},
1181-
tests::{crypt, loopbacked, real},
1173+
use crate::engine::{
1174+
strat_engine::{
1175+
backstore::devices::{ProcessedPathInfos, UnownedDevices},
1176+
cmd,
1177+
crypt::crypt_metadata_size,
1178+
metadata::device_identifiers,
1179+
ns::{unshare_mount_namespace, MemoryFilesystem},
1180+
tests::{crypt, loopbacked, real},
1181+
},
1182+
types::ValidatedIntegritySpec,
11821183
};
11831184

11841185
use super::*;
@@ -1255,8 +1256,7 @@ mod tests {
12551256
initdatadevs,
12561257
MDADataSize::default(),
12571258
None,
1258-
None,
1259-
None,
1259+
ValidatedIntegritySpec::default(),
12601260
)
12611261
.unwrap();
12621262

@@ -1354,8 +1354,7 @@ mod tests {
13541354
devices1,
13551355
MDADataSize::default(),
13561356
None,
1357-
None,
1358-
None,
1357+
ValidatedIntegritySpec::default(),
13591358
)
13601359
.unwrap();
13611360

@@ -1420,8 +1419,7 @@ mod tests {
14201419
"tang".to_string(),
14211420
json!({"url": env::var("TANG_URL").expect("TANG_URL env var required"), "stratis:tang:trust_url": true}),
14221421
))),
1423-
None,
1424-
None,
1422+
ValidatedIntegritySpec::default(),
14251423
)
14261424
.unwrap();
14271425
backstore.alloc(pool_uuid, &[Sectors(512)]).unwrap();
@@ -1496,8 +1494,7 @@ mod tests {
14961494
json!({"url": env::var("TANG_URL").expect("TANG_URL env var required"), "stratis:tang:trust_url": true}),
14971495
),
14981496
)),
1499-
None,
1500-
None,
1497+
ValidatedIntegritySpec::default(),
15011498
).unwrap();
15021499
cmd::udev_settle().unwrap();
15031500

src/engine/strat_engine/backstore/blockdev/v2.rs

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ use crate::{
3434
types::BDAResult,
3535
},
3636
types::{
37-
Compare, DevUuid, DevicePath, Diff, IntegrityTagSpec, PoolUuid, StateDiff,
38-
StratBlockDevDiff, StratSigblockVersion,
37+
Compare, DevUuid, DevicePath, Diff, PoolUuid, StateDiff, StratBlockDevDiff,
38+
StratSigblockVersion, ValidatedIntegritySpec,
3939
},
4040
},
4141
stratis::{StratisError, StratisResult},
@@ -49,14 +49,15 @@ use crate::{
4949
/// The result is divisible by 8 sectors.
5050
pub fn integrity_meta_space(
5151
total_space: Sectors,
52-
journal_size: Sectors,
53-
block_size: Bytes,
54-
tag_spec: IntegrityTagSpec,
52+
integrity_spec: ValidatedIntegritySpec,
5553
) -> Sectors {
5654
Bytes(4096).sectors()
57-
+ journal_size
55+
+ integrity_spec.journal_size
5856
+ Bytes::from(
59-
(*((total_space.bytes() / block_size) * tag_spec.as_bytes_ceil()) + 4095) & !4095,
57+
(*((total_space.bytes() / integrity_spec.block_size)
58+
* integrity_spec.tag_spec.as_bytes_ceil())
59+
+ 4095)
60+
& !4095,
6061
)
6162
.sectors()
6263
}
@@ -220,12 +221,7 @@ impl StratBlockDev {
220221
///
221222
/// This will also extend integrity metadata reservations according to the new
222223
/// size of the device.
223-
pub fn grow(
224-
&mut self,
225-
integrity_journal_size: Sectors,
226-
integrity_block_size: Bytes,
227-
integrity_tag_spec: IntegrityTagSpec,
228-
) -> StratisResult<bool> {
224+
pub fn grow(&mut self, integrity_spec: ValidatedIntegritySpec) -> StratisResult<bool> {
229225
let size = BlockdevSize::new(Self::scan_blkdev_size(self.devnode())?);
230226
let metadata_size = self.bda.dev_size();
231227
match size.cmp(&metadata_size) {
@@ -252,16 +248,12 @@ impl StratBlockDev {
252248
self.bda.header = h;
253249
self.used.increase_size(size.sectors());
254250

255-
let integrity_grow = integrity_meta_space(
256-
size.sectors(),
257-
integrity_journal_size,
258-
integrity_block_size,
259-
integrity_tag_spec,
260-
) - self
261-
.integrity_meta_allocs
262-
.iter()
263-
.map(|(_, len)| *len)
264-
.sum::<Sectors>();
251+
let integrity_grow = integrity_meta_space(size.sectors(), integrity_spec)
252+
- self
253+
.integrity_meta_allocs
254+
.iter()
255+
.map(|(_, len)| *len)
256+
.sum::<Sectors>();
265257
self.alloc_int_meta_back(integrity_grow);
266258

267259
Ok(true)

src/engine/strat_engine/backstore/blockdevmgr.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ use crate::{
2929
serde_structs::{BaseBlockDevSave, Recordable},
3030
shared::bds_to_bdas,
3131
},
32-
types::{DevUuid, EncryptionInfo, IntegrityTagSpec, Name, PoolEncryptionInfo, PoolUuid},
32+
types::{
33+
DevUuid, EncryptionInfo, Name, PoolEncryptionInfo, PoolUuid, ValidatedIntegritySpec,
34+
},
3335
},
3436
stratis::{StratisError, StratisResult},
3537
};
@@ -246,20 +248,14 @@ impl BlockDevMgr<v2::StratBlockDev> {
246248
pub fn grow(
247249
&mut self,
248250
dev: DevUuid,
249-
integrity_journal_size: Sectors,
250-
integrity_block_size: Bytes,
251-
integrity_tag_spec: IntegrityTagSpec,
251+
integrity_spec: ValidatedIntegritySpec,
252252
) -> StratisResult<bool> {
253253
let bd = self
254254
.block_devs
255255
.iter_mut()
256256
.find(|bd| bd.uuid() == dev)
257257
.ok_or_else(|| StratisError::Msg(format!("Block device with UUID {dev} not found")))?;
258-
bd.grow(
259-
integrity_journal_size,
260-
integrity_block_size,
261-
integrity_tag_spec,
262-
)
258+
bd.grow(integrity_spec)
263259
}
264260

265261
#[cfg(test)]

0 commit comments

Comments
 (0)