Skip to content

Commit

Permalink
Rework udev unlocked device detection
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaublitz committed Apr 8, 2022
1 parent e4abe61 commit 2942b6e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
16 changes: 11 additions & 5 deletions src/engine/strat_engine/liminal/identify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ use crate::engine::{
backstore::{CryptMetadataHandle, StratBlockDev},
metadata::{device_identifiers, StratisIdentifiers},
udev::{
block_enumerator, decide_ownership, UdevOwnership, CRYPTO_FS_TYPE, FS_POOL_UUID_KEY,
FS_TYPE_KEY, STRATIS_FS_TYPE,
block_enumerator, decide_ownership, UdevOwnership, CRYPTO_FS_TYPE, FS_TYPE_KEY,
FS_UUID_KEY, STRATIS_FS_TYPE,
},
},
types::{EncryptionInfo, PoolUuid, UdevEngineDevice, UdevEngineEvent},
types::{DevUuid, EncryptionInfo, PoolUuid, UdevEngineDevice, UdevEngineEvent},
};

/// A miscellaneous group of identifiers found when identifying a LUKS
Expand Down Expand Up @@ -332,10 +332,16 @@ fn find_all_stratis_devices() -> libudev::Result<HashMap<PoolUuid, Vec<StratisIn
}

// Find all devices identified by udev as Stratis devices that match the given UUID.
pub fn find_pool_stratis_devices(pool_uuid: PoolUuid) -> libudev::Result<Vec<StratisInfo>> {
pub fn find_pool_stratis_devices(dev_uuids: Vec<DevUuid>) -> libudev::Result<Vec<StratisInfo>> {
if dev_uuids.is_empty() {
return Ok(Vec::new());
}

let context = libudev::Context::new()?;
let mut enumerator = block_enumerator(&context)?;
enumerator.match_property(FS_POOL_UUID_KEY, pool_uuid.to_string())?;
for uuid in dev_uuids {
enumerator.match_property(FS_UUID_KEY, uuid.to_string())?;
}

let info_list = enumerator
.scan_devices()?
Expand Down
10 changes: 9 additions & 1 deletion src/engine/strat_engine/liminal/liminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,12 @@ impl LiminalDevices {
if let Err(e) = udev_settle() {
warn!("Failed to wait for udev processing to complete: {}", e);
}
match find_pool_stratis_devices(pool_uuid) {
match find_pool_stratis_devices(
unlocked_devices
.iter()
.map(|(dev_uuid, _)| *dev_uuid)
.collect::<Vec<_>>(),
) {
Ok(infos) => {
for info in infos {
stopped_pool.process_info_add(DeviceInfo::Stratis(info));
Expand Down Expand Up @@ -532,6 +537,9 @@ impl LiminalDevices {

devices.process_info_remove(device_path, pool_uuid, dev_uuid);
self.uuid_lookup.remove(device_path);
if !devices.is_empty() {
self.stopped_pools.insert(pool_uuid, devices);
}
}
None
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/engine/strat_engine/udev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{

/// Key for a udev property
pub const FS_TYPE_KEY: &str = "ID_FS_TYPE";
pub const FS_POOL_UUID_KEY: &str = "ID_FS_POOL_UUID";
pub const FS_UUID_KEY: &str = "ID_FS_UUID";

/// Possible values for the "ID_FS_TYPE" udev property
pub const STRATIS_FS_TYPE: &str = "stratis";
Expand Down
2 changes: 0 additions & 2 deletions udev/61-stratisd.rules
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
ACTION=="add|change", ENV{ID_FS_TYPE}=="stratis", IMPORT{program}="/usr/sbin/blkid -o udev $env{DEVNAME}"

ACTION=="change", ENV{DM_NAME}=="stratis-1-[0-9a-f]*-thin-fs-[0-9a-f]*", IMPORT{program}="stratis-base32-decode STRATIS_POOL_NAME $env{SYNTH_ARG_STRATISPOOLNAME}", ENV{SYNTH_ARG_STRATISPOOLNAME}!=""
ACTION=="change", ENV{DM_NAME}=="stratis-1-[0-9a-f]*-thin-fs-[0-9a-f]*", IMPORT{program}="stratis-base32-decode STRATIS_FS_NAME $env{SYNTH_ARG_STRATISFSNAME}", ENV{SYNTH_ARG_STRATISFSNAME}!=""
ACTION=="change", ENV{DM_NAME}=="stratis-1-[0-9a-f]*-thin-fs-[0-9a-f]*", PROGRAM+="stratis-str-cmp $env{SYNTH_UUID} $env{ID_FS_UUID}", RESULT=="0", ENV{SYNTH_UUID}!="", ENV{STRATIS_POOL_NAME}!="", ENV{STRATIS_FS_NAME}!="", SYMLINK+="stratis/$env{STRATIS_POOL_NAME}/$env{STRATIS_FS_NAME}", GOTO="stratis_end"
Expand Down

0 comments on commit 2942b6e

Please sign in to comment.