Skip to content

Commit

Permalink
Expose metadata version on D-Bus
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaublitz authored and mulkieran committed Sep 14, 2023
1 parent 623afeb commit d2799c4
Show file tree
Hide file tree
Showing 12 changed files with 82 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 @@ -45,6 +45,7 @@ pub const POOL_ALLOC_SIZE_PROP: &str = "AllocatedSize";
pub const POOL_FS_LIMIT_PROP: &str = "FsLimit";
pub const POOL_OVERPROV_PROP: &str = "Overprovisioning";
pub const POOL_NO_ALLOCABLE_SPACE_PROP: &str = "NoAllocSpace";
pub const POOL_METADATA_VERSION_PROP: &str = "MetadataVersion";

pub const FILESYSTEM_INTERFACE_NAME_3_0: &str = "org.storage.stratis3.filesystem.r0";
pub const FILESYSTEM_INTERFACE_NAME_3_1: &str = "org.storage.stratis3.filesystem.r1";
Expand Down
7 changes: 5 additions & 2 deletions src/dbus_api/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod pool_3_0;
mod pool_3_1;
mod pool_3_3;
mod pool_3_5;
mod pool_3_6;
pub mod prop_conv;
mod shared;

Expand Down Expand Up @@ -239,7 +240,8 @@ pub fn create_dbus_pool<'a>(
.add_p(pool_3_0::total_size_property(&f))
.add_p(pool_3_1::fs_limit_property(&f))
.add_p(pool_3_1::enable_overprov_property(&f))
.add_p(pool_3_1::no_alloc_space_property(&f)),
.add_p(pool_3_1::no_alloc_space_property(&f))
.add_p(pool_3_6::metadata_version_property(&f)),
);

let path = object_path.get_name().to_owned();
Expand Down Expand Up @@ -355,7 +357,8 @@ pub fn get_pool_properties(
consts::POOL_TOTAL_SIZE_PROP => shared::pool_total_size(pool),
consts::POOL_FS_LIMIT_PROP => shared::pool_fs_limit(pool),
consts::POOL_OVERPROV_PROP => shared::pool_overprov_enabled(pool),
consts::POOL_NO_ALLOCABLE_SPACE_PROP => shared::pool_no_alloc_space(pool)
consts::POOL_NO_ALLOCABLE_SPACE_PROP => shared::pool_no_alloc_space(pool),
consts::POOL_METADATA_VERSION_PROP => shared::pool_metadata_version(pool)
}
}
}
16 changes: 16 additions & 0 deletions src/dbus_api/pool/pool_3_6/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 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, pool::pool_3_6::props::get_pool_metadata_version, types::TData};

pub fn metadata_version_property(
f: &Factory<MTSync<TData>, TData>,
) -> Property<MTSync<TData>, TData> {
f.property::<u64, _>(consts::POOL_METADATA_VERSION_PROP, ())
.access(Access::Read)
.emits_changed(EmitsChangedSignal::Const)
.on_get(get_pool_metadata_version)
}
8 changes: 8 additions & 0 deletions src/dbus_api/pool/pool_3_6/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::metadata_version_property;
18 changes: 18 additions & 0 deletions src/dbus_api/pool/pool_3_6/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::{
pool::shared::{self, get_pool_property},
types::TData,
};

pub fn get_pool_metadata_version(
i: &mut IterAppend<'_>,
p: &PropInfo<'_, MTSync<TData>, TData>,
) -> Result<(), MethodErr> {
get_pool_property(i, p, |(_, _, pool)| Ok(shared::pool_metadata_version(pool)))
}
6 changes: 6 additions & 0 deletions src/dbus_api/pool/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,12 @@ pub fn pool_fs_limit(pool: &dyn Pool) -> u64 {
pool.fs_limit()
}

/// Generate a D-Bus representation of the filesystem limit on the pool.
#[inline]
pub fn pool_metadata_version(pool: &dyn Pool) -> u64 {
pool.metadata_version() as u64
}

