Skip to content

Commit

Permalink
Add MergeRequested property to filesystem
Browse files Browse the repository at this point in the history
Use it to set and unset the filesystem metadata.

Signed-off-by: mulhern <amulhern@redhat.com>
  • Loading branch information
mulkieran committed Aug 13, 2024
1 parent bde85e6 commit e44d40e
Show file tree
Hide file tree
Showing 17 changed files with 257 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/dbus_api/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub const FILESYSTEM_CREATED_PROP: &str = "Created";
pub const FILESYSTEM_SIZE_PROP: &str = "Size";
pub const FILESYSTEM_SIZE_LIMIT_PROP: &str = "SizeLimit";
pub const FILESYSTEM_ORIGIN_PROP: &str = "Origin";
pub const FILESYSTEM_MERGE_SCHEDULED_PROP: &str = "MergeScheduled";

pub const BLOCKDEV_INTERFACE_NAME_3_0: &str = "org.storage.stratis3.blockdev.r0";
pub const BLOCKDEV_INTERFACE_NAME_3_1: &str = "org.storage.stratis3.blockdev.r1";
Expand Down
18 changes: 17 additions & 1 deletion src/dbus_api/filesystem/filesystem_3_7/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,27 @@

use dbus_tree::{Access, EmitsChangedSignal, Factory, MTSync, Property};

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

pub fn origin_property(f: &Factory<MTSync<TData>, TData>) -> Property<MTSync<TData>, TData> {
f.property::<(bool, String), _>(consts::FILESYSTEM_ORIGIN_PROP, ())
.access(Access::Read)
.emits_changed(EmitsChangedSignal::True)
.on_get(get_fs_origin)
}

pub fn merge_scheduled_property(
f: &Factory<MTSync<TData>, TData>,
) -> Property<MTSync<TData>, TData> {
f.property::<bool, _>(consts::FILESYSTEM_MERGE_SCHEDULED_PROP, ())
.access(Access::ReadWrite)
.emits_changed(EmitsChangedSignal::True)
.on_get(get_fs_merge_scheduled)
.on_set(set_fs_merge_scheduled)
}
2 changes: 1 addition & 1 deletion src/dbus_api/filesystem/filesystem_3_7/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
mod api;
mod props;

pub use api::origin_property;
pub use api::{merge_scheduled_property, origin_property};
46 changes: 42 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 @@ -16,3 +20,37 @@ pub fn get_fs_origin(
) -> Result<(), MethodErr> {
get_filesystem_property(i, p, |(_, _, f)| Ok(shared::fs_origin_prop(f)))
}

pub fn get_fs_merge_scheduled(
i: &mut IterAppend<'_>,
p: &PropInfo<'_, MTSync<TData>, TData>,
) -> 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),
}
}
6 changes: 4 additions & 2 deletions src/dbus_api/filesystem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ pub fn create_dbus_filesystem<'a>(
.add_p(filesystem_3_0::size_property(&f))
.add_p(filesystem_3_0::used_property(&f))
.add_p(filesystem_3_6::size_limit_property(&f))
.add_p(filesystem_3_7::origin_property(&f)),
.add_p(filesystem_3_7::origin_property(&f))
.add_p(filesystem_3_7::merge_scheduled_property(&f)),
);

let path = object_path.get_name().to_owned();
Expand Down Expand Up @@ -217,7 +218,8 @@ pub fn get_fs_properties(
consts::FILESYSTEM_SIZE_PROP => shared::fs_size_prop(fs),
consts::FILESYSTEM_USED_PROP => shared::fs_used_prop(fs),
consts::FILESYSTEM_SIZE_LIMIT_PROP => shared::fs_size_limit_prop(fs),
consts::FILESYSTEM_ORIGIN_PROP => shared::fs_origin_prop(fs)
consts::FILESYSTEM_ORIGIN_PROP => shared::fs_origin_prop(fs),
consts::FILESYSTEM_MERGE_SCHEDULED_PROP => shared::fs_merge_scheduled_prop(fs)
}
}
}
15 changes: 15 additions & 0 deletions src/dbus_api/filesystem/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,18 @@ pub fn fs_used_prop(fs: &dyn Filesystem) -> (bool, String) {
pub fn fs_origin_prop(fs: &dyn Filesystem) -> (bool, String) {
prop_conv::fs_origin_to_prop(fs.origin())
}

/// Generate D-Bus representation of merge scheduled property
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
9 changes: 9 additions & 0 deletions src/engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ pub trait Filesystem: Debug {

/// Get filesystem snapshot origin.
fn origin(&self) -> Option<FilesystemUuid>;

fn merge_scheduled(&self) -> bool;
}

pub trait BlockDev: Debug {
Expand Down Expand Up @@ -350,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
17 changes: 17 additions & 0 deletions src/engine/sim_engine/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct SimFilesystem {
size: Sectors,
size_limit: Option<Sectors>,
origin: Option<FilesystemUuid>,
merge_scheduled: bool,
}

impl SimFilesystem {
Expand All @@ -42,6 +43,7 @@ impl SimFilesystem {
size,
size_limit,
origin,
merge_scheduled: false,
})
}

Expand Down Expand Up @@ -73,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 Expand Up @@ -105,6 +118,10 @@ impl Filesystem for SimFilesystem {
fn origin(&self) -> Option<FilesystemUuid> {
self.origin
}

fn merge_scheduled(&self) -> bool {
self.merge_scheduled
}
}

impl<'a> Into<Value> for &'a 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),
}
}
}
16 changes: 16 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,22 @@ 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>> {
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
16 changes: 16 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,22 @@ 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>> {
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
Loading

0 comments on commit e44d40e

Please sign in to comment.