From 5f121e068c40d0df3d4d9a7ce243c31dd331b557 Mon Sep 17 00:00:00 2001 From: John Baublitz Date: Fri, 19 Jul 2024 15:16:07 -0400 Subject: [PATCH] Reflect changes to encryption layering in sim pool --- src/engine/sim_engine/blockdev.rs | 55 ++----------------------------- src/engine/sim_engine/pool.rs | 52 ++++++++++++----------------- 2 files changed, 23 insertions(+), 84 deletions(-) diff --git a/src/engine/sim_engine/blockdev.rs b/src/engine/sim_engine/blockdev.rs index 4b3d474e9c..cd63aca3a7 100644 --- a/src/engine/sim_engine/blockdev.rs +++ b/src/engine/sim_engine/blockdev.rs @@ -12,7 +12,7 @@ use devicemapper::{Bytes, Sectors, IEC}; use crate::engine::{ engine::BlockDev, shared::now_to_timestamp, - types::{DevUuid, EncryptionInfo, KeyDescription, StratSigblockVersion}, + types::{DevUuid, StratSigblockVersion}, }; #[derive(Debug)] @@ -22,7 +22,6 @@ pub struct SimDev { user_info: Option, hardware_info: Option, initialization_time: DateTime, - encryption_info: Option, } impl SimDev { @@ -68,7 +67,7 @@ impl BlockDev for SimDev { impl SimDev { /// Generates a new device from any devnode. - pub fn new(devnode: &Path, encryption_info: Option<&EncryptionInfo>) -> (DevUuid, SimDev) { + pub fn new(devnode: &Path) -> (DevUuid, SimDev) { ( DevUuid::new_v4(), SimDev { @@ -76,7 +75,6 @@ impl SimDev { user_info: None, hardware_info: None, initialization_time: now_to_timestamp(), - encryption_info: encryption_info.cloned(), }, ) } @@ -87,37 +85,6 @@ impl SimDev { pub fn set_user_info(&mut self, user_info: Option<&str>) -> bool { set_blockdev_user_info!(self; user_info) } - - /// Set the clevis info for a block device. - pub fn set_clevis_info(&mut self, pin: &str, config: &Value) { - self.encryption_info = self - .encryption_info - .take() - .map(|ei| ei.set_clevis_info((pin.to_owned(), config.clone()))); - } - - /// Unset the clevis info for a block device. - pub fn unset_clevis_info(&mut self) { - self.encryption_info = self.encryption_info.take().map(|ei| ei.unset_clevis_info()); - } - - /// Set the key description for a block device. - pub fn set_key_desc(&mut self, key_desc: &KeyDescription) { - self.encryption_info = self - .encryption_info - .take() - .map(|ei| ei.set_key_desc(key_desc.clone())) - } - - /// Unset the key description for a block device. - pub fn unset_key_desc(&mut self) { - self.encryption_info = self.encryption_info.take().map(|ei| ei.unset_key_desc()) - } - - /// Get encryption information for this block device. - pub fn encryption_info(&self) -> Option<&EncryptionInfo> { - self.encryption_info.as_ref() - } } impl<'a> Into for &'a SimDev { @@ -128,24 +95,6 @@ impl<'a> Into for &'a SimDev { Value::from(self.devnode.display().to_string()), ); json.insert("size".to_string(), Value::from(self.size().to_string())); - if let Some(EncryptionInfo::Both(kd, (pin, config))) = self.encryption_info.as_ref() { - json.insert( - "key_description".to_string(), - Value::from(kd.as_application_str()), - ); - json.insert("clevis_pin".to_string(), Value::from(pin.to_owned())); - json.insert("clevis_config".to_string(), config.to_owned()); - } else if let Some(EncryptionInfo::KeyDesc(kd)) = self.encryption_info.as_ref() { - json.insert( - "key_description".to_string(), - Value::from(kd.as_application_str()), - ); - } else if let Some(EncryptionInfo::ClevisInfo((pin, config))) = - self.encryption_info.as_ref() - { - json.insert("clevis_pin".to_string(), Value::from(pin.to_owned())); - json.insert("clevis_config".to_string(), config.to_owned()); - } Value::from(json) } } diff --git a/src/engine/sim_engine/pool.rs b/src/engine/sim_engine/pool.rs index 1e9a017b29..45f45eb0f6 100644 --- a/src/engine/sim_engine/pool.rs +++ b/src/engine/sim_engine/pool.rs @@ -4,6 +4,7 @@ use std::{ collections::{hash_map::RandomState, HashMap, HashSet}, + iter::once, path::Path, vec::Vec, }; @@ -16,8 +17,8 @@ use crate::{ engine::{ engine::{BlockDev, Filesystem, Pool}, shared::{ - gather_encryption_info, init_cache_idempotent_or_err, validate_filesystem_size, - validate_filesystem_size_specs, validate_name, validate_paths, + init_cache_idempotent_or_err, validate_filesystem_size, validate_filesystem_size_specs, + validate_name, validate_paths, }, sim_engine::{blockdev::SimDev, filesystem::SimFilesystem}, structures::Table, @@ -39,6 +40,7 @@ pub struct SimPool { filesystems: Table, fs_limit: u64, enable_overprov: bool, + encryption_info: Option, } #[derive(Debug, Eq, PartialEq, Serialize)] @@ -51,7 +53,7 @@ pub struct PoolSave { impl SimPool { pub fn new(paths: &[&Path], enc_info: Option<&EncryptionInfo>) -> (PoolUuid, SimPool) { let devices: HashSet<_, RandomState> = HashSet::from_iter(paths); - let device_pairs = devices.iter().map(|p| SimDev::new(p, enc_info)); + let device_pairs = devices.iter().map(|p| SimDev::new(p)); ( PoolUuid::new_v4(), SimPool { @@ -60,6 +62,7 @@ impl SimPool { filesystems: Table::default(), fs_limit: 10, enable_overprov: true, + encryption_info: enc_info.cloned(), }, ) } @@ -86,35 +89,31 @@ impl SimPool { } fn encryption_info(&self) -> Option { - gather_encryption_info( - self.block_devs.len(), - self.block_devs.values().map(|bd| bd.encryption_info()), - ) - .expect("sim engine cannot create pools with encrypted and unencrypted devices together") + self.encryption_info + .as_ref() + .map(|p| PoolEncryptionInfo::from(once(p))) } fn add_clevis_info(&mut self, pin: &str, config: &Value) { - self.block_devs - .iter_mut() - .for_each(|(_, bd)| bd.set_clevis_info(pin, config)) + self.encryption_info = self + .encryption_info + .take() + .map(|ei| ei.set_clevis_info((pin.to_owned(), config.to_owned()))); } fn clear_clevis_info(&mut self) { - self.block_devs - .iter_mut() - .for_each(|(_, bd)| bd.unset_clevis_info()) + self.encryption_info = self.encryption_info.take().map(|ei| ei.unset_clevis_info()); } fn add_key_desc(&mut self, key_desc: &KeyDescription) { - self.block_devs - .iter_mut() - .for_each(|(_, bd)| bd.set_key_desc(key_desc)) + self.encryption_info = self + .encryption_info + .take() + .map(|ei| ei.set_key_desc(key_desc.to_owned())); } fn clear_key_desc(&mut self) { - self.block_devs - .iter_mut() - .for_each(|(_, bd)| bd.unset_key_desc()) + self.encryption_info = self.encryption_info.take().map(|ei| ei.unset_key_desc()); } /// Check the limit of filesystems on a pool and return an error if it has been passed. @@ -219,7 +218,7 @@ impl Pool for SimPool { "At least one blockdev path is required to initialize a cache.".to_string(), )); } - let blockdev_pairs: Vec<_> = blockdevs.iter().map(|p| SimDev::new(p, None)).collect(); + let blockdev_pairs: Vec<_> = blockdevs.iter().map(|p| SimDev::new(p)).collect(); let blockdev_uuids: Vec<_> = blockdev_pairs.iter().map(|(uuid, _)| *uuid).collect(); self.cache_devs.extend(blockdev_pairs); Ok(SetCreateAction::new(blockdev_uuids)) @@ -296,7 +295,6 @@ impl Pool for SimPool { } let devices: HashSet<_, RandomState> = HashSet::from_iter(paths); - let encryption_info = pool_enc_to_enc!(self.encryption_info()); let the_vec = match tier { BlockDevTier::Cache => &self.cache_devs, @@ -307,15 +305,7 @@ impl Pool for SimPool { let filtered_device_pairs: Vec<_> = devices .iter() - .map(|p| { - SimDev::new( - p, - match tier { - BlockDevTier::Data => encryption_info.as_ref(), - BlockDevTier::Cache => None, - }, - ) - }) + .map(|p| SimDev::new(p)) .filter(|(_, sd)| !filter.contains(&sd.devnode())) .collect();