Skip to content

Commit

Permalink
Record integrity parameters in metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaublitz committed Dec 9, 2024
1 parent 908402a commit 3ce9af2
Show file tree
Hide file tree
Showing 13 changed files with 310 additions and 160 deletions.
12 changes: 10 additions & 2 deletions src/bin/utils/predict_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ use serde_json::{json, Value};

use devicemapper::{Bytes, Sectors};

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

// 2^FS_SIZE_START_POWER is the logical size of the smallest Stratis
// filesystem for which usage data exists in FSSizeLookup::internal, i.e.,
Expand Down Expand Up @@ -168,7 +171,12 @@ fn predict_pool_metadata_usage(device_sizes: Vec<Sectors>) -> Result<Sectors, Bo
.map(|&s| {
info!("Total size of device: {:}", s);

let integrity_deduction = integrity_meta_space(s);
let integrity_deduction = integrity_meta_space(
s,
DEFAULT_INTEGRITY_JOURNAL_SIZE.sectors(),
DEFAULT_INTEGRITY_BLOCK_SIZE,
DEFAULT_INTEGRITY_TAG_SIZE,
);
info!(
"Deduction for stratis metadata: {:}",
stratis_metadata_alloc
Expand Down
1 change: 1 addition & 0 deletions src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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,
},
structures::{AllLockReadGuard, ExclusiveGuard, SharedGuard, Table},
types::{
Expand Down
44 changes: 33 additions & 11 deletions src/engine/strat_engine/backstore/backstore/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ use either::Either;
use serde_json::Value;

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

use crate::{
Expand Down Expand Up @@ -437,12 +438,15 @@ impl Backstore {
devices: UnownedDevices,
mda_data_size: MDADataSize,
encryption_info: Option<&EncryptionInfo>,
integrity_journal_size: Option<Sectors>,
integrity_tag_size: Option<Bytes>,
) -> StratisResult<Backstore> {
let data_tier = DataTier::<StratBlockDev>::new(BlockDevMgr::<StratBlockDev>::initialize(
pool_uuid,
devices,
mda_data_size,
)?);
let data_tier = DataTier::<StratBlockDev>::new(
BlockDevMgr::<StratBlockDev>::initialize(pool_uuid, devices, mda_data_size)?,
integrity_journal_size,
None,
integrity_tag_size,
);

let mut backstore = Backstore {
data_tier,
Expand Down Expand Up @@ -1248,8 +1252,15 @@ mod tests {
let initdatadevs = get_devices(initdatapaths).unwrap();
let initcachedevs = get_devices(initcachepaths).unwrap();

let mut backstore =
Backstore::initialize(pool_uuid, initdatadevs, MDADataSize::default(), None).unwrap();
let mut backstore = Backstore::initialize(
pool_uuid,
initdatadevs,
MDADataSize::default(),
None,
None,
None,
)
.unwrap();

invariant(&backstore);

Expand Down Expand Up @@ -1340,8 +1351,15 @@ mod tests {
let devices1 = get_devices(paths1).unwrap();
let devices2 = get_devices(paths2).unwrap();

let mut backstore =
Backstore::initialize(pool_uuid, devices1, MDADataSize::default(), None).unwrap();
let mut backstore = Backstore::initialize(
pool_uuid,
devices1,
MDADataSize::default(),
None,
None,
None,
)
.unwrap();

for path in paths1 {
assert_eq!(
Expand Down Expand Up @@ -1404,6 +1422,8 @@ mod tests {
"tang".to_string(),
json!({"url": env::var("TANG_URL").expect("TANG_URL env var required"), "stratis:tang:trust_url": true}),
))),
None,
None,
)
.unwrap();
backstore.alloc(pool_uuid, &[Sectors(512)]).unwrap();
Expand Down Expand Up @@ -1478,6 +1498,8 @@ mod tests {
json!({"url": env::var("TANG_URL").expect("TANG_URL env var required"), "stratis:tang:trust_url": true}),
),
)),
None,
None,
).unwrap();
cmd::udev_settle().unwrap();

Expand Down
11 changes: 0 additions & 11 deletions src/engine/strat_engine/backstore/blockdev/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,6 @@ pub trait InternalBlockDev {
/// * Otherwise, `Some(_)`
fn calc_new_size(&self) -> StratisResult<Option<Sectors>>;

/// Grow the block device if the underlying physical device has grown in size.
/// Return an error and leave the size as is if the device has shrunk.
/// Do nothing if the device is the same size as recorded in the metadata.
///
/// This method does not need to block IO to the extended crypt device prior
/// to rollback because of per-pool locking. Growing the device will acquire
/// an exclusive lock on the pool and therefore the thin pool cannot be
/// extended to use the larger or unencrypted block device size until the
/// transaction has been completed successfully.
fn grow(&mut self) -> StratisResult<bool>;

/// Load the pool-level metadata for the given block device.
fn load_state(&self) -> StratisResult<Option<(Vec<u8>, &DateTime<Utc>)>>;

Expand Down
140 changes: 74 additions & 66 deletions src/engine/strat_engine/backstore/blockdev/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,72 +336,16 @@ impl StratBlockDev {
}
}

#[cfg(test)]
pub fn invariant(&self) {
assert!(self.total_size() == self.used.size());
}
}

impl InternalBlockDev for StratBlockDev {
fn uuid(&self) -> DevUuid {
self.bda.dev_uuid()
}

fn device(&self) -> &Device {
&self.dev
}

fn physical_path(&self) -> &Path {
self.devnode()
}

fn blksizes(&self) -> StratSectorSizes {
self.blksizes
}

fn metadata_version(&self) -> StratSigblockVersion {
self.bda.sigblock_version()
}

fn total_size(&self) -> BlockdevSize {
self.bda.dev_size()
}

fn available(&self) -> Sectors {
self.used.available()
}

fn metadata_size(&self) -> Sectors {
self.bda.extended_size().sectors()
}

fn max_stratis_metadata_size(&self) -> MDADataSize {
self.bda.max_data_size()
}

fn in_use(&self) -> bool {
self.used.used() > self.metadata_size()
}

fn alloc(&mut self, size: Sectors) -> PerDevSegments {
self.used.alloc_front(size)
}

fn calc_new_size(&self) -> StratisResult<Option<Sectors>> {
let s = Self::scan_blkdev_size(
self.physical_path(),
self.underlying_device.crypt_handle().is_some(),
)?;
if Some(s) == self.new_size
|| (self.new_size.is_none() && s == self.bda.dev_size().sectors())
{
Ok(None)
} else {
Ok(Some(s))
}
}

fn grow(&mut self) -> StratisResult<bool> {
/// Grow the block device if the underlying physical device has grown in size.
/// Return an error and leave the size as is if the device has shrunk.
/// Do nothing if the device is the same size as recorded in the metadata.
///
/// This method does not need to block IO to the extended crypt device prior
/// to rollback because of per-pool locking. Growing the device will acquire
/// an exclusive lock on the pool and therefore the thin pool cannot be
/// extended to use the larger or unencrypted block device size until the
/// transaction has been completed successfully.
pub fn grow(&mut self) -> StratisResult<bool> {
/// Precondition: size > h.blkdev_size
fn needs_rollback(bd: &mut StratBlockDev, size: BlockdevSize) -> StratisResult<()> {
let mut f = OpenOptions::new()
Expand Down Expand Up @@ -472,6 +416,70 @@ impl InternalBlockDev for StratBlockDev {
}
}
}
#[cfg(test)]
pub fn invariant(&self) {
assert!(self.total_size() == self.used.size());
}
}

impl InternalBlockDev for StratBlockDev {
fn uuid(&self) -> DevUuid {
self.bda.dev_uuid()
}

fn device(&self) -> &Device {
&self.dev
}

fn physical_path(&self) -> &Path {
self.devnode()
}

fn blksizes(&self) -> StratSectorSizes {
self.blksizes
}

fn metadata_version(&self) -> StratSigblockVersion {
self.bda.sigblock_version()
}

fn total_size(&self) -> BlockdevSize {
self.bda.dev_size()
}

fn available(&self) -> Sectors {
self.used.available()
}

fn metadata_size(&self) -> Sectors {
self.bda.extended_size().sectors()
}

fn max_stratis_metadata_size(&self) -> MDADataSize {
self.bda.max_data_size()
}

fn in_use(&self) -> bool {
self.used.used() > self.metadata_size()
}

fn alloc(&mut self, size: Sectors) -> PerDevSegments {
self.used.alloc_front(size)
}

fn calc_new_size(&self) -> StratisResult<Option<Sectors>> {
let s = Self::scan_blkdev_size(
self.physical_path(),
self.underlying_device.crypt_handle().is_some(),
)?;
if Some(s) == self.new_size
|| (self.new_size.is_none() && s == self.bda.dev_size().sectors())
{
Ok(None)
} else {
Ok(Some(s))
}
}

fn load_state(&self) -> StratisResult<Option<(Vec<u8>, &DateTime<Utc>)>> {
let mut f = OpenOptions::new()
Expand Down
Loading

0 comments on commit 3ce9af2

Please sign in to comment.