Skip to content

Commit

Permalink
Add metadata version to StoppedPools
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaublitz committed Jun 3, 2024
1 parent e4da75c commit 140004a
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/dbus_api/api/manager_3_2/props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ pub fn get_stopped_pools(
i: &mut IterAppend<'_>,
p: &PropInfo<'_, MTSync<TData>, TData>,
) -> Result<(), MethodErr> {
get_manager_property(i, p, |e| Ok(shared::stopped_pools_prop(e)))
get_manager_property(i, p, |e| Ok(shared::stopped_pools_prop(e, false)))
}
18 changes: 16 additions & 2 deletions src/dbus_api/api/manager_3_7/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +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_tree::{Factory, MTSync, Method};
use dbus_tree::{Access, EmitsChangedSignal, Factory, MTSync, Method, Property};

use crate::dbus_api::{api::manager_3_7::methods::start_pool, types::TData};
use crate::dbus_api::{
api::{
manager_3_7::{methods::start_pool, props::get_stopped_pools},
prop_conv::StoppedOrLockedPools,
},
consts,
types::TData,
};

pub fn start_pool_method(f: &Factory<MTSync<TData>, TData>) -> Method<MTSync<TData>, TData> {
f.method("StartPool", (), start_pool)
Expand All @@ -23,3 +30,10 @@ pub fn start_pool_method(f: &Factory<MTSync<TData>, TData>) -> Method<MTSync<TDa
.out_arg(("return_code", "q"))
.out_arg(("return_string", "s"))
}

pub fn stopped_pools_property(f: &Factory<MTSync<TData>, TData>) -> Property<MTSync<TData>, TData> {
f.property::<StoppedOrLockedPools, _>(consts::STOPPED_POOLS_PROP, ())
.access(Access::Read)
.emits_changed(EmitsChangedSignal::True)
.on_get(get_stopped_pools)
}
3 changes: 2 additions & 1 deletion src/dbus_api/api/manager_3_7/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@

mod api;
mod methods;
mod props;

pub use api::start_pool_method;
pub use api::{start_pool_method, stopped_pools_property};
18 changes: 18 additions & 0 deletions src/dbus_api/api/manager_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::{
api::shared::{self, get_manager_property},
types::TData,
};

