Skip to content
Closed
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
3 changes: 3 additions & 0 deletions src/engine/storage/partitioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 15 additions & 7 deletions src/offline_init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ struct PrismPartition {

#[serde(rename = "type")]
ty: Option<String>,

#[serde(default)]
lazy: bool,
}

#[derive(Debug, serde::Deserialize)]
Expand Down Expand Up @@ -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);
}
Expand All @@ -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,
}
},
});
}
Expand Down Expand Up @@ -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]
Expand Down
22 changes: 21 additions & 1 deletion trident_api/src/config/host/storage/partitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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.
Expand All @@ -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)?)
})
Expand All @@ -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"),
}
}
}
Expand All @@ -249,6 +261,7 @@ impl PartitionSize {
match self {
PartitionSize::Fixed(size) => Some(size.bytes()),
PartitionSize::Grow => None,
PartitionSize::Lazy => None,
}
}
}
Expand Down Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
3 changes: 3 additions & 0 deletions trident_api/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down