Skip to content

Commit

Permalink
Add code for tearing down the backstore devices
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaublitz committed Mar 16, 2022
1 parent ef495b3 commit 8b71434
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/engine/strat_engine/backstore/backstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,11 @@ impl Backstore {
self.data_tier.destroy()
}

/// Run code required to stop a pool on backstore data structures.
pub fn stop(&mut self) -> StratisResult<()> {
self.data_tier.block_mgr.teardown()
}

/// Teardown the DM devices in the backstore.
#[cfg(test)]
pub fn teardown(&mut self) -> StratisResult<()> {
Expand Down
10 changes: 10 additions & 0 deletions src/engine/strat_engine/backstore/blockdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,16 @@ impl StratBlockDev {
})?;
crypt_handle.rebind_clevis()
}

/// If a pool is encrypted, tear down the cryptsetup devicemapper devices on the
/// physical device.
pub fn teardown(&mut self) -> StratisResult<()> {
if let Some(ch) = self.underlying_device.crypt_handle() {
ch.deactivate()
} else {
Ok(())
}
}
}

impl<'a> Into<Value> for &'a StratBlockDev {
Expand Down
16 changes: 16 additions & 0 deletions src/engine/strat_engine/backstore/blockdevmgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,22 @@ impl BlockDevMgr {
Ok(())
}
}

/// Tear down devicemapper devices for the block devices in this BlockDevMgr.
pub fn teardown(&mut self) -> StratisResult<()> {
let mut errors = Vec::new();
for bd in self.block_devs.iter_mut() {
if let Err(e) = bd.teardown() {
errors.push(e);
}
}

if errors.is_empty() {
Ok(())
} else {
Err(StratisError::BestEffortError("Failed to remove devicemapper devices for some or all physical devices in the pool".to_string(), errors))
}
}
}

fn operation_loop<'a, I, A>(blockdevs: I, action: A) -> StratisResult<()>
Expand Down
1 change: 0 additions & 1 deletion src/engine/strat_engine/backstore/crypt/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ impl CryptHandle {
}

/// Deactivate the device referenced by the current device handle.
#[cfg(test)]
pub fn deactivate(&self) -> StratisResult<()> {
super::shared::ensure_inactive(&mut self.acquire_crypt_device()?, &self.name)
}
Expand Down
1 change: 1 addition & 0 deletions src/engine/strat_engine/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ impl StratPool {
/// set up again later.
pub fn stop(mut self) -> StratisResult<DeviceSet> {
self.thin_pool.teardown()?;
self.backstore.stop()?;
Ok(self
.backstore
.blockdevs()
Expand Down

0 comments on commit 8b71434

Please sign in to comment.