/// Set the filesystem limit on a pool.
#[inline]
pub fn set_pool_fs_limit(
Expand Down
3 changes: 3 additions & 0 deletions src/engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ pub trait Pool: Debug + Send + Sync {
pool_uuid: PoolUuid,
device: DevUuid,
) -> StratisResult<(GrowAction<(PoolUuid, DevUuid)>, Option<PoolDiff>)>;

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

pub type HandleEvents<P> = (
Expand Down
4 changes: 2 additions & 2 deletions src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ pub use self::{
MaybeInconsistent, Name, PoolDiff, PoolEncryptionInfo, PoolIdentifier, PoolUuid,
PropChangeAction, RenameAction, ReportType, SetCreateAction, SetDeleteAction,
SetUnlockAction, StartAction, StopAction, StoppedPoolInfo, StoppedPoolsInfo,
StratBlockDevDiff, StratFilesystemDiff, StratPoolDiff, StratisUuid, ThinPoolDiff,
ToDisplay, UdevEngineEvent, UnlockMethod,
StratBlockDevDiff, StratFilesystemDiff, StratPoolDiff, StratSigblockVersion, StratisUuid,
ThinPoolDiff, ToDisplay, UdevEngineEvent, UnlockMethod,
},
};

Expand Down
6 changes: 5 additions & 1 deletion src/engine/sim_engine/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
ActionAvailability, BlockDevTier, Clevis, CreateAction, DeleteAction, DevUuid,
EncryptionInfo, FilesystemUuid, GrowAction, Key, KeyDescription, Name, PoolDiff,
PoolEncryptionInfo, PoolUuid, RegenAction, RenameAction, SetCreateAction,
SetDeleteAction,
SetDeleteAction, StratSigblockVersion,
},
},
stratis::{StratisError, StratisResult},
Expand Down Expand Up @@ -691,6 +691,10 @@ impl Pool for SimPool {
) -> StratisResult<(GrowAction<(PoolUuid, DevUuid)>, Option<PoolDiff>)> {
Ok((GrowAction::Identity, None))
}

fn metadata_version(&self) -> StratSigblockVersion {
StratSigblockVersion::V2
}
}

#[cfg(test)]
Expand Down
8 changes: 8 additions & 0 deletions src/engine/strat_engine/pool/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::{
ActionAvailability, BlockDevTier, Clevis, CreateAction, DeleteAction, DevUuid,
FilesystemUuid, GrowAction, Key, KeyDescription, Name, PoolDiff, PoolEncryptionInfo,
PoolUuid, RegenAction, RenameAction, SetCreateAction, SetDeleteAction,
StratSigblockVersion,
},
},
stratis::StratisResult,
Expand Down Expand Up @@ -315,4 +316,11 @@ impl Pool for AnyPool {
AnyPool::V2(p) => p.grow_physical(name, pool_uuid, device),
}
}

fn metadata_version(&self) -> StratSigblockVersion {
match self {
AnyPool::V1(p) => p.metadata_version(),
AnyPool::V2(p) => p.metadata_version(),
}
}
}
6 changes: 5 additions & 1 deletion src/engine/strat_engine/pool/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use crate::{
ActionAvailability, BlockDevTier, Clevis, Compare, CreateAction, DeleteAction, DevUuid,
Diff, FilesystemUuid, GrowAction, Key, KeyDescription, Name, PoolDiff,
PoolEncryptionInfo, PoolUuid, RegenAction, RenameAction, SetCreateAction,
SetDeleteAction, StratFilesystemDiff, StratPoolDiff,
SetDeleteAction, StratFilesystemDiff, StratPoolDiff, StratSigblockVersion,
},
},
stratis::{StratisError, StratisResult},
Expand Down Expand Up @@ -1228,6 +1228,10 @@ impl Pool for StratPool {
Ok((GrowAction::Identity, None))
}
}

fn metadata_version(&self) -> StratSigblockVersion {
StratSigblockVersion::V1
}
}

pub struct StratPoolState {
Expand Down
6 changes: 5 additions & 1 deletion src/engine/strat_engine/pool/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::{
ActionAvailability, BlockDevTier, Clevis, Compare, CreateAction, DeleteAction, DevUuid,
Diff, EncryptionInfo, FilesystemUuid, GrowAction, Key, KeyDescription, Name, PoolDiff,
PoolEncryptionInfo, PoolUuid, RegenAction, RenameAction, SetCreateAction,
SetDeleteAction, StratFilesystemDiff, StratPoolDiff,
SetDeleteAction, StratFilesystemDiff, StratPoolDiff, StratSigblockVersion,
},
},
stratis::{StratisError, StratisResult},
Expand Down Expand Up @@ -1129,6 +1129,10 @@ impl Pool for StratPool {
Ok((GrowAction::Identity, None))
}
}

fn metadata_version(&self) -> StratSigblockVersion {
StratSigblockVersion::V2
}
}

pub struct StratPoolState {
Expand Down

0 comments on commit d2799c4

Please sign in to comment.