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 Jun 8, 2021
1 parent dd22674 commit 9e826c0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/dbus_api/blockdev/fetch_properties_2_5/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] = [
const ALL_PROPERTIES: [&str; 3] = [
consts::BLOCKDEV_TOTAL_SIZE_PROP,
consts::BLOCKDEV_TOTAL_SIZE_ALLOCATED_PROP,
consts::BLOCKDEV_TOTAL_REAL_SIZE_PROP,
];

#[allow(unknown_lints)]
Expand Down Expand Up @@ -50,6 +51,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 @@ -69,6 +69,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 @@ -109,6 +109,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 @@ -73,6 +73,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 @@ -309,6 +309,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 9e826c0

Please sign in to comment.