Skip to content

Commit

Permalink
Make MergeRequested property settable
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <amulhern@redhat.com>
  • Loading branch information
mulkieran committed Jul 24, 2024
1 parent c51b84a commit 017f330
Show file tree
Hide file tree
Showing 14 changed files with 216 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/dbus_api/filesystem/filesystem_3_7/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use dbus_tree::{Access, EmitsChangedSignal, Factory, MTSync, Property};

use crate::dbus_api::{
consts,
filesystem::filesystem_3_7::props::{get_fs_merge_scheduled, get_fs_origin},
filesystem::filesystem_3_7::props::{
get_fs_merge_scheduled, get_fs_origin, set_fs_merge_scheduled,
},
types::TData,
};

Expand All @@ -21,7 +23,8 @@ pub fn merge_scheduled_property(
f: &Factory<MTSync<TData>, TData>,
) -> Property<MTSync<TData>, TData> {
f.property::<bool, _>(consts::FILESYSTEM_MERGE_SCHEDULED_PROP, ())
.access(Access::Read)
.access(Access::ReadWrite)
.emits_changed(EmitsChangedSignal::True)
.on_get(get_fs_merge_scheduled)
.on_set(set_fs_merge_scheduled)
}
39 changes: 35 additions & 4 deletions src/dbus_api/filesystem/filesystem_3_7/props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

use dbus::arg::IterAppend;
use dbus::arg::{Iter, IterAppend};
use dbus_tree::{MTSync, MethodErr, PropInfo};

