Skip to content

Commit

Permalink
Add origin field to StratFilesystem
Browse files Browse the repository at this point in the history
Expose on D-Bus and store in metadata

Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Dec 12, 2023
1 parent 7ffe13a commit 2ade7f5
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/dbus_api/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub const FILESYSTEM_POOL_PROP: &str = "Pool";
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 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
14 changes: 14 additions & 0 deletions src/dbus_api/filesystem/filesystem_3_7/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// 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_tree::{Access, EmitsChangedSignal, Factory, MTSync, Property};

use crate::dbus_api::{consts, filesystem::filesystem_3_7::props::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::Const)
.on_get(get_fs_origin)
}
8 changes: 8 additions & 0 deletions src/dbus_api/filesystem/filesystem_3_7/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// 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/.

mod api;
mod props;

pub use api::origin_property;
18 changes: 18 additions & 0 deletions src/dbus_api/filesystem/filesystem_3_7/props.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// 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_tree::{MTSync, MethodErr, PropInfo};

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

pub fn get_fs_origin(
i: &mut IterAppend<'_>,
p: &PropInfo<'_, MTSync<TData>, TData>,
) -> Result<(), MethodErr> {
get_filesystem_property(i, p, |(_, _, f)| Ok(shared::fs_size_limit_prop(f)))
}
7 changes: 5 additions & 2 deletions src/dbus_api/filesystem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::{

mod filesystem_3_0;
mod filesystem_3_6;
mod filesystem_3_7;
pub mod prop_conv;
mod shared;

Expand Down Expand Up @@ -124,7 +125,8 @@ pub fn create_dbus_filesystem<'a>(
.add_p(filesystem_3_0::created_property(&f))
.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_6::size_limit_property(&f))
.add_p(filesystem_3_7::origin_property(&f)),
);

let path = object_path.get_name().to_owned();
Expand Down Expand Up @@ -214,7 +216,8 @@ pub fn get_fs_properties(
consts::FILESYSTEM_CREATED_PROP => shared::fs_created_prop(fs),
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_SIZE_LIMIT_PROP => shared::fs_size_limit_prop(fs),
consts::FILESYSTEM_ORIGIN_PROP => shared::fs_origin_prop(fs)
}
}
}
8 changes: 7 additions & 1 deletion src/dbus_api/filesystem/prop_conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use devicemapper::{Bytes, Sectors};

use crate::dbus_api::util::option_to_tuple;
use crate::{dbus_api::util::option_to_tuple, engine::FilesystemUuid};

