Skip to content

Commit

Permalink
Merge pull request #3706 from jbaublitz/raid-metadata-removal
Browse files Browse the repository at this point in the history
Remove preallocation of RAID metadata
  • Loading branch information
mulkieran authored Oct 22, 2024
2 parents db449b8 + 24f6c88 commit a055200
Show file tree
Hide file tree
Showing 10 changed files with 8 additions and 44 deletions.
7 changes: 1 addition & 6 deletions src/bin/utils/predict_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ use serde_json::{json, Value};

use devicemapper::{Bytes, Sectors};

use stratisd::engine::{
crypt_metadata_size, integrity_meta_space, raid_meta_space, ThinPoolSizeParams, BDA,
};
use stratisd::engine::{crypt_metadata_size, integrity_meta_space, ThinPoolSizeParams, BDA};

// 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 @@ -164,7 +162,6 @@ pub fn predict_filesystem_usage(
}

fn predict_pool_metadata_usage(device_sizes: Vec<Sectors>) -> Result<Sectors, Box<dyn Error>> {
let raid_metadata_alloc = raid_meta_space();
let stratis_metadata_alloc = BDA::default().extended_size().sectors();
let stratis_avail_sizes = device_sizes
.iter()
Expand All @@ -178,9 +175,7 @@ fn predict_pool_metadata_usage(device_sizes: Vec<Sectors>) -> Result<Sectors, Bo
);

