Skip to content

Commit

Permalink
Send blockdev 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 6, 2023
1 parent 3acbae8 commit 5c21210
Show file tree
Hide file tree
Showing 4 changed files with 85 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()
}
11 changes: 9 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},
};

pub fn grow_physical(m: &MethodInfo<'_, MTSync<TData>, TData>) -> MethodResult {
Expand Down Expand Up @@ -53,7 +53,14 @@ 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(_)) => {
dbus_context.push_blockdev_total_physical_size_change(
pool_path.get_name(),
pool.total_physical_size(),
);
true
}
Err(err) => {
let (rc, rs) = engine_to_dbus_err_tuple(&err);
return Ok(vec![return_message.append3(default_return, rc, rs)]);
Expand Down
50 changes: 49 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 @@ -857,6 +860,47 @@ 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_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 @@ -1125,6 +1169,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 5c21210

Please sign in to comment.