Skip to content

Commit

Permalink
Send blockdev and pool change signal on grow physical
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Jul 10, 2023
1 parent 8bae503 commit 49351f9
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/dbus_api/blockdev/prop_conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ pub fn blockdev_new_size_to_prop(new_size: Option<Sectors>) -> (bool, String) {
pub fn blockdev_user_info_to_prop(user_info: Option<String>) -> (bool, String) {
option_to_tuple(user_info, String::new())
}

/// Generate D-Bus representation of block device total physical size property.
#[inline]
pub fn blockdev_total_physical_size_to_prop(total_physical_size: Sectors) -> String {
(*total_physical_size.bytes()).to_string()
}
34 changes: 32 additions & 2 deletions src/dbus_api/pool/pool_3_3/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
types::{DbusErrorEnum, TData, OK_STRING},
util::{engine_to_dbus_err_tuple, get_next_arg},
},
engine::{DevUuid, EngineAction},
engine::{DevUuid, GrowAction, StratisUuid},
};

pub fn grow_physical(m: &MethodInfo<'_, MTSync<TData>, TData>) -> MethodResult {
Expand Down Expand Up @@ -53,7 +53,37 @@ pub fn grow_physical(m: &MethodInfo<'_, MTSync<TData>, TData>) -> MethodResult {
);

let ret = match result {
Ok(grown) => grown.is_changed(),
Ok(GrowAction::Identity) => false,
Ok(GrowAction::Grown((_, dev_uuid))) => {
match m.tree.iter().find(|op| {
op.get_data()
.as_ref()
.map(|data| match data.uuid {
StratisUuid::Dev(uuid) => uuid == dev_uuid,
_ => false,
})
.unwrap_or(false)
}) {
Some(op) => {
let dev_total_physical_size = pool
.get_blockdev(dev_uuid)
.expect("dev_uuid is the UUID of the blockdev that was just expanded; it must be in pool")
.1
.size();
dbus_context.push_blockdev_total_physical_size_change(
op.get_name(),
dev_total_physical_size,
);
}
None => {
warn!("Could not find object path for blockdev uuid {dev_uuid}; no property changed signal requested");
}
}

dbus_context.push_pool_size_change(object_path, pool.total_physical_size().bytes());

true
}
Err(err) => {
let (rc, rs) = engine_to_dbus_err_tuple(&err);
return Ok(vec![return_message.append3(default_return, rc, rs)]);
Expand Down
65 changes: 64 additions & 1 deletion src/dbus_api/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ use devicemapper::{Bytes, Sectors};
use crate::{
dbus_api::{
api::prop_conv::{locked_pools_to_prop, stopped_pools_to_prop},
blockdev::prop_conv::{blockdev_new_size_to_prop, blockdev_user_info_to_prop},
blockdev::prop_conv::{
blockdev_new_size_to_prop, blockdev_total_physical_size_to_prop,
blockdev_user_info_to_prop,
},
consts,
filesystem::prop_conv::{fs_size_to_prop, fs_used_to_prop},
pool::prop_conv::{
Expand Down Expand Up @@ -847,6 +850,62 @@ impl DbusTreeHandler {
}
}

/// Send a signal indicating that the blockdev total physical size has
/// changed.
fn handle_blockdev_total_physical_size_change(
&self,
path: Path<'static>,
new_total_physical_size: Sectors,
) {
let total_physical_size_prop =
blockdev_total_physical_size_to_prop(new_total_physical_size);
if let Err(e) = self.property_changed_invalidated_signal(
&path,
prop_hashmap!(
consts::BLOCKDEV_INTERFACE_NAME_3_0 => {
Vec::new(),
consts::BLOCKDEV_TOTAL_SIZE_PROP.to_string() =>
box_variant!(total_physical_size_prop.clone())
},
consts::BLOCKDEV_INTERFACE_NAME_3_1 => {
Vec::new(),
consts::BLOCKDEV_TOTAL_SIZE_PROP.to_string() =>
box_variant!(total_physical_size_prop.clone())
},
consts::BLOCKDEV_INTERFACE_NAME_3_2 => {
Vec::new(),
consts::BLOCKDEV_TOTAL_SIZE_PROP.to_string() =>
box_variant!(total_physical_size_prop.clone())
},
consts::BLOCKDEV_INTERFACE_NAME_3_3 => {
Vec::new(),
consts::BLOCKDEV_TOTAL_SIZE_PROP.to_string() =>
box_variant!(total_physical_size_prop.clone())
},
consts::BLOCKDEV_INTERFACE_NAME_3_4 => {
Vec::new(),
consts::BLOCKDEV_TOTAL_SIZE_PROP.to_string() =>
box_variant!(total_physical_size_prop.clone())
},
consts::BLOCKDEV_INTERFACE_NAME_3_5 => {
Vec::new(),
consts::BLOCKDEV_TOTAL_SIZE_PROP.to_string() =>
box_variant!(total_physical_size_prop.clone())
},
consts::BLOCKDEV_INTERFACE_NAME_3_6 => {
Vec::new(),
consts::BLOCKDEV_TOTAL_SIZE_PROP.to_string() =>
box_variant!(total_physical_size_prop)
}
),
) {
warn!(
"Failed to send a signal over D-Bus indicating blockdev total physical size change: {}",
e
);
}
}

/// Send a signal indicating that the pool overprovisioning mode has changed.
fn handle_pool_overprov_mode_change(&self, path: Path<'static>, new_mode: bool) {
if let Err(e) = self.property_changed_invalidated_signal(
Expand Down Expand Up @@ -1115,6 +1174,10 @@ impl DbusTreeHandler {
self.handle_blockdev_user_info_change(path, new_user_info);
Ok(true)
}
DbusAction::BlockdevTotalPhysicalSizeChange(path, new_total_physical_size) => {
self.handle_blockdev_total_physical_size_change(path, new_total_physical_size);
Ok(true)
}
DbusAction::PoolForegroundChange(item, new_used, new_alloc, new_size, new_no_space) => {
self.handle_pool_foreground_change(
item,
Expand Down
22 changes: 21 additions & 1 deletion src/dbus_api/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub enum DbusAction {
LockedPoolsChange(LockedPoolsInfo),
StoppedPoolsChange(StoppedPoolsInfo),
BlockdevUserInfoChange(Path<'static>, Option<String>),

BlockdevTotalPhysicalSizeChange(Path<'static>, Sectors),
FsBackgroundChange(
FilesystemUuid,
SignalChange<Option<Bytes>>,
Expand Down Expand Up @@ -445,6 +445,26 @@ impl DbusContext {
}
}

/// Send changed signal for changed blockdev total size property.
pub fn push_blockdev_total_physical_size_change(
&self,
path: &Path<'static>,
total_physical_size: Sectors,
) {
if let Err(e) = self
.sender
.send(DbusAction::BlockdevTotalPhysicalSizeChange(
path.clone(),
total_physical_size,
))
{
warn!(
"Block device total physical size change event could not be sent to the processing thread; no signal will be sent out for the block device total physical size state change: {}",
e,
)
}
}

/// Send changed signal for changed pool properties when blockdevs are
/// added.
pub fn push_pool_foreground_change(
Expand Down

0 comments on commit 49351f9

Please sign in to comment.