Skip to content

Commit

Permalink
Allocate space for md-raid
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaublitz committed Apr 18, 2024
1 parent bfe55f3 commit 34cf968
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
17 changes: 17 additions & 0 deletions src/engine/strat_engine/backstore/blockdev/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ pub fn integrity_meta_space(total_space: Sectors) -> Sectors {
+ Bytes::from((*total_space * 32u64 + 4095) & !4096).sectors()
}

/// Return the amount of space required for integrity 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 Down Expand Up @@ -174,6 +182,14 @@ 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 @@ -240,6 +256,7 @@ 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
11 changes: 7 additions & 4 deletions src/engine/strat_engine/backstore/data_tier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ use crate::{
engine::{
strat_engine::{
backstore::{
blockdev::{v1, v2, InternalBlockDev},
blockdev::{
v1,
v2::{self, integrity_meta_space, raid_meta_space},
InternalBlockDev,
},
blockdevmgr::BlockDevMgr,
devices::UnownedDevices,
shared::{metadata_to_segment, AllocatedAbove, BlkDevSegment, BlockDevPartition},
Expand All @@ -28,8 +32,6 @@ use crate::{
stratis::StratisResult,
};

use super::blockdev::v2::integrity_meta_space;

/// Handles the lowest level, base layer of this tier.
#[derive(Debug)]
pub struct DataTier<B> {
Expand Down Expand Up @@ -105,12 +107,13 @@ 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());
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
// the future, this code will no longer work.
bd.total_size().sectors() - bd.metadata_size(),
))
));
}
DataTier {
block_mgr,
Expand Down

0 comments on commit 34cf968

Please sign in to comment.