From 9a676e91c1be67ce2eddf13efe8c69aa94200ba8 Mon Sep 17 00:00:00 2001 From: mulhern Date: Mon, 7 Jun 2021 18:11:37 -0400 Subject: [PATCH 1/5] Expose used information from the blockdev Signed-off-by: mulhern --- src/engine/strat_engine/backstore/blockdev.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/engine/strat_engine/backstore/blockdev.rs b/src/engine/strat_engine/backstore/blockdev.rs index 36fc919d38..2c4c61bb25 100644 --- a/src/engine/strat_engine/backstore/blockdev.rs +++ b/src/engine/strat_engine/backstore/blockdev.rs @@ -199,6 +199,11 @@ impl StratBlockDev { self.used.available() } + /// The number of Sectors on this device which have been allocated. + pub fn used(&self) -> Sectors { + self.used.used() + } + /// The total size of the Stratis block device. pub fn total_size(&self) -> BlockdevSize { let size = self.used.size(); From 88f30b511b1a804e713b2b573694fe5af224f277 Mon Sep 17 00:00:00 2001 From: mulhern Date: Mon, 7 Jun 2021 18:15:41 -0400 Subject: [PATCH 2/5] Expose the allocated information for the block device Signed-off-by: mulhern --- src/engine/engine.rs | 3 +++ src/engine/sim_engine/blockdev.rs | 4 ++++ src/engine/strat_engine/backstore/blockdev.rs | 9 ++++----- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/engine/engine.rs b/src/engine/engine.rs index f318278274..cff7c6fb01 100644 --- a/src/engine/engine.rs +++ b/src/engine/engine.rs @@ -103,6 +103,9 @@ pub trait BlockDev: Debug { /// Get the status of whether a block device is encrypted or not. fn is_encrypted(&self) -> bool; + + /// The total number of sectors allocated from this block device + fn allocated(&self) -> Sectors; } pub trait Pool: Debug { diff --git a/src/engine/sim_engine/blockdev.rs b/src/engine/sim_engine/blockdev.rs index 067a7e5b18..485d348a5d 100644 --- a/src/engine/sim_engine/blockdev.rs +++ b/src/engine/sim_engine/blockdev.rs @@ -59,6 +59,10 @@ impl BlockDev for SimDev { fn is_encrypted(&self) -> bool { self.encryption_info.is_some() } + + fn allocated(&self) -> Sectors { + Bytes::from(IEC::Mi).sectors() + } } impl SimDev { diff --git a/src/engine/strat_engine/backstore/blockdev.rs b/src/engine/strat_engine/backstore/blockdev.rs index 2c4c61bb25..0c2e26ab06 100644 --- a/src/engine/strat_engine/backstore/blockdev.rs +++ b/src/engine/strat_engine/backstore/blockdev.rs @@ -199,11 +199,6 @@ impl StratBlockDev { self.used.available() } - /// The number of Sectors on this device which have been allocated. - pub fn used(&self) -> Sectors { - self.used.used() - } - /// The total size of the Stratis block device. pub fn total_size(&self) -> BlockdevSize { let size = self.used.size(); @@ -345,6 +340,10 @@ impl BlockDev for StratBlockDev { fn is_encrypted(&self) -> bool { self.encryption_info().is_some() } + + fn allocated(&self) -> Sectors { + self.used.used() + } } impl Recordable for StratBlockDev { From 027ee342b1da2943b602d64d10d481cd15744f15 Mon Sep 17 00:00:00 2001 From: mulhern Date: Mon, 7 Jun 2021 18:27:59 -0400 Subject: [PATCH 3/5] Export the value via a newly added FetchProperties key Signed-off-by: mulhern --- .../blockdev/fetch_properties_3_0/methods.rs | 13 ++++++++++++- src/dbus_api/consts.rs | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/dbus_api/blockdev/fetch_properties_3_0/methods.rs b/src/dbus_api/blockdev/fetch_properties_3_0/methods.rs index fcec2be93e..702f1d97ff 100644 --- a/src/dbus_api/blockdev/fetch_properties_3_0/methods.rs +++ b/src/dbus_api/blockdev/fetch_properties_3_0/methods.rs @@ -15,7 +15,10 @@ use crate::dbus_api::{ blockdev::shared::blockdev_operation, consts, types::TData, util::result_to_tuple, }; -const ALL_PROPERTIES: [&str; 1] = [consts::BLOCKDEV_TOTAL_SIZE_PROP]; +const ALL_PROPERTIES: [&str; 2] = [ + consts::BLOCKDEV_TOTAL_SIZE_ALLOCATED_PROP, + consts::BLOCKDEV_TOTAL_SIZE_PROP, +]; fn get_properties_shared( m: &MethodInfo, TData>, @@ -37,6 +40,14 @@ fn get_properties_shared( |_, bd| Ok((*bd.size().bytes()).to_string()), )), )), + consts::BLOCKDEV_TOTAL_SIZE_ALLOCATED_PROP => Some(( + prop, + result_to_tuple(blockdev_operation( + m.tree, + object_path.get_name(), + |_, bd| Ok((*bd.allocated().bytes()).to_string()), + )), + )), _ => None, }) .collect(); diff --git a/src/dbus_api/consts.rs b/src/dbus_api/consts.rs index 8cd331246b..2609d1af38 100644 --- a/src/dbus_api/consts.rs +++ b/src/dbus_api/consts.rs @@ -46,6 +46,7 @@ pub const BLOCKDEV_TIER_PROP: &str = "Tier"; pub const BLOCKDEV_PHYSICAL_PATH_PROP: &str = "PhysicalPath"; pub const BLOCKDEV_TOTAL_SIZE_PROP: &str = "TotalPhysicalSize"; +pub const BLOCKDEV_TOTAL_SIZE_ALLOCATED_PROP: &str = "TotalPhysicalSizeAllocated"; /// Get a list of all the FetchProperties interfaces pub fn fetch_properties_interfaces() -> Vec { From ce54afcd33e76222892648d60dc9d4f39914e4d6 Mon Sep 17 00:00:00 2001 From: mulhern Date: Tue, 8 Jun 2021 08:32:51 -0400 Subject: [PATCH 4/5] Store the real size in the StratBlockdev on setup Signed-off-by: mulhern --- src/engine/strat_engine/backstore/blockdev.rs | 4 ++++ src/engine/strat_engine/backstore/devices.rs | 2 +- src/engine/strat_engine/liminal/setup.rs | 12 ++++++------ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/engine/strat_engine/backstore/blockdev.rs b/src/engine/strat_engine/backstore/blockdev.rs index 0c2e26ab06..ee37f7371d 100644 --- a/src/engine/strat_engine/backstore/blockdev.rs +++ b/src/engine/strat_engine/backstore/blockdev.rs @@ -71,6 +71,7 @@ pub struct StratBlockDev { user_info: Option, hardware_info: Option, underlying_device: UnderlyingDevice, + real_size: BlockdevSize, } impl StratBlockDev { @@ -95,6 +96,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, bda: BDA, @@ -102,6 +104,7 @@ impl StratBlockDev { user_info: Option, hardware_info: Option, underlying_device: UnderlyingDevice, + real_size: BlockdevSize, ) -> StratisResult { let mut segments = vec![(Sectors(0), bda.extended_size().sectors())]; segments.extend(other_segments); @@ -115,6 +118,7 @@ impl StratBlockDev { user_info, hardware_info, underlying_device, + real_size, }) } diff --git a/src/engine/strat_engine/backstore/devices.rs b/src/engine/strat_engine/backstore/devices.rs index fa387b0bd0..d5a0e38e25 100644 --- a/src/engine/strat_engine/backstore/devices.rs +++ b/src/engine/strat_engine/backstore/devices.rs @@ -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. diff --git a/src/engine/strat_engine/liminal/setup.rs b/src/engine/strat_engine/liminal/setup.rs index fc80ce8106..7766e9011b 100644 --- a/src/engine/strat_engine/liminal/setup.rs +++ b/src/engine/strat_engine/liminal/setup.rs @@ -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}, @@ -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 { @@ -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(); @@ -261,6 +260,7 @@ pub fn get_blockdevs( Some(handle) => UnderlyingDevice::Encrypted(handle), None => UnderlyingDevice::Unencrypted(DevicePath::new(physical_path)?), }, + real_size, )?, )) } From 7b3c06adb92d93478aab36099aa7103b6bd1e722 Mon Sep 17 00:00:00 2001 From: mulhern Date: Tue, 8 Jun 2021 08:58:17 -0400 Subject: [PATCH 5/5] Expose real size on the D-Bus Signed-off-by: mulhern --- .../blockdev/fetch_properties_3_0/methods.rs | 13 +++++++++++-- src/dbus_api/consts.rs | 1 + src/engine/engine.rs | 4 ++++ src/engine/sim_engine/blockdev.rs | 4 ++++ src/engine/strat_engine/backstore/blockdev.rs | 4 ++++ 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/dbus_api/blockdev/fetch_properties_3_0/methods.rs b/src/dbus_api/blockdev/fetch_properties_3_0/methods.rs index 702f1d97ff..ddb6164056 100644 --- a/src/dbus_api/blockdev/fetch_properties_3_0/methods.rs +++ b/src/dbus_api/blockdev/fetch_properties_3_0/methods.rs @@ -15,9 +15,10 @@ use crate::dbus_api::{ blockdev::shared::blockdev_operation, consts, types::TData, util::result_to_tuple, }; -const ALL_PROPERTIES: [&str; 2] = [ - consts::BLOCKDEV_TOTAL_SIZE_ALLOCATED_PROP, +const ALL_PROPERTIES: [&str; 3] = [ consts::BLOCKDEV_TOTAL_SIZE_PROP, + consts::BLOCKDEV_TOTAL_SIZE_ALLOCATED_PROP, + consts::BLOCKDEV_TOTAL_REAL_SIZE_PROP, ]; fn get_properties_shared( @@ -48,6 +49,14 @@ fn get_properties_shared( |_, bd| Ok((*bd.allocated().bytes()).to_string()), )), )), + consts::BLOCKDEV_TOTAL_REAL_SIZE_PROP => Some(( + prop, + result_to_tuple(blockdev_operation( + m.tree, + object_path.get_name(), + |_, bd| Ok((*bd.real_size().bytes()).to_string()), + )), + )), _ => None, }) .collect(); diff --git a/src/dbus_api/consts.rs b/src/dbus_api/consts.rs index 2609d1af38..26b0c62d07 100644 --- a/src/dbus_api/consts.rs +++ b/src/dbus_api/consts.rs @@ -47,6 +47,7 @@ pub const BLOCKDEV_PHYSICAL_PATH_PROP: &str = "PhysicalPath"; pub const BLOCKDEV_TOTAL_SIZE_PROP: &str = "TotalPhysicalSize"; pub const BLOCKDEV_TOTAL_SIZE_ALLOCATED_PROP: &str = "TotalPhysicalSizeAllocated"; +pub const BLOCKDEV_TOTAL_REAL_SIZE_PROP: &str = "TotalPhysicalRealSize"; /// Get a list of all the FetchProperties interfaces pub fn fetch_properties_interfaces() -> Vec { diff --git a/src/engine/engine.rs b/src/engine/engine.rs index cff7c6fb01..dd4f5287eb 100644 --- a/src/engine/engine.rs +++ b/src/engine/engine.rs @@ -106,6 +106,10 @@ pub trait BlockDev: Debug { /// The total number of sectors allocated from this block device fn allocated(&self) -> Sectors; + + /// The real size of this block device in sectors. Greater than or equal + /// to the value of size. + fn real_size(&self) -> Sectors; } pub trait Pool: Debug { diff --git a/src/engine/sim_engine/blockdev.rs b/src/engine/sim_engine/blockdev.rs index 485d348a5d..ad3cd116b4 100644 --- a/src/engine/sim_engine/blockdev.rs +++ b/src/engine/sim_engine/blockdev.rs @@ -63,6 +63,10 @@ impl BlockDev for SimDev { fn allocated(&self) -> Sectors { Bytes::from(IEC::Mi).sectors() } + + fn real_size(&self) -> Sectors { + 2usize * Bytes::from(IEC::Gi).sectors() + } } impl SimDev { diff --git a/src/engine/strat_engine/backstore/blockdev.rs b/src/engine/strat_engine/backstore/blockdev.rs index ee37f7371d..2bc80ae2f4 100644 --- a/src/engine/strat_engine/backstore/blockdev.rs +++ b/src/engine/strat_engine/backstore/blockdev.rs @@ -348,6 +348,10 @@ impl BlockDev for StratBlockDev { fn allocated(&self) -> Sectors { self.used.used() } + + fn real_size(&self) -> Sectors { + self.real_size.sectors() + } } impl Recordable for StratBlockDev {