/// Generate D-Bus representation of filesystem size property.
#[inline]
Expand All @@ -23,3 +23,9 @@ pub fn fs_used_to_prop(used: Option<Bytes>) -> (bool, String) {
pub fn fs_size_limit_to_prop(limit: Option<Sectors>) -> (bool, String) {
option_to_tuple(limit.map(|u| (*u.bytes()).to_string()), String::new())
}

/// Generate D-Bus representation of filesystem origin property.
#[inline]
pub fn fs_origin_to_prop(origin: Option<FilesystemUuid>) -> (bool, String) {
option_to_tuple(origin.map(|u| (uuid_to_string!(u))), String::new())
}
5 changes: 5 additions & 0 deletions src/dbus_api/filesystem/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,8 @@ pub fn fs_size_prop(fs: &dyn Filesystem) -> String {
pub fn fs_used_prop(fs: &dyn Filesystem) -> (bool, String) {
prop_conv::fs_used_to_prop(fs.used().ok())
}

/// Generate D-Bus representation of origin property.
pub fn fs_origin_prop(fs: &dyn Filesystem) -> (bool, String) {
prop_conv::fs_origin_to_prop(fs.origin())
}
3 changes: 3 additions & 0 deletions src/engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ pub trait Filesystem: Debug {

/// Get filesystem size limit.
fn size_limit(&self) -> Option<Sectors>;

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

pub trait BlockDev: Debug {
Expand Down
14 changes: 12 additions & 2 deletions src/engine/sim_engine/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde_json::{Map, Value};
use devicemapper::{Bytes, Sectors};

use crate::{
engine::Filesystem,
engine::{types::FilesystemUuid, Filesystem},
stratis::{StratisError, StratisResult},
};

Expand All @@ -20,10 +20,15 @@ pub struct SimFilesystem {
created: DateTime<Utc>,
size: Sectors,
size_limit: Option<Sectors>,
origin: Option<FilesystemUuid>,
}

impl SimFilesystem {
pub fn new(size: Sectors, size_limit: Option<Sectors>) -> StratisResult<SimFilesystem> {
pub fn new(
size: Sectors,
size_limit: Option<Sectors>,
origin: Option<FilesystemUuid>,
) -> StratisResult<SimFilesystem> {
if let Some(limit) = size_limit {
if limit < size {
return Err(StratisError::Msg(format!(
Expand All @@ -36,6 +41,7 @@ impl SimFilesystem {
created: Utc::now(),
size,
size_limit,
origin,
})
}

Expand Down Expand Up @@ -89,6 +95,10 @@ impl Filesystem for SimFilesystem {
fn size_limit(&self) -> Option<Sectors> {
self.size_limit
}

fn origin(&self) -> Option<FilesystemUuid> {
self.origin
}
}

impl<'a> Into<Value> for &'a SimFilesystem {
Expand Down
8 changes: 6 additions & 2 deletions src/engine/sim_engine/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl Pool for SimPool {
for (name, (size, size_limit)) in spec_map {
if !self.filesystems.contains_name(name) {
let uuid = FilesystemUuid::new_v4();
let new_filesystem = SimFilesystem::new(size, size_limit)?;
let new_filesystem = SimFilesystem::new(size, size_limit, None)?;
self.filesystems
.insert(Name::new((name).to_owned()), uuid, new_filesystem);
result.push((name, uuid, size));
Expand Down Expand Up @@ -533,7 +533,11 @@ impl Pool for SimPool {
return Ok(CreateAction::Identity);
}
}
SimFilesystem::new(filesystem.size(), filesystem.size_limit())?
SimFilesystem::new(
filesystem.size(),
filesystem.size_limit(),
Some(origin_uuid),
)?
}
None => {
return Err(StratisError::Msg(origin_uuid.to_string()));
Expand Down
2 changes: 2 additions & 0 deletions src/engine/strat_engine/serde_structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,6 @@ pub struct FilesystemSave {
pub created: u64, // Unix timestamp
#[serde(skip_serializing_if = "Option::is_none")]
pub fs_size_limit: Option<Sectors>,
#[serde(skip_serializing_if = "Option::is_none")]
pub origin: Option<FilesystemUuid>,
}
10 changes: 10 additions & 0 deletions src/engine/strat_engine/thinpool/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub struct StratFilesystem {
created: DateTime<Utc>,
used: Option<Bytes>,
size_limit: Option<Sectors>,
origin: Option<FilesystemUuid>,
}

fn init_used(thin_dev: &ThinDev) -> Option<Bytes> {
Expand Down Expand Up @@ -114,6 +115,7 @@ impl StratFilesystem {
thin_dev,
created: Utc::now(),
size_limit,
origin: None,
},
))
}
Expand All @@ -140,6 +142,7 @@ impl StratFilesystem {
thin_dev,
created,
size_limit: fssave.fs_size_limit,
origin: fssave.origin,
})
}

Expand Down Expand Up @@ -200,6 +203,7 @@ impl StratFilesystem {
snapshot_fs_name: &Name,
snapshot_fs_uuid: FilesystemUuid,
snapshot_thin_id: ThinDevId,
origin_uuid: FilesystemUuid,
) -> StratisResult<StratFilesystem> {
match self.thin_dev.snapshot(
get_dm(),
Expand Down Expand Up @@ -245,6 +249,7 @@ impl StratFilesystem {
thin_dev,
created: Utc::now(),
size_limit: self.size_limit,
origin: Some(origin_uuid),
})
}
Err(e) => Err(StratisError::Msg(format!(
Expand Down Expand Up @@ -366,6 +371,7 @@ impl StratFilesystem {
size: self.thin_dev.size(),
created: self.created.timestamp() as u64,
fs_size_limit: self.size_limit,
origin: self.origin,
}
}

Expand Down Expand Up @@ -459,6 +465,10 @@ impl Filesystem for StratFilesystem {
fn size_limit(&self) -> Option<Sectors> {
self.size_limit
}

fn origin(&self) -> Option<FilesystemUuid> {
self.origin
}
}

/// Represents the state of the Stratis filesystem at a given moment in time.
Expand Down
1 change: 1 addition & 0 deletions src/engine/strat_engine/thinpool/thinpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,7 @@ impl ThinPool {
&fs_name,
snapshot_fs_uuid,
snapshot_id,
origin_uuid,
)?,
None => {
return Err(StratisError::Msg(
Expand Down
3 changes: 3 additions & 0 deletions tests/client-dbus/src/stratisd_client_dbus/_introspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="invalidates" />
</property>
<property name="Name" type="s" access="read" />
<property name="Origin" type="(bs)" access="read">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const" />
</property>
<property name="Pool" type="o" access="read">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const" />
</property>
Expand Down

0 comments on commit 2ade7f5

Please sign in to comment.