Skip to content

Commit

Permalink
Add D-Bus method to get filesystem metadata
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Jul 24, 2024
1 parent 96d94c4 commit 87a3542
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/dbus_api/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ pub fn create_dbus_pool<'a>(
.add_m(pool_3_0::rename_method(&f))
.add_m(pool_3_3::grow_physical_device_method(&f))
.add_m(pool_3_7::get_metadata_method(&f))
.add_m(pool_3_7::get_fs_metadata_method(&f))
.add_p(pool_3_0::name_property(&f))
.add_p(pool_3_0::uuid_property(&f))
.add_p(pool_3_0::encrypted_property(&f))
Expand Down
13 changes: 12 additions & 1 deletion src/dbus_api/pool/pool_3_7/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use dbus_tree::{Access, EmitsChangedSignal, Factory, MTSync, Method, Property};
use crate::dbus_api::{
consts,
pool::pool_3_7::{
methods::{destroy_filesystems, metadata},
methods::{destroy_filesystems, metadata, fs_metadata},
props::get_pool_metadata_version,
},
types::TData,
Expand Down Expand Up @@ -47,3 +47,14 @@ pub fn metadata_version_property(
.emits_changed(EmitsChangedSignal::Const)
.on_get(get_pool_metadata_version)
}

pub fn get_fs_metadata_method(f: &Factory<MTSync<TData>, TData>) -> Method<MTSync<TData>, TData> {
f.method("FilesystemMetadata", (), fs_metadata)
// A string representing the pool's filesystem metadata in serialized
// JSON format.
//
// Rust representation: String
.out_arg(("results", "s"))
.out_arg(("return_code", "q"))
.out_arg(("return_string", "s"))
}
36 changes: 36 additions & 0 deletions src/dbus_api/pool/pool_3_7/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,39 @@ pub fn metadata(m: &MethodInfo<'_, MTSync<TData>, TData>) -> MethodResult {
};
Ok(vec![msg])
}

pub fn fs_metadata(m: &MethodInfo<'_, MTSync<TData>, TData>) -> MethodResult {
let default_return = String::new();

let message: &Message = m.msg;

let return_message = message.method_return();

let dbus_context = m.tree.get_data();
let object_path = m.path.get_name();

let pool_path = m
.tree
.get(object_path)
.expect("implicit argument must be in tree");
let pool_uuid = typed_uuid!(
get_data!(pool_path; default_return; return_message).uuid;
Pool;
default_return;
return_message
);

let guard = get_pool!(dbus_context.engine; pool_uuid; default_return; return_message);
let (_, _, pool) = guard.as_tuple();

let result = pool.last_metadata();

let msg = match result {
Ok(v) => return_message.append3(v, DbusErrorEnum::OK as u16, OK_STRING.to_string()),
Err(err) => {
let (rc, rs) = engine_to_dbus_err_tuple(&err);
return_message.append3(default_return, rc, rs)
}
};
Ok(vec![msg])
}
5 changes: 4 additions & 1 deletion src/dbus_api/pool/pool_3_7/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ mod api;
mod methods;
mod props;

pub use api::{destroy_filesystems_method, get_metadata_method, metadata_version_property};
pub use api::{
destroy_filesystems_method, get_fs_metadata_method, get_metadata_method,
metadata_version_property,
};
3 changes: 3 additions & 0 deletions src/engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ pub trait Pool: Debug + Send + Sync {

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

/// Get the last written filesystem metadata.
fn last_fs_metadata(&self) -> StratisResult<String>;
}

pub type HandleEvents<P> = (
Expand Down
4 changes: 4 additions & 0 deletions src/engine/sim_engine/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,10 @@ impl Pool for SimPool {
fn metadata_version(&self) -> StratSigblockVersion {
StratSigblockVersion::V2
}

fn last_fs_metadata(&self) -> StratisResult<String> {
unimplemented!()
}
}

#[cfg(test)]
Expand Down
7 changes: 7 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,11 @@ impl Pool for AnyPool {
AnyPool::V2(p) => p.metadata_version(),
}
}

fn last_fs_metadata(&self) -> StratisResult<String> {
match self {
AnyPool::V1(p) => p.last_fs_metadata(),
AnyPool::V2(p) => p.last_fs_metadata(),
}
}
}
4 changes: 4 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,10 @@ impl Pool for StratPool {
fn metadata_version(&self) -> StratSigblockVersion {
StratSigblockVersion::V1
}

fn last_fs_metadata(&self) -> StratisResult<String> {
unimplemented!()
}
}

pub struct StratPoolState {
Expand Down
4 changes: 4 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,10 @@ impl Pool for StratPool {
fn metadata_version(&self) -> StratSigblockVersion {
StratSigblockVersion::V2
}

fn last_fs_metadata(&self) -> StratisResult<String> {
unimplemented!()
}
}

pub struct StratPoolState {
Expand Down

0 comments on commit 87a3542

Please sign in to comment.