Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in MDV Drop implementation and clean up tests #3027

Merged
merged 1 commit into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 2 additions & 39 deletions src/engine/strat_engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ impl Engine for StratEngine {

#[cfg(test)]
mod test {
use std::{env, error::Error, ffi::OsStr, iter::once, path::Path};
use std::{env, error::Error, path::Path};

use devicemapper::{Bytes, Sectors};

Expand All @@ -551,11 +551,8 @@ mod test {
cmd,
ns::unshare_namespace,
tests::{crypt, dm_stratis_devices_remove, loopbacked, real, FailDevice},
udev::{CRYPTO_FS_TYPE, FS_TYPE_KEY},
},
types::{
ActionAvailability, EngineAction, KeyDescription, UdevEngineDevice, UdevEngineEvent,
},
types::{ActionAvailability, EngineAction, KeyDescription},
};

use super::*;
Expand Down Expand Up @@ -775,40 +772,6 @@ mod test {
))
})?;

let mut events = generate_events!();

// Hack because fail device does not show up as LUKS2 device in udev
let cxt = libudev::Context::new().expect("Creating udev context should succeed");
let mut enumerator =
libudev::Enumerator::new(&cxt).expect("Creating enumerator should succeed");
enumerator.match_is_initialized().unwrap();
let mut devices = enumerator
.scan_devices()
.expect("Scanning udev devices should succeed");

let fail_udev = devices
.find(|dev| dev.devnode() == Some(&fail_device.as_path().canonicalize().unwrap()))
.expect("Fail device must be in udev database");

events.push(UdevEngineEvent::new(
libudev::EventType::Add,
UdevEngineDevice::new(
fail_udev.is_initialized(),
fail_udev.devnode().map(|p| p.to_owned()),
fail_udev.devnum(),
fail_udev
.properties()
.map(|prop| (Box::from(prop.name()), Box::from(prop.value())))
.chain(once((
Box::from(OsStr::new(FS_TYPE_KEY)),
Box::from(OsStr::new(CRYPTO_FS_TYPE)),
)))
.collect::<HashMap<_, _>>(),
),
));

test_async!(engine.handle_events(events));

let res = needs_clean_up(engine, uuid, fail_device, operation);

dm_stratis_devices_remove()?;
Expand Down
16 changes: 14 additions & 2 deletions src/engine/strat_engine/thinpool/mdv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,20 @@ impl MetadataVol {
impl Drop for MetadataVol {
fn drop(&mut self) {
fn drop_failure(mount_pt: &PathBuf) -> StratisResult<()> {
let mtpt_stat = stat(mount_pt)?;
let parent_stat = stat(&mount_pt.join(".."))?;
let mtpt_stat = match stat(mount_pt) {
Ok(s) => s,
Err(e) => match e {
nix::errno::Errno::ENOENT => return Ok(()),
e => return Err(StratisError::Nix(e)),
},
};
let parent_stat = match stat(&mount_pt.join("..")) {
Ok(s) => s,
Err(e) => match e {
nix::errno::Errno::ENOENT => return Ok(()),
e => return Err(StratisError::Nix(e)),
},
};

if mtpt_stat.st_dev != parent_stat.st_dev {
if let Err(e) = retry_with_index(Fixed::from_millis(100).take(2), |i| {
Expand Down
7 changes: 6 additions & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#[cfg(test)]
macro_rules! test_async {
($expr:expr) => {
tokio::runtime::Runtime::new().unwrap().block_on($expr)
tokio::task::LocalSet::new().block_on(
&tokio::runtime::Builder::new_current_thread()
.build()
.unwrap(),
$expr,
)
};
}

Expand Down