use crate::dbus_api::{
filesystem::shared::{self, get_filesystem_property},
types::TData,
use crate::{
dbus_api::{
consts,
filesystem::shared::{self, get_filesystem_property},
types::TData,
},
engine::PropChangeAction,
};

pub fn get_fs_origin(
Expand All @@ -23,3 +27,30 @@ pub fn get_fs_merge_scheduled(
) -> Result<(), MethodErr> {
get_filesystem_property(i, p, |(_, _, f)| Ok(shared::fs_merge_scheduled_prop(f)))
}

/// Set the merge scheduled property on a filesystem
pub fn set_fs_merge_scheduled(
i: &mut Iter<'_>,
p: &PropInfo<'_, MTSync<TData>, TData>,
) -> Result<(), MethodErr> {
let merge_scheduled: bool = i
.get()
.ok_or_else(|| MethodErr::failed("Value required as argument to set property"))?;

let res = shared::set_fs_property_to_display(
p,
consts::FILESYSTEM_MERGE_SCHEDULED_PROP,
|(_, uuid, p)| shared::set_fs_merge_scheduled_prop(uuid, p, merge_scheduled),
);

match res {
Ok(PropChangeAction::NewValue(v)) => {
p.tree
.get_data()
.push_fs_merge_scheduled_change(p.path.get_name(), v);
Ok(())
}
Ok(PropChangeAction::Identity) => Ok(()),
Err(e) => Err(e),
}
}
10 changes: 10 additions & 0 deletions src/dbus_api/filesystem/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,13 @@ pub fn fs_origin_prop(fs: &dyn Filesystem) -> (bool, String) {
pub fn fs_merge_scheduled_prop(fs: &dyn Filesystem) -> bool {
fs.merge_scheduled()
}

#[inline]
pub fn set_fs_merge_scheduled_prop(
uuid: FilesystemUuid,
pool: &mut dyn Pool,
schedule: bool,
) -> Result<PropChangeAction<bool>, String> {
pool.set_fs_merge_scheduled(uuid, schedule)
.map_err(|e| e.to_string())
}
24 changes: 24 additions & 0 deletions src/dbus_api/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,26 @@ impl DbusTreeHandler {
}
}

/// Send a signal indicating that the filesystem merge scheduled value has
/// changed.
fn handle_fs_merge_scheduled_change(&self, path: Path<'static>, new_scheduled: bool) {
if let Err(e) = self.property_changed_invalidated_signal(
&path,
prop_hashmap!(
consts::FILESYSTEM_INTERFACE_NAME_3_7 => {
Vec::new(),
consts::FILESYSTEM_MERGE_SCHEDULED_PROP.to_string() =>
box_variant!(new_scheduled)
}
),
) {
warn!(
"Failed to send a signal over D-Bus indicating filesystem merge scheduled value change: {}",
e
);
}
}

/// Send a signal indicating that the blockdev user info has changed.
fn handle_blockdev_user_info_change(&self, path: Path<'static>, new_user_info: Option<String>) {
let user_info_prop = blockdev_user_info_to_prop(new_user_info);
Expand Down Expand Up @@ -1254,6 +1274,10 @@ impl DbusTreeHandler {
self.handle_fs_size_limit_change(path, new_limit);
Ok(true)
}
DbusAction::FsMergeScheduledChange(path, new_scheduled) => {
self.handle_fs_merge_scheduled_change(path, new_scheduled);
Ok(true)
}
DbusAction::PoolOverprovModeChange(path, new_mode) => {
self.handle_pool_overprov_mode_change(path, new_mode);
Ok(true)
Expand Down
14 changes: 14 additions & 0 deletions src/dbus_api/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ pub enum DbusAction {
BlockdevTotalPhysicalSizeChange(Path<'static>, Sectors),
FsOriginChange(Path<'static>),
FsSizeLimitChange(Path<'static>, Option<Sectors>),
FsMergeScheduledChange(Path<'static>, bool),
FsBackgroundChange(
FilesystemUuid,
SignalChange<Option<Bytes>>,
Expand Down Expand Up @@ -498,6 +499,19 @@ impl DbusContext {
)
}
}

/// Send changed signal for pool MergeScheduled property.
pub fn push_fs_merge_scheduled_change(&self, item: &Path<'static>, new_merge_scheduled: bool) {
if let Err(e) = self.sender.send(DbusAction::FsMergeScheduledChange(
item.clone(),
new_merge_scheduled,
)) {
warn!(
"D-Bus filesystem merge scheduled change event could not be sent to the processing thread; no signal will be sent out for the merge scheduled change of filesystem with path {}: {}",
item, e,
)
}
}
}

#[derive(Debug)]
Expand Down
7 changes: 7 additions & 0 deletions src/engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,13 @@ pub trait Pool: Debug + Send + Sync {

/// Get the metadata version for a given pool.
fn metadata_version(&self) -> StratSigblockVersion;

/// Set whether a merge of the filesystem is scheduled.
fn set_fs_merge_scheduled(
&mut self,
fs: FilesystemUuid,
new_scheduled: bool,
) -> StratisResult<PropChangeAction<bool>>;
}

pub type HandleEvents<P> = (
Expand Down
11 changes: 11 additions & 0 deletions src/engine/sim_engine/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ impl SimFilesystem {
self.origin = None;
changed
}

/// Set the merge scheduled value for the filesystem.
pub fn set_merge_scheduled(&mut self, scheduled: bool) -> StratisResult<bool> {
if self.merge_scheduled == scheduled {
Ok(false)
} else {
// TODO: reject if conflict or no origin
self.merge_scheduled = scheduled;
Ok(true)
}
}
}

impl Filesystem for SimFilesystem {
Expand Down
16 changes: 16 additions & 0 deletions src/engine/sim_engine/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,22 @@ impl Pool for SimPool {
fn metadata_version(&self) -> StratSigblockVersion {
StratSigblockVersion::V2
}

fn set_fs_merge_scheduled(
&mut self,
fs_uuid: FilesystemUuid,
schedule: bool,
) -> StratisResult<PropChangeAction<bool>> {
let (_, fs) = self.filesystems.get_mut_by_uuid(fs_uuid).ok_or_else(|| {
StratisError::Msg(format!("Filesystem with UUID {fs_uuid} not found"))
})?;
let changed = fs.set_merge_scheduled(schedule)?;
if changed {
Ok(PropChangeAction::NewValue(schedule))
} else {
Ok(PropChangeAction::Identity)
}
}
}

#[cfg(test)]
Expand Down
11 changes: 11 additions & 0 deletions src/engine/strat_engine/pool/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,15 @@ impl Pool for AnyPool {
AnyPool::V2(p) => p.metadata_version(),
}
}

fn set_fs_merge_scheduled(
&mut self,
fs_uuid: FilesystemUuid,
new_scheduled: bool,
) -> StratisResult<PropChangeAction<bool>> {
match self {
AnyPool::V1(p) => p.set_fs_merge_scheduled(fs_uuid, new_scheduled),
AnyPool::V2(p) => p.set_fs_merge_scheduled(fs_uuid, new_scheduled),
}
}
}
19 changes: 19 additions & 0 deletions src/engine/strat_engine/pool/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,25 @@ impl Pool for StratPool {
fn metadata_version(&self) -> StratSigblockVersion {
StratSigblockVersion::V1
}

#[pool_mutating_action("NoRequests")]
fn set_fs_merge_scheduled(
&mut self,
fs_uuid: FilesystemUuid,
new_scheduled: bool,
) -> StratisResult<PropChangeAction<bool>> {
let (_, _) = self.get_filesystem(fs_uuid).ok_or_else(|| {
StratisError::Msg(format!("Filesystem with UUID {fs_uuid} not found"))
})?;
if self
.thin_pool
.set_fs_merge_scheduled(fs_uuid, new_scheduled)?
{
Ok(PropChangeAction::NewValue(new_scheduled))
} else {
Ok(PropChangeAction::Identity)
}
}
}

pub struct StratPoolState {
Expand Down
19 changes: 19 additions & 0 deletions src/engine/strat_engine/pool/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,25 @@ impl Pool for StratPool {
fn metadata_version(&self) -> StratSigblockVersion {
StratSigblockVersion::V2
}

#[pool_mutating_action("NoRequests")]
fn set_fs_merge_scheduled(
&mut self,
fs_uuid: FilesystemUuid,
new_scheduled: bool,
) -> StratisResult<PropChangeAction<bool>> {
let (_, _) = self.get_filesystem(fs_uuid).ok_or_else(|| {
StratisError::Msg(format!("Filesystem with UUID {fs_uuid} not found"))
})?;
if self
.thin_pool
.set_fs_merge_scheduled(fs_uuid, new_scheduled)?
{
Ok(PropChangeAction::NewValue(new_scheduled))
} else {
Ok(PropChangeAction::Identity)
}
}
}

pub struct StratPoolState {
Expand Down
11 changes: 11 additions & 0 deletions src/engine/strat_engine/thinpool/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,17 @@ impl StratFilesystem {
self.origin = None;
changed
}

/// Set the merge scheduled value for the filesystem.
pub fn set_merge_scheduled(&mut self, scheduled: bool) -> StratisResult<bool> {
if self.merge_scheduled == scheduled {
Ok(false)
} else {
// TODO: reject if conflict or no origin
self.merge_scheduled = scheduled;
Ok(true)
}
}
}

impl Filesystem for StratFilesystem {
Expand Down
21 changes: 21 additions & 0 deletions src/engine/strat_engine/thinpool/thinpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1715,6 +1715,27 @@ where
}
Ok(changed)
}

/// Set the filesystem merge scheduled value for filesystem with given UUID.
pub fn set_fs_merge_scheduled(
&mut self,
fs_uuid: FilesystemUuid,
scheduled: bool,
) -> StratisResult<bool> {
let changed = {
let (_, fs) = self.get_mut_filesystem_by_uuid(fs_uuid).ok_or_else(|| {
StratisError::Msg(format!("No filesystem with UUID {fs_uuid} found"))
})?;
fs.set_merge_scheduled(scheduled)?
};
let (name, fs) = self
.get_filesystem_by_uuid(fs_uuid)
.expect("Looked up above");
if changed {
self.mdv.save_fs(&name, fs_uuid, fs)?;
}
Ok(changed)
}
}

impl<'a, B> Into<Value> for &'a ThinPool<B> {
Expand Down
13 changes: 13 additions & 0 deletions src/engine/types/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,19 @@ where
}
}

impl ToDisplay for PropChangeAction<bool> {
type Display = PropChangeAction<String>;

fn to_display(&self) -> PropChangeAction<String> {
match self {
PropChangeAction::Identity => PropChangeAction::Identity,
PropChangeAction::NewValue(v) => {
PropChangeAction::NewValue(format!("a value of {}", v))
}
}
}
}

impl<T> Display for PropChangeAction<T>
where
T: Display,
Expand Down

0 comments on commit 017f330

Please sign in to comment.