Skip to content

Commit

Permalink
Add merge_scheduled field to filesystem
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <amulhern@redhat.com>
  • Loading branch information
mulkieran committed Jul 23, 2024
1 parent bde85e6 commit c51b84a
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 5 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
15 changes: 14 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,24 @@

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},
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::Read)
.emits_changed(EmitsChangedSignal::True)
.on_get(get_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};
7 changes: 7 additions & 0 deletions src/dbus_api/filesystem/filesystem_3_7/props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ 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)))
}
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)
}
}
}
5 changes: 5 additions & 0 deletions src/dbus_api/filesystem/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,8 @@ 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()
}
2 changes: 2 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
6 changes: 6 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 @@ -105,6 +107,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
10 changes: 9 additions & 1 deletion src/engine/strat_engine/thinpool/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub struct StratFilesystem {
used: Option<Bytes>,
size_limit: Option<Sectors>,
origin: Option<FilesystemUuid>,
merge_scheduled: bool,
}

fn init_used(thin_dev: &ThinDev) -> Option<Bytes> {
Expand Down Expand Up @@ -116,6 +117,7 @@ impl StratFilesystem {
created: Utc::now(),
size_limit,
origin: None,
merge_scheduled: false,
},
))
}
Expand Down Expand Up @@ -143,6 +145,7 @@ impl StratFilesystem {
created,
size_limit: fssave.fs_size_limit,
origin: fssave.origin,
merge_scheduled: fssave.merge.unwrap_or_default(),
})
}

Expand Down Expand Up @@ -250,6 +253,7 @@ impl StratFilesystem {
created: Utc::now(),
size_limit: self.size_limit,
origin: Some(origin_uuid),
merge_scheduled: false,
})
}
Err(e) => Err(StratisError::Msg(format!(
Expand Down Expand Up @@ -390,7 +394,7 @@ impl StratFilesystem {
created: self.created.timestamp() as u64,
fs_size_limit: self.size_limit,
origin: self.origin,
merge: None,
merge: self.origin.map(|_| self.merge_scheduled),
}
}

Expand Down Expand Up @@ -494,6 +498,10 @@ impl Filesystem for StratFilesystem {
fn origin(&self) -> Option<FilesystemUuid> {
self.origin
}

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

/// Represents the state of the Stratis filesystem at a given moment in time.
Expand Down

0 comments on commit c51b84a

Please sign in to comment.