Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose sectors allocated and real size of block device on the D-Bus #2647

Draft
wants to merge 5 commits into
base: develop-2.4.2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/dbus_api/blockdev/fetch_properties_3_0/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ 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; 3] = [
consts::BLOCKDEV_TOTAL_SIZE_PROP,
consts::BLOCKDEV_TOTAL_SIZE_ALLOCATED_PROP,
consts::BLOCKDEV_TOTAL_REAL_SIZE_PROP,
];

fn get_properties_shared(
m: &MethodInfo<MTSync<TData>, TData>,
Expand All @@ -37,6 +41,22 @@ 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()),
)),
)),
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();
Expand Down
2 changes: 2 additions & 0 deletions src/dbus_api/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ 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";
pub const BLOCKDEV_TOTAL_REAL_SIZE_PROP: &str = "TotalPhysicalRealSize";

/// Get a list of all the FetchProperties interfaces
pub fn fetch_properties_interfaces() -> Vec<String> {
Expand Down
7 changes: 7 additions & 0 deletions src/engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ 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;

/// 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 {
Expand Down
8 changes: 8 additions & 0 deletions src/engine/sim_engine/blockdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ impl BlockDev for SimDev {
fn is_encrypted(&self) -> bool {
self.encryption_info.is_some()
}

fn allocated(&self) -> Sectors {
Bytes::from(IEC::Mi).sectors()
}

fn real_size(&self) -> Sectors {
2usize * Bytes::from(IEC::Gi).sectors()
}
}

impl SimDev {
Expand Down
12 changes: 12 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 Expand Up @@ -340,6 +344,14 @@ impl BlockDev for StratBlockDev {
fn is_encrypted(&self) -> bool {
self.encryption_info().is_some()
}

fn allocated(&self) -> Sectors {
self.used.used()
}

fn real_size(&self) -> Sectors {
self.real_size.sectors()
}
}

impl Recordable<BaseBlockDevSave> for StratBlockDev {
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