From 38af3c1e84830c1b5c89ac5c77d6441c682796b7 Mon Sep 17 00:00:00 2001 From: Brian Fjeldstad Date: Wed, 16 Jul 2025 00:12:39 +0000 Subject: [PATCH] PartitionSize::Lazy --- src/engine/storage/partitioning.rs | 3 +++ src/offline_init/mod.rs | 22 +++++++++++++------ .../src/config/host/storage/partitions.rs | 22 ++++++++++++++++++- .../host/storage/storage_graph/rules/mod.rs | 4 ++++ trident_api/src/constants.rs | 3 +++ 5 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/engine/storage/partitioning.rs b/src/engine/storage/partitioning.rs index 00bf88567..0ae4e8247 100644 --- a/src/engine/storage/partitioning.rs +++ b/src/engine/storage/partitioning.rs @@ -368,6 +368,9 @@ fn add_repart_entries( let size = match partition.size { PartitionSize::Grow => None, PartitionSize::Fixed(s) => Some(s.bytes()), + // Lazy partitions are not created during install/update, so + // skip them here. + PartitionSize::Lazy => continue, }; repart.push_partition_entry(RepartPartitionEntry { diff --git a/src/offline_init/mod.rs b/src/offline_init/mod.rs index aaae411fa..9799aa580 100644 --- a/src/offline_init/mod.rs +++ b/src/offline_init/mod.rs @@ -41,6 +41,9 @@ struct PrismPartition { #[serde(rename = "type")] ty: Option, + + #[serde(default)] + lazy: bool, } #[derive(Debug, serde::Deserialize)] @@ -151,8 +154,9 @@ fn generate_host_status( id: lazy_partition_b.to_string(), // "Empty" settings for remaining properties start: "0".to_string(), - size: None, + size: Some("0G".to_string()), ty: None, + lazy: true, }; prism_partitions.push(lazy_partition); } @@ -169,11 +173,15 @@ fn generate_host_status( } else { PartitionType::LinuxGeneric }, - size: match &partition.size { - Some(s) => PartitionSize::from_str(s) - .structured(InvalidInputError::ParsePrismHistory) - .message(format!("Failed to parse partition size '{s}'"))?, - None => PartitionSize::Grow, + size: if partition.lazy { + PartitionSize::Lazy + } else { + match &partition.size { + Some(s) => PartitionSize::from_str(s) + .structured(InvalidInputError::ParsePrismHistory) + .message(format!("Failed to parse partition size '{s}'"))?, + None => PartitionSize::Grow, + } }, }); } @@ -643,7 +651,7 @@ mod tests { host_status.partition_paths.get("usr-hash-b").unwrap(), &PathBuf::from(format!("/dev/disk/by-partuuid/{usr_hash_b_uuid}")) ); - assert_eq!(host_status.partition_paths.len(), 12); + assert_eq!(host_status.partition_paths.len(), 121); } #[test] diff --git a/trident_api/src/config/host/storage/partitions.rs b/trident_api/src/config/host/storage/partitions.rs index 756cf66e5..4338836eb 100644 --- a/trident_api/src/config/host/storage/partitions.rs +++ b/trident_api/src/config/host/storage/partitions.rs @@ -6,7 +6,11 @@ use uuid::Uuid; #[cfg(feature = "schemars")] use schemars::JsonSchema; -use crate::{constants::PARTITION_SIZE_GROW, primitives::bytes::ByteCount, BlockDeviceId}; +use crate::{ + constants::{PARTITION_SIZE_GROW, PARTITION_SIZE_LAZY}, + primitives::bytes::ByteCount, + BlockDeviceId, +}; #[cfg(feature = "schemars")] use crate::schema_helpers::{block_device_id_schema, unit_enum_with_untagged_variant}; @@ -208,6 +212,11 @@ pub enum PartitionSize { /// Grow a partition to use all available space. Grow, + /// # Lazy + /// + /// No size specified, parition will not be created during install or update. + Lazy, + /// # Fixed /// /// Fixed size in bytes. Must be a non-zero multiple of 4096 bytes. @@ -222,6 +231,8 @@ impl FromStr for PartitionSize { let s = s.trim(); Ok(if s == PARTITION_SIZE_GROW { PartitionSize::Grow + } else if s == PARTITION_SIZE_LAZY { + PartitionSize::Lazy } else { PartitionSize::Fixed(ByteCount::from_human_readable(s)?) }) @@ -233,6 +244,7 @@ impl Display for PartitionSize { match self { PartitionSize::Fixed(n) => write!(f, "{}", n.to_human_readable()), PartitionSize::Grow => write!(f, "{PARTITION_SIZE_GROW}"), + PartitionSize::Lazy => write!(f, "lazy"), } } } @@ -249,6 +261,7 @@ impl PartitionSize { match self { PartitionSize::Fixed(size) => Some(size.bytes()), PartitionSize::Grow => None, + PartitionSize::Lazy => None, } } } @@ -276,11 +289,18 @@ mod tests { size: PartitionSize::Grow, } } + + fn lazy() -> Self { + Self { + size: PartitionSize::Lazy, + } + } } // Define test cases let test_cases = [ ("size: grow", TestStruct::grow(), "size: grow"), + ("size: lazy", TestStruct::lazy(), "size: lazy"), ("size: 1", TestStruct::fixed(1), "size: 1"), ("size: 512", TestStruct::fixed(512), "size: 512"), ("size: 1K", TestStruct::fixed(1024), "size: 1K"), diff --git a/trident_api/src/config/host/storage/storage_graph/rules/mod.rs b/trident_api/src/config/host/storage/storage_graph/rules/mod.rs index 1a74a5742..2fb6744f6 100644 --- a/trident_api/src/config/host/storage/storage_graph/rules/mod.rs +++ b/trident_api/src/config/host/storage/storage_graph/rules/mod.rs @@ -77,6 +77,10 @@ impl HostConfigBlockDevice { size: PartitionSize::Grow, .. }) => (), + Self::Partition(Partition { + size: PartitionSize::Lazy, + .. + }) => (), Self::AdoptedPartition(ap) => match (&ap.match_label, &ap.match_uuid) { (Some(_), Some(_)) => { bail!("Adopted partitions cannot have both matchLabel and matchUUID"); diff --git a/trident_api/src/constants.rs b/trident_api/src/constants.rs index 51e87949d..f6e5b7734 100644 --- a/trident_api/src/constants.rs +++ b/trident_api/src/constants.rs @@ -5,6 +5,9 @@ use const_format::formatcp; /// Size of a partition that will be grown to fill all available space. pub const PARTITION_SIZE_GROW: &str = "grow"; +/// Size of a partition that will be not be created during install or update. +pub const PARTITION_SIZE_LAZY: &str = "lazy"; + /// Default interpreter to use for scripts if not specified. pub const DEFAULT_SCRIPT_INTERPRETER: &str = "/bin/sh";