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 Jun 8, 2021
1 parent 7e50154 commit dd22674
Show file tree
Hide file tree
Showing 3 changed files with 20 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 @@ -41,6 +41,7 @@ pub struct StratBlockDev {
user_info: Option<String>,
hardware_info: Option<String>,
crypt_handle: Option<CryptHandle>,
real_size: BlockdevSize,
}

impl StratBlockDev {
Expand All @@ -65,6 +66,7 @@ impl StratBlockDev {
///
/// Precondition: segments in other_segments do not overlap with Stratis
/// metadata region.
#[allow(clippy::too_many_arguments)]
pub fn new(
dev: Device,
devnode: &Path,
Expand All @@ -73,6 +75,7 @@ impl StratBlockDev {
user_info: Option<String>,
hardware_info: Option<String>,
crypt_handle: Option<CryptHandle>,
real_size: BlockdevSize,
) -> StratisResult<StratBlockDev> {
let mut segments = vec![(Sectors(0), bda.extended_size().sectors())];
segments.extend(other_segments);
Expand All @@ -90,6 +93,7 @@ impl StratBlockDev {
user_info,
hardware_info,
crypt_handle,
real_size,
})
}

Expand Down
11 changes: 10 additions & 1 deletion src/engine/strat_engine/backstore/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,16 @@ pub fn initialize_devices(

bda.initialize(&mut f)?;

StratBlockDev::new(devno, physical_path, bda, &[], None, hw_id, crypt_handle)
StratBlockDev::new(
devno,
physical_path,
bda,
&[],
None,
hw_id,
crypt_handle,
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},
device::blkdev_size,
liminal::device_info::LStratisInfo,
metadata::{StaticHeader, BDA},
metadata::{BlockdevSize, StaticHeader, BDA},
serde_structs::{BackstoreSave, BaseBlockDevSave, PoolSave},
},
types::{BlockDevTier, DevUuid},
Expand Down Expand Up @@ -201,8 +201,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 @@ -214,10 +214,9 @@ pub fn get_blockdevs(
);
Err(StratisError::Engine(ErrorEnum::Error, err_msg))
} else {
Ok(())
Ok(BlockdevSize::new(actual_size.sectors()))
}
},
)?;
})?;

let dev_uuid = bda.dev_uuid();

Expand Down Expand Up @@ -260,6 +259,7 @@ pub fn get_blockdevs(
bd_save.user_info.clone(),
bd_save.hardware_info.clone(),
handle,
real_size,
)?,
))
}
Expand Down

0 comments on commit dd22674

Please sign in to comment.