Skip to content

Commit

Permalink
Store the real size in the StratBlockdev on setup
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Aug 20, 2021
1 parent 027ee34 commit ce54afc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/engine/strat_engine/backstore/blockdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub struct StratBlockDev {
user_info: Option<String>,
hardware_info: Option<String>,
underlying_device: UnderlyingDevice,
real_size: BlockdevSize,
}

impl StratBlockDev {
Expand All @@ -95,13 +96,15 @@ impl StratBlockDev {
///
/// Precondition: segments in other_segments do not overlap with Stratis
/// metadata region.
#[allow(clippy::too_many_arguments)]
pub fn new(
dev: Device,
bda: BDA,
other_segments: &[(Sectors, Sectors)],
user_info: Option<String>,
hardware_info: Option<String>,
underlying_device: UnderlyingDevice,
real_size: BlockdevSize,
) -> StratisResult<StratBlockDev> {
let mut segments = vec![(Sectors(0), bda.extended_size().sectors())];
segments.extend(other_segments);
Expand All @@ -115,6 +118,7 @@ impl StratBlockDev {
user_info,
hardware_info,
underlying_device,
real_size,
})
}

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 @@ -473,7 +473,7 @@ pub fn initialize_devices(

bda.initialize(&mut f)?;

StratBlockDev::new(devno, bda, &[], None, hw_id, underlying_device)
StratBlockDev::new(devno, bda, &[], None, hw_id, underlying_device, data_size)
}

/// Clean up an encrypted device after initialization failure.
Expand Down
12 changes: 6 additions & 6 deletions src/engine/strat_engine/liminal/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
backstore::{CryptHandle, StratBlockDev, UnderlyingDevice},
device::blkdev_size,
liminal::device_info::LStratisInfo,
metadata::{StaticHeader, BDA},
metadata::{BlockdevSize, StaticHeader, BDA},
serde_structs::{BackstoreSave, BaseBlockDevSave, PoolSave},
},
types::{ActionAvailability, BlockDevTier, DevUuid, DevicePath, PoolEncryptionInfo},
Expand Down Expand Up @@ -200,8 +200,8 @@ pub fn get_blockdevs(
// Return an error if apparent size of Stratis block device appears to
// have decreased since metadata was recorded or if size of block
// device could not be obtained.
blkdev_size(&OpenOptions::new().read(true).open(&info.ids.devnode)?).and_then(
|actual_size| {
let real_size = blkdev_size(&OpenOptions::new().read(true).open(&info.ids.devnode)?)
.and_then(|actual_size| {
let actual_size_sectors = actual_size.sectors();
let recorded_size = bda.dev_size().sectors();
if actual_size_sectors < recorded_size {
Expand All @@ -213,10 +213,9 @@ pub fn get_blockdevs(
);
Err(StratisError::Msg(err_msg))
} else {
Ok(())
Ok(BlockdevSize::new(actual_size.sectors()))
}
},
)?;
})?;

let dev_uuid = bda.dev_uuid();

Expand Down Expand Up @@ -261,6 +260,7 @@ pub fn get_blockdevs(
Some(handle) => UnderlyingDevice::Encrypted(handle),
None => UnderlyingDevice::Unencrypted(DevicePath::new(physical_path)?),
},
real_size,
)?,
))
}
Expand Down

0 comments on commit ce54afc

Please sign in to comment.