info!("Deduction for integrity space: {:}", integrity_deduction);
info!("Deduction for raid space: {:}", raid_metadata_alloc);
(*s).checked_sub(*stratis_metadata_alloc)
.and_then(|r| r.checked_sub(*raid_metadata_alloc))
.and_then(|r| r.checked_sub(*integrity_deduction))
.map(Sectors)
.map(|x| {
Expand Down
7 changes: 3 additions & 4 deletions src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ pub use self::{
shared::{total_allocated, total_used},
sim_engine::SimEngine,
strat_engine::{
crypt_metadata_size, get_dm, get_dm_init, integrity_meta_space, raid_meta_space,
register_clevis_token, set_up_crypt_logging, unshare_mount_namespace, StaticHeader,
StaticHeaderResult, StratEngine, StratKeyActions, ThinPoolSizeParams, BDA,
CLEVIS_TANG_TRUST_URL,
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,
},
structures::{AllLockReadGuard, ExclusiveGuard, SharedGuard, Table},
types::{
Expand Down
1 change: 0 additions & 1 deletion src/engine/strat_engine/backstore/blockdev/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,6 @@ impl Recordable<BaseBlockDevSave> for StratBlockDev {
uuid: self.uuid(),
user_info: self.user_info.clone(),
hardware_info: self.hardware_info.clone(),
raid_meta_allocs: Vec::new(),
integrity_meta_allocs: Vec::new(),
}
}
Expand Down
22 changes: 0 additions & 22 deletions src/engine/strat_engine/backstore/blockdev/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ pub fn integrity_meta_space(total_space: Sectors) -> Sectors {
+ Bytes::from((*total_space * 32u64 + 4095) & !4095).sectors()
}

/// Return the amount of space required for RAID for a device of the given size.
///
/// This is a slight overestimation for the sake of simplicity. The maximum metadata size is used
/// to leave adequate room for any sized device's metadata.
pub fn raid_meta_space() -> Sectors {
Bytes::from(129 * IEC::Mi).sectors()
}

#[derive(Debug)]
pub struct StratBlockDev {
dev: Device,
Expand All @@ -71,7 +63,6 @@ pub struct StratBlockDev {
devnode: DevicePath,
new_size: Option<Sectors>,
blksizes: StratSectorSizes,
raid_meta_allocs: Vec<(Sectors, Sectors)>,
integrity_meta_allocs: Vec<(Sectors, Sectors)>,
}

Expand Down Expand Up @@ -103,15 +94,13 @@ impl StratBlockDev {
dev: Device,
bda: BDA,
other_segments: &[(Sectors, Sectors)],
raid_meta_allocs: &[(Sectors, Sectors)],
integrity_meta_allocs: &[(Sectors, Sectors)],
user_info: Option<String>,
hardware_info: Option<String>,
devnode: DevicePath,
) -> BDAResult<StratBlockDev> {
let mut segments = vec![(Sectors(0), bda.extended_size().sectors())];
segments.extend(other_segments);
segments.extend(raid_meta_allocs);
segments.extend(integrity_meta_allocs);

let allocator = match RangeAllocator::new(bda.dev_size(), &segments) {
Expand Down Expand Up @@ -143,7 +132,6 @@ impl StratBlockDev {
devnode,
new_size: None,
blksizes,
raid_meta_allocs: raid_meta_allocs.to_owned(),
integrity_meta_allocs: integrity_meta_allocs.to_owned(),
})
}
Expand Down Expand Up @@ -190,14 +178,6 @@ impl StratBlockDev {
Ok(blkdev_size(&File::open(physical_path)?)?.sectors())
}

/// Allocate room for RAID metadata from the back of the device.
pub fn alloc_raid_meta(&mut self, size: Sectors) {
let segs = self.used.alloc_front(size);
for (start, len) in segs.iter() {
self.raid_meta_allocs.push((*start, *len));
}
}

/// Allocate room for integrity metadata from the back of the device.
pub fn alloc_int_meta_back(&mut self, size: Sectors) {
let segs = self.used.alloc_back(size);
Expand Down Expand Up @@ -264,7 +244,6 @@ impl InternalBlockDev for StratBlockDev {
fn metadata_size(&self) -> Sectors {
self.bda.extended_size().sectors()
+ self.integrity_meta_allocs.iter().map(|(_, len)| *len).sum()
+ self.raid_meta_allocs.iter().map(|(_, len)| *len).sum()
}

fn max_stratis_metadata_size(&self) -> MDADataSize {
Expand Down Expand Up @@ -432,7 +411,6 @@ impl Recordable<BaseBlockDevSave> for StratBlockDev {
uuid: self.uuid(),
user_info: self.user_info.clone(),
hardware_info: self.hardware_info.clone(),
raid_meta_allocs: self.raid_meta_allocs.clone(),
integrity_meta_allocs: self.integrity_meta_allocs.clone(),
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/engine/strat_engine/backstore/data_tier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
backstore::{
blockdev::{
v1,
v2::{self, integrity_meta_space, raid_meta_space},
v2::{self, integrity_meta_space},
InternalBlockDev,
},
blockdevmgr::BlockDevMgr,
Expand Down Expand Up @@ -107,7 +107,6 @@ impl DataTier<v2::StratBlockDev> {
/// WARNING: metadata changing event
pub fn new(mut block_mgr: BlockDevMgr<v2::StratBlockDev>) -> DataTier<v2::StratBlockDev> {
for (_, bd) in block_mgr.blockdevs_mut() {
bd.alloc_raid_meta(raid_meta_space());
// NOTE: over-allocates integrity metadata slightly. Some of the
// total size of the device will not make use of the integrity
// metadata.
Expand Down Expand Up @@ -142,7 +141,6 @@ impl DataTier<v2::StratBlockDev> {
.collect::<Vec<_>>();
assert_eq!(bds.len(), uuids.len());
for bd in bds {
bd.alloc_raid_meta(raid_meta_space());
bd.alloc_int_meta_back(integrity_meta_space(
// NOTE: Subtracting metadata size works here because the only metadata currently
// recorded in a newly created block device is the BDA. If this becomes untrue in
Expand Down
2 changes: 1 addition & 1 deletion src/engine/strat_engine/backstore/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ pub fn initialize_devices(

bda.initialize(&mut f)?;

v2::StratBlockDev::new(devno, bda, &[], &[], &[], None, hw_id, devnode).map_err(|(e, _)| e)
v2::StratBlockDev::new(devno, bda, &[], &[], None, hw_id, devnode).map_err(|(e, _)| e)
}

/// Clean up an unencrypted device after initialization failure.
Expand Down
2 changes: 1 addition & 1 deletion src/engine/strat_engine/backstore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod range_alloc;
mod shared;

pub use self::{
blockdev::v2::{integrity_meta_space, raid_meta_space},
blockdev::v2::integrity_meta_space,
devices::{find_stratis_devs_by_uuid, get_devno_from_path, ProcessedPathInfos, UnownedDevices},
};

Expand Down
2 changes: 0 additions & 2 deletions src/engine/strat_engine/liminal/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,6 @@ fn get_blockdev(
// conclusion is metadata corruption.
let segments = segment_table.get(&dev_uuid);
let meta = data_map.get(&dev_uuid);
let raid = meta.map(|base| &base.1.raid_meta_allocs);
let integrity = meta.map(|base| &base.1.integrity_meta_allocs);

assert_eq!(info.luks, None);
Expand All @@ -557,7 +556,6 @@ fn get_blockdev(
info.dev_info.device_number,
bda,
segments.unwrap_or(&vec![]),
raid.unwrap_or(&vec![]),
integrity.unwrap_or(&vec![]),
bd_save.user_info.clone(),
bd_save.hardware_info.clone(),
Expand Down
2 changes: 1 addition & 1 deletion src/engine/strat_engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mod writing;
pub use self::{backstore::ProcessedPathInfos, pool::v1::StratPool};

pub use self::{
backstore::{integrity_meta_space, raid_meta_space},
backstore::integrity_meta_space,
crypt::{
crypt_metadata_size, register_clevis_token, set_up_crypt_logging, CLEVIS_TANG_TRUST_URL,
},
Expand Down
3 changes: 0 additions & 3 deletions src/engine/strat_engine/serde_structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@ pub struct BaseBlockDevSave {
pub uuid: DevUuid,
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub raid_meta_allocs: Vec<(Sectors, Sectors)>,
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub integrity_meta_allocs: Vec<(Sectors, Sectors)>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(serialize_with = "serialize_option_string")]
Expand Down

0 comments on commit a055200

Please sign in to comment.