Skip to content

Commit

Permalink
Expose real size on the D-Bus
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 ce54afc commit 7b3c06a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/dbus_api/blockdev/fetch_properties_3_0/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/dbus_api/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
Expand Down
4 changes: 4 additions & 0 deletions src/engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/engine/sim_engine/blockdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
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 @@ -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<BaseBlockDevSave> for StratBlockDev {
Expand Down

0 comments on commit 7b3c06a

Please sign in to comment.