Skip to content

Commit

Permalink
Add code to tear down thin pool devices and convert StratPool to Devi…
Browse files Browse the repository at this point in the history
…ceSet
  • Loading branch information
jbaublitz committed Mar 16, 2022
1 parent f1e9f48 commit ef495b3
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/engine/strat_engine/liminal/device_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use std::{
collections::{hash_map, HashMap, HashSet},
fmt,
iter::FromIterator,
path::Path,
};

Expand Down Expand Up @@ -331,6 +332,17 @@ impl Default for DeviceSet {
}
}

impl FromIterator<(DevUuid, LInfo)> for DeviceSet {
fn from_iter<I>(i: I) -> Self
where
I: IntoIterator<Item = (DevUuid, LInfo)>,
{
DeviceSet {
internal: HashMap::from_iter(i),
}
}
}

impl DeviceSet {
/// Create a new, empty DeviceSet
pub fn new() -> DeviceSet {
Expand Down
25 changes: 24 additions & 1 deletion src/engine/strat_engine/liminal/identify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use devicemapper::Device;

use crate::engine::{
strat_engine::{
backstore::CryptMetadataHandle,
backstore::{CryptMetadataHandle, StratBlockDev},
metadata::{device_identifiers, StratisIdentifiers},
udev::{
block_enumerator, decide_ownership, UdevOwnership, CRYPTO_FS_TYPE, FS_TYPE_KEY,
Expand Down Expand Up @@ -148,6 +148,29 @@ impl DeviceInfo {
}
}

impl From<&StratBlockDev> for DeviceInfo {
fn from(bd: &StratBlockDev) -> Self {
fn stratis_info_from_bd(bd: &StratBlockDev) -> StratisInfo {
StratisInfo {
device_number: *bd.device(),
devnode: bd.physical_path().to_owned(),
identifiers: StratisIdentifiers {
pool_uuid: bd.pool_uuid(),
device_uuid: bd.uuid(),
},
}
}

match bd.encryption_info() {
Some(ei) => DeviceInfo::Luks(LuksInfo {
encryption_info: ei.clone(),
info: stratis_info_from_bd(bd),
}),
None => DeviceInfo::Stratis(stratis_info_from_bd(bd)),
}
}
}

impl fmt::Display for DeviceInfo {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down
6 changes: 5 additions & 1 deletion src/engine/strat_engine/liminal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ mod identify;
mod liminal;
mod setup;

pub use self::{device_info::DeviceSet, identify::find_all, liminal::LiminalDevices};
pub use self::{
device_info::{DeviceSet, LInfo},
identify::{find_all, DeviceInfo},
liminal::LiminalDevices,
};
12 changes: 9 additions & 3 deletions src/engine/strat_engine/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
},
strat_engine::{
backstore::{Backstore, StratBlockDev},
liminal::DeviceSet,
liminal::{DeviceInfo, DeviceSet, LInfo},
metadata::MDADataSize,
serde_structs::{FlexDevsSave, PoolSave, Recordable},
thinpool::{StratFilesystem, ThinPool, ThinPoolSizeParams, DATA_BLOCK_SIZE},
Expand Down Expand Up @@ -358,8 +358,14 @@ impl StratPool {

/// Stop a pool, consuming it and converting it into a set of devices to be
/// set up again later.
pub fn stop(self) -> StratisResult<DeviceSet> {
Ok(DeviceSet::default())
pub fn stop(mut self) -> StratisResult<DeviceSet> {
self.thin_pool.teardown()?;
Ok(self
.backstore
.blockdevs()
.into_iter()
.map(|(uuid, _, bd)| (uuid, LInfo::from(DeviceInfo::from(bd))))
.collect::<DeviceSet>())
}

#[cfg(test)]
Expand Down

0 comments on commit ef495b3

Please sign in to comment.