pub fn get_stopped_pools(
i: &mut IterAppend<'_>,
p: &PropInfo<'_, MTSync<TData>, TData>,
) -> Result<(), MethodErr> {
get_manager_property(i, p, |e| Ok(shared::stopped_pools_prop(e, true)))
}
2 changes: 1 addition & 1 deletion src/dbus_api/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub fn get_base_tree<'a>(
.add_m(manager_3_6::stop_pool_method(&f))
.add_m(manager_3_2::refresh_state_method(&f))
.add_p(manager_3_0::version_property(&f))
.add_p(manager_3_2::stopped_pools_property(&f)),
.add_p(manager_3_7::stopped_pools_property(&f)),
)
.add(
f.interface(consts::REPORT_INTERFACE_NAME_3_0, ())
Expand Down
11 changes: 10 additions & 1 deletion src/dbus_api/api/prop_conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub fn locked_pools_to_prop(pools: &LockedPoolsInfo) -> StoppedOrLockedPools {
}

/// Convert a stopped pool data structure to a property format.
pub fn stopped_pools_to_prop(pools: &StoppedPoolsInfo) -> StoppedOrLockedPools {
pub fn stopped_pools_to_prop(pools: &StoppedPoolsInfo, metadata: bool) -> StoppedOrLockedPools {
pools
.stopped
.iter()
Expand Down Expand Up @@ -111,6 +111,15 @@ pub fn stopped_pools_to_prop(pools: &StoppedPoolsInfo) -> StoppedOrLockedPools {
.collect::<Vec<_>>(),
)),
);
if metadata {
map.insert(
"metadata_version".to_string(),
match stopped.metadata_version {
Some(m) => Variant(Box::new((true, m as u64))),
None => Variant(Box::new((false, 0))),
},
);
}
(uuid_to_string!(u), map)
})
.collect::<HashMap<_, _>>()
Expand Down
4 changes: 2 additions & 2 deletions src/dbus_api/api/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,6 @@ pub fn locked_pools_prop(e: Arc<dyn Engine>) -> StoppedOrLockedPools {

/// Generate D-Bus representation of stopped pools
#[inline]
pub fn stopped_pools_prop(e: Arc<dyn Engine>) -> StoppedOrLockedPools {
prop_conv::stopped_pools_to_prop(&block_on(e.stopped_pools()))
pub fn stopped_pools_prop(e: Arc<dyn Engine>, metadata: bool) -> StoppedOrLockedPools {
prop_conv::stopped_pools_to_prop(&block_on(e.stopped_pools()), metadata)
}
12 changes: 6 additions & 6 deletions src/dbus_api/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,32 +578,32 @@ impl DbusTreeHandler {
consts::MANAGER_INTERFACE_NAME_3_2 => {
Vec::new(),
consts::STOPPED_POOLS_PROP.to_string() =>
box_variant!(stopped_pools_to_prop(&stopped_pools))
box_variant!(stopped_pools_to_prop(&stopped_pools, false))
},
consts::MANAGER_INTERFACE_NAME_3_3 => {
Vec::new(),
consts::STOPPED_POOLS_PROP.to_string() =>
box_variant!(stopped_pools_to_prop(&stopped_pools))
box_variant!(stopped_pools_to_prop(&stopped_pools, false))
},
consts::MANAGER_INTERFACE_NAME_3_4 => {
Vec::new(),
consts::STOPPED_POOLS_PROP.to_string() =>
box_variant!(stopped_pools_to_prop(&stopped_pools))
box_variant!(stopped_pools_to_prop(&stopped_pools, false))
},
consts::MANAGER_INTERFACE_NAME_3_5 => {
Vec::new(),
consts::STOPPED_POOLS_PROP.to_string() =>
box_variant!(stopped_pools_to_prop(&stopped_pools))
box_variant!(stopped_pools_to_prop(&stopped_pools, false))
},
consts::MANAGER_INTERFACE_NAME_3_6 => {
Vec::new(),
consts::STOPPED_POOLS_PROP.to_string() =>
box_variant!(stopped_pools_to_prop(&stopped_pools))
box_variant!(stopped_pools_to_prop(&stopped_pools, false))
},
consts::MANAGER_INTERFACE_NAME_3_7 => {
Vec::new(),
consts::STOPPED_POOLS_PROP.to_string() =>
box_variant!(stopped_pools_to_prop(&stopped_pools))
box_variant!(stopped_pools_to_prop(&stopped_pools, true))
}
},
)
Expand Down
2 changes: 2 additions & 0 deletions src/engine/sim_engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use crate::{
SetUnlockAction, StartAction, StopAction, StoppedPoolInfo, StoppedPoolsInfo,
StratFilesystemDiff, UdevEngineEvent, UnlockMethod,
},
StratSigblockVersion,
},
stratis::{StratisError, StratisResult},
};
Expand Down Expand Up @@ -254,6 +255,7 @@ impl Engine for SimEngine {
uuid: dev_uuid,
})
.collect::<Vec<_>>(),
metadata_version: Some(StratSigblockVersion::V2),
},
);
st
Expand Down
1 change: 1 addition & 0 deletions src/engine/strat_engine/liminal/device_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ impl DeviceSet {
}
})
.collect::<Vec<_>>(),
metadata_version: self.metadata_version().ok(),
})
}

Expand Down
1 change: 1 addition & 0 deletions src/engine/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ pub struct LockedPoolsInfo {
pub struct StoppedPoolInfo {
pub info: Option<PoolEncryptionInfo>,
pub devices: Vec<PoolDevice>,
pub metadata_version: Option<StratSigblockVersion>,
}

#[derive(Default, Debug, Eq, PartialEq)]
Expand Down

0 comments on commit 140004a

Please sign in to comment.