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

Store StaticHeader::pool_uuid and StaticHeader::dev_uuid into a new StratisIdentifiers type #1826

Merged
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
4 changes: 2 additions & 2 deletions src/engine/strat_engine/backstore/backstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ mod tests {
device_identifiers(&mut OpenOptions::new().read(true).open(path).unwrap())
.unwrap()
.unwrap()
.0
.pool_uuid
);
}

Expand All @@ -850,7 +850,7 @@ mod tests {
device_identifiers(&mut OpenOptions::new().read(true).open(path).unwrap())
.unwrap()
.unwrap()
.0
.pool_uuid
);
}

Expand Down
14 changes: 8 additions & 6 deletions src/engine/strat_engine/backstore/blockdevmgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
backstore::{
blockdev::StratBlockDev,
devices::{initialize_devices, process_devices, wipe_blockdevs, DeviceInfo},
metadata::MDADataSize,
metadata::{MDADataSize, StratisIdentifiers},
},
serde_structs::{BaseBlockDevSave, BaseDevSave, Recordable},
},
Expand Down Expand Up @@ -144,10 +144,10 @@ fn check_device_ids(
let stratis_identifiers: HashMap<PoolUuid, HashSet<DevUuid>> = devices
.iter()
.filter_map(|info| info.stratis_identifiers)
.fold(HashMap::new(), |mut acc, (pool_uuid, dev_uuid)| {
acc.entry(pool_uuid)
.fold(HashMap::new(), |mut acc, identifiers| {
acc.entry(identifiers.pool_uuid)
.or_insert_with(HashSet::new)
.insert(dev_uuid);
.insert(identifiers.device_uuid);
acc
});

Expand All @@ -163,7 +163,7 @@ fn check_device_ids(
.iter()
.filter(|info| match info.stratis_identifiers {
None => false,
Some((pool_uuid, _)) => devs.contains(&pool_uuid),
Some(StratisIdentifiers { pool_uuid, .. }) => devs.contains(&pool_uuid),
})
.map(|info| info.devnode.display().to_string())
.collect::<Vec<_>>()
Expand Down Expand Up @@ -193,7 +193,9 @@ fn check_device_ids(
.iter()
.filter(|info| match info.stratis_identifiers {
None => false,
Some((pool_uuid, _)) => invalid_uuids.contains(&&pool_uuid),
Some(StratisIdentifiers { pool_uuid, .. }) => {
invalid_uuids.contains(&&pool_uuid)
}
})
.map(|info| info.devnode.display().to_string())
.collect::<Vec<_>>()
Expand Down
26 changes: 17 additions & 9 deletions src/engine/strat_engine/backstore/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ use crate::{
strat_engine::{
backstore::{
blockdev::StratBlockDev,
metadata::{device_identifiers, disown_device, BlockdevSize, MDADataSize, BDA},
metadata::{
device_identifiers, disown_device, BlockdevSize, MDADataSize,
StratisIdentifiers, BDA,
},
udev::{block_device_apply, decide_ownership, get_udev_property, UdevOwnership},
},
device::blkdev_size,
},
types::{DevUuid, PoolUuid},
types::PoolUuid,
},
stratis::{ErrorEnum, StratisError, StratisResult},
};
Expand Down Expand Up @@ -102,7 +105,7 @@ fn dev_info(
) -> StratisResult<(
Option<StratisResult<String>>,
Bytes,
Option<(PoolUuid, DevUuid)>,
Option<StratisIdentifiers>,
Device,
)> {
let (ownership, devnum, hw_id) = udev_info(devnode)?;
Expand Down Expand Up @@ -180,7 +183,7 @@ pub struct DeviceInfo {
pub size: Bytes,
/// The device identifiers obtained from the Stratis metadata. If None,
/// the device has been determined to be unowned.
pub stratis_identifiers: Option<(PoolUuid, DevUuid)>,
pub stratis_identifiers: Option<StratisIdentifiers>,
}

/// Process a list of devices specified as device nodes. Return a vector
Expand Down Expand Up @@ -218,8 +221,7 @@ pub fn initialize_devices(
let mut f = OpenOptions::new().write(true).open(&dev_info.devnode)?;
let bda = BDA::initialize(
&mut f,
pool_uuid,
Uuid::new_v4(),
StratisIdentifiers::new(pool_uuid, Uuid::new_v4()),
mda_data_size,
BlockdevSize::new(dev_info.size.sectors()),
Utc::now().timestamp() as u64,
Expand Down Expand Up @@ -319,7 +321,7 @@ mod tests {
device_identifiers(&mut OpenOptions::new().read(true).open(path).unwrap(),)
.unwrap()
.unwrap()
.0
.pool_uuid
);
}

Expand Down Expand Up @@ -383,7 +385,10 @@ mod tests {
.write(true)
.open(path)
.unwrap();
assert_eq!(device_identifiers(&mut f).unwrap().unwrap().0, uuid1);
assert_eq!(
device_identifiers(&mut f).unwrap().unwrap().pool_uuid,
uuid1
);
}
}

Expand Down Expand Up @@ -416,7 +421,10 @@ mod tests {
.write(true)
.open(path)
.unwrap();
assert_eq!(device_identifiers(&mut f).unwrap().unwrap().0, uuid2);
assert_eq!(
device_identifiers(&mut f).unwrap().unwrap().pool_uuid,
uuid2
);
}
}

Expand Down
52 changes: 23 additions & 29 deletions src/engine/strat_engine/backstore/identify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ use devicemapper::Device;

use crate::engine::{
strat_engine::backstore::{
metadata::device_identifiers,
metadata::{device_identifiers, StratisIdentifiers},
udev::{block_enumerator, decide_ownership, UdevOwnership},
},
types::{DevUuid, PoolUuid},
types::PoolUuid,
};

// A wrapper for obtaining the device number as a devicemapper Device
Expand All @@ -41,7 +41,7 @@ fn device_to_devno_wrapper(device: &libudev::Device) -> Result<Device, String> {
// the device.
fn device_identifiers_wrapper(
devnode: &Path,
) -> Result<Result<Option<(PoolUuid, DevUuid)>, String>, String> {
) -> Result<Result<Option<StratisIdentifiers>, String>, String> {
OpenOptions::new()
.read(true)
.open(devnode)
Expand All @@ -65,7 +65,7 @@ fn device_identifiers_wrapper(
}

/// Process a device which udev information indicates is a Stratis device.
fn process_stratis_device(dev: &libudev::Device) -> Option<(PoolUuid, DevUuid, Device, PathBuf)> {
fn process_stratis_device(dev: &libudev::Device) -> Option<(StratisIdentifiers, Device, PathBuf)> {
match dev.devnode() {
Some(devnode) => {
match (
Expand All @@ -83,8 +83,8 @@ fn process_stratis_device(dev: &libudev::Device) -> Option<(PoolUuid, DevUuid, D
devnode.display());
None
}
(Ok(devno), Ok(Ok(Some((pool_uuid, device_uuid))))) => {
Some((pool_uuid, device_uuid, devno, devnode.to_path_buf()))
(Ok(devno), Ok(Ok(Some(identifiers)))) => {
Some((identifiers, devno, devnode.to_path_buf()))
}
}
}
Expand All @@ -96,7 +96,7 @@ fn process_stratis_device(dev: &libudev::Device) -> Option<(PoolUuid, DevUuid, D
}

/// Process a device which udev information indicates is unowned.
fn process_unowned_device(dev: &libudev::Device) -> Option<(PoolUuid, DevUuid, Device, PathBuf)> {
fn process_unowned_device(dev: &libudev::Device) -> Option<(StratisIdentifiers, Device, PathBuf)> {
match dev.devnode() {
Some(devnode) => {
match (
Expand All @@ -121,8 +121,8 @@ fn process_unowned_device(dev: &libudev::Device) -> Option<(PoolUuid, DevUuid, D
None
}
(_, Ok(Ok(None))) => None,
(Ok(devno), Ok(Ok(Some((pool_uuid, device_uuid))))) => {
Some((pool_uuid, device_uuid, devno, devnode.to_path_buf()))
(Ok(devno), Ok(Ok(Some(identifiers)))) => {
Some((identifiers, devno, devnode.to_path_buf()))
}
}
}
Expand All @@ -143,15 +143,12 @@ pub fn find_all_block_devices_with_stratis_signatures(
let pool_map = enumerator
.scan_devices()?
.filter_map(|dev| identify_block_device(&dev))
.fold(
HashMap::new(),
|mut acc, (pool_uuid, _, device, devnode)| {
acc.entry(pool_uuid)
.or_insert_with(HashMap::new)
.insert(device, devnode);
acc
},
);
.fold(HashMap::new(), |mut acc, (identifiers, device, devnode)| {
acc.entry(identifiers.pool_uuid)
.or_insert_with(HashMap::new)
.insert(device, devnode);
acc
});

Ok(pool_map)
}
Expand All @@ -165,22 +162,19 @@ fn find_all_stratis_devices() -> libudev::Result<HashMap<PoolUuid, HashMap<Devic
let pool_map = enumerator
.scan_devices()?
.filter_map(|dev| identify_stratis_device(&dev))
.fold(
HashMap::new(),
|mut acc, (pool_uuid, _, device, devnode)| {
acc.entry(pool_uuid)
.or_insert_with(HashMap::new)
.insert(device, devnode);
acc
},
);
.fold(HashMap::new(), |mut acc, (identifiers, device, devnode)| {
acc.entry(identifiers.pool_uuid)
.or_insert_with(HashMap::new)
.insert(device, devnode);
acc
});
Ok(pool_map)
}

// Identify a device that udev enumeration has already picked up as a Stratis
// device. Return None if the device does not, after all, appear to be a Stratis
// device. Log anything unusual at an appropriate level.
fn identify_stratis_device(dev: &libudev::Device) -> Option<(PoolUuid, DevUuid, Device, PathBuf)> {
fn identify_stratis_device(dev: &libudev::Device) -> Option<(StratisIdentifiers, Device, PathBuf)> {
let initialized = dev.is_initialized();
if !initialized {
warn!("Found a udev entry for a device identified as a Stratis device, but udev also identified it as uninitialized, disregarding the device");
Expand Down Expand Up @@ -209,7 +203,7 @@ fn identify_stratis_device(dev: &libudev::Device) -> Option<(PoolUuid, DevUuid,
/// appear to be a Stratis device. Log at an appropriate level on all errors.
pub fn identify_block_device(
dev: &libudev::Device,
) -> Option<(PoolUuid, DevUuid, Device, PathBuf)> {
) -> Option<(StratisIdentifiers, Device, PathBuf)> {
let initialized = dev.is_initialized();
if !initialized {
debug!("Found a udev entry for a device identified as a block device, but udev also identified it as uninitialized, disregarding the device");
Expand Down
22 changes: 8 additions & 14 deletions src/engine/strat_engine/backstore/metadata/bda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
use std::io::{Read, Seek};

use chrono::{DateTime, Utc};
use uuid::Uuid;

use crate::{
engine::{
strat_engine::{
backstore::metadata::{
mda,
sizes::{BDAExtendedSize, BlockdevSize, MDADataSize, STATIC_HEADER_SIZE},
static_header::{MetadataLocation, StaticHeader},
static_header::{MetadataLocation, StaticHeader, StratisIdentifiers},
},
device::SyncAll,
},
Expand All @@ -32,8 +31,7 @@ impl BDA {
/// Initialize a blockdev with a Stratis BDA.
pub fn initialize<F>(
f: &mut F,
pool_uuid: Uuid,
dev_uuid: Uuid,
identifiers: StratisIdentifiers,
mda_data_size: MDADataSize,
blkdev_size: BlockdevSize,
initialization_time: u64,
Expand All @@ -42,8 +40,7 @@ impl BDA {
F: Seek + SyncAll,
{
let header = StaticHeader::new(
pool_uuid,
dev_uuid,
identifiers,
mda_data_size.region_size().mda_size(),
blkdev_size,
initialization_time,
Expand Down Expand Up @@ -111,12 +108,12 @@ impl BDA {

/// The UUID of the device.
pub fn dev_uuid(&self) -> DevUuid {
self.header.dev_uuid
self.header.identifiers.device_uuid
}

/// The UUID of the device's pool.
pub fn pool_uuid(&self) -> PoolUuid {
self.header.pool_uuid
self.header.identifiers.pool_uuid
}

/// The size of the device.
Expand Down Expand Up @@ -163,8 +160,7 @@ mod tests {
let mut buf = Cursor::new(vec![0; buf_size]);
let bda = BDA::initialize(
&mut buf,
sh.pool_uuid,
sh.dev_uuid,
sh.identifiers,
sh.mda_size.region_size().data_size(),
sh.blkdev_size,
Utc::now().timestamp() as u64,
Expand All @@ -184,8 +180,7 @@ mod tests {
let mut buf = Cursor::new(vec![0; *sh.blkdev_size.sectors().bytes() as usize]);
let mut bda = BDA::initialize(
&mut buf,
sh.pool_uuid,
sh.dev_uuid,
sh.identifiers,
sh.mda_size.region_size().data_size(),
sh.blkdev_size,
Utc::now().timestamp() as u64,
Expand Down Expand Up @@ -229,8 +224,7 @@ mod tests {
let mut buf = Cursor::new(vec![0; buf_size]);
let mut bda = BDA::initialize(
&mut buf,
sh.pool_uuid,
sh.dev_uuid,
sh.identifiers,
sh.mda_size.region_size().data_size(),
sh.blkdev_size,
Utc::now().timestamp() as u64,
Expand Down
2 changes: 1 addition & 1 deletion src/engine/strat_engine/backstore/metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ mod static_header;
pub use self::{
bda::BDA,
sizes::{BDAExtendedSize, BlockdevSize, MDADataSize},
static_header::{device_identifiers, disown_device},
static_header::{device_identifiers, disown_device, StratisIdentifiers},
};
Loading