Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,9 @@ fn handle_bls_conf(
cfs_cmdline: &ComposefsCmdline,
boot_dir: &Dir,
is_uki: bool,
bootloader: crate::spec::Bootloader,
) -> Result<()> {
let entries = get_sorted_type1_boot_entries(boot_dir, true)?;
let entries = get_sorted_type1_boot_entries(boot_dir, true, bootloader)?;
let (rename_transaction, new_bls_entries) =
stage_bls_entry_changes(storage, boot_dir, &entries, cfs_cmdline)?;

Expand Down Expand Up @@ -324,7 +325,7 @@ pub(crate) async fn prepend_custom_prefix(

match get_boot_type(storage, cfs_cmdline)? {
BootType::Bls => {
handle_bls_conf(storage, cfs_cmdline, boot_dir, false)?;
handle_bls_conf(storage, cfs_cmdline, boot_dir, false, bootloader)?;
}

BootType::Uki => match bootloader.kind()? {
Expand Down Expand Up @@ -389,7 +390,7 @@ pub(crate) async fn prepend_custom_prefix(
}

BootloaderKind::BLSCompatible => {
handle_bls_conf(storage, cfs_cmdline, boot_dir, true)?;
handle_bls_conf(storage, cfs_cmdline, boot_dir, true, bootloader)?;
}
},
};
Expand Down
4 changes: 2 additions & 2 deletions crates/lib/src/bootc_composefs/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ pub(crate) fn setup_composefs_bls_boot(
}

BootSetupType::Upgrade((storage, booted_cfs, host)) => {
let bootloader = host.require_composefs_booted()?.bootloader.clone();
let bootloader = host.require_composefs_booted()?.require_bootloader()?;

let boot_dir = storage.require_boot_dir()?;
let current_cfg = get_booted_bls(&boot_dir, booted_cfs)?;
Expand Down Expand Up @@ -1095,7 +1095,7 @@ pub(crate) fn setup_composefs_uki_boot(

BootSetupType::Upgrade((storage, booted_cfs, host)) => {
let sysroot = Utf8PathBuf::from("/sysroot"); // Still needed for root_path
let bootloader = host.require_composefs_booted()?.bootloader.clone();
let bootloader = host.require_composefs_booted()?.require_bootloader()?;

// Locate ESP partition device by walking up to the root disk(s)
let root_dev = bootc_blockdev::list_dev_by_dir(&storage.physical_root)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/lib/src/bootc_composefs/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ fn delete_depl_boot_entries(
) -> Result<()> {
let boot_dir = storage.require_boot_dir()?;

match deployment.deployment.bootloader.kind()? {
match deployment.deployment.require_bootloader()?.kind()? {
BootloaderKind::GRUBClassic => match deployment.deployment.boot_type {
BootType::Bls => delete_type1_conf_file(deployment, boot_dir, deleting_staged),
BootType::Uki => {
Expand Down
2 changes: 1 addition & 1 deletion crates/lib/src/bootc_composefs/finalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub(crate) async fn composefs_backend_finalize(

let boot_dir = storage.require_boot_dir()?;

match booted_composefs.bootloader.kind()? {
match booted_composefs.require_bootloader()?.kind()? {
BootloaderKind::GRUBClassic => match staged_composefs.boot_type {
BootType::Bls => {
let entries_dir = boot_dir.open_dir("loader")?;
Expand Down
32 changes: 17 additions & 15 deletions crates/lib/src/bootc_composefs/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ pub(crate) async fn composefs_gc(

let sysroot = &storage.physical_root;

let bootloader_entries = list_bootloader_entries(storage)?;
let bootloader_entries =
list_bootloader_entries(storage, booted_cfs_status.require_bootloader()?)?;
let boot_binaries = collect_boot_binaries(storage)?;

tracing::debug!("bootloader_entries: {bootloader_entries:?}");
Expand Down Expand Up @@ -501,6 +502,7 @@ pub(crate) async fn composefs_gc(
mod tests {
use super::*;
use crate::bootc_composefs::status::list_type1_entries;
use crate::spec::Bootloader;
use crate::testutils::{ChangeType, TestRoot};

/// Reproduce the shared-entry GC bug from issue #2102.
Expand Down Expand Up @@ -555,7 +557,7 @@ mod tests {
);

// Collect what the BLS entries reference
let bls_entries = list_type1_entries(&boot_dir)?;
let bls_entries = list_type1_entries(&boot_dir, Bootloader::Systemd)?;
assert_eq!(bls_entries.len(), 2, "D (primary) + C (secondary)");

// The fix: unreferenced_boot_binaries uses boot_artifact_name.
Expand Down Expand Up @@ -585,7 +587,7 @@ mod tests {
// A's dir + C's dir still on disk (boot binary cleanup hasn't run)
assert_eq!(on_disk_2.len(), 2);

let bls_entries_2 = list_type1_entries(&root.boot_dir()?)?;
let bls_entries_2 = list_type1_entries(&root.boot_dir()?, Bootloader::Systemd)?;
// D (primary) + B (secondary)
assert_eq!(bls_entries_2.len(), 2);

Expand Down Expand Up @@ -638,7 +640,7 @@ mod tests {
let digest_b = root.current().verity.clone();

let boot_dir = root.boot_dir()?;
let bls_entries = list_type1_entries(&boot_dir)?;
let bls_entries = list_type1_entries(&boot_dir, Bootloader::Systemd)?;

assert_eq!(bls_entries.len(), 2, "Should find both BLS entries");

Expand Down Expand Up @@ -709,7 +711,7 @@ mod tests {
assert_eq!(on_disk.len(), 2, "Should see A's and C's boot dirs");

// BLS entries should correctly reference boot artifact names
let bls_entries = list_type1_entries(&boot_dir)?;
let bls_entries = list_type1_entries(&boot_dir, Bootloader::Systemd)?;
assert_eq!(bls_entries.len(), 2);

// No boot dirs should be unreferenced (all are in use)
Expand All @@ -723,7 +725,7 @@ mod tests {
root.gc_deployment(&digest_a)?;

let boot_dir = root.boot_dir()?;
let bls_entries = list_type1_entries(&boot_dir)?;
let bls_entries = list_type1_entries(&boot_dir, Bootloader::Systemd)?;
assert_eq!(bls_entries.len(), 2, "B (secondary) + C (primary)");

let mut on_disk = Vec::new();
Expand Down Expand Up @@ -771,7 +773,7 @@ mod tests {
let mut on_disk = Vec::new();
collect_type1_boot_binaries(&boot_dir, &mut on_disk)?;

let bls_entries = list_type1_entries(&boot_dir)?;
let bls_entries = list_type1_entries(&boot_dir, Bootloader::Systemd)?;
assert_eq!(bls_entries.len(), 2, "D (primary) + C (secondary)");

let unreferenced = unreferenced_boot_binaries(&on_disk, &bls_entries);
Expand Down Expand Up @@ -830,7 +832,7 @@ mod tests {
assert_eq!(on_disk[0].1, digest_a, "The boot dir belongs to A");

// BLS entries: D (primary) + C (secondary), both referencing A's dir
let bls_entries = list_type1_entries(&boot_dir)?;
let bls_entries = list_type1_entries(&boot_dir, Bootloader::Systemd)?;
assert_eq!(bls_entries.len(), 2);
for entry in &bls_entries {
assert_eq!(
Expand All @@ -843,7 +845,7 @@ mod tests {
root.gc_deployment(&digest_a)?;

let boot_dir = root.boot_dir()?;
let bls_entries = list_type1_entries(&boot_dir)?;
let bls_entries = list_type1_entries(&boot_dir, Bootloader::Systemd)?;
// D (primary) + C (secondary) — A was already evicted from BLS
assert_eq!(bls_entries.len(), 2);

Expand All @@ -864,7 +866,7 @@ mod tests {

// D is the only deployment left
let boot_dir = root.boot_dir()?;
let bls_entries = list_type1_entries(&boot_dir)?;
let bls_entries = list_type1_entries(&boot_dir, Bootloader::Systemd)?;
assert_eq!(bls_entries.len(), 1, "Only D remains");
assert_eq!(bls_entries[0].fsverity, digest_d);
assert_eq!(
Expand Down Expand Up @@ -901,7 +903,7 @@ mod tests {

// -- Pre-migration: all entries lack the prefix --
let boot_dir = root.boot_dir()?;
let raw_entries = get_sorted_type1_boot_entries(&boot_dir, true)?;
let raw_entries = get_sorted_type1_boot_entries(&boot_dir, true, Bootloader::Systemd)?;
assert_eq!(raw_entries.len(), 2);

let needs_migration: Vec<_> = raw_entries
Expand All @@ -924,7 +926,7 @@ mod tests {

// -- Post-migration: all entries have the prefix --
let boot_dir = root.boot_dir()?;
let raw_entries = get_sorted_type1_boot_entries(&boot_dir, true)?;
let raw_entries = get_sorted_type1_boot_entries(&boot_dir, true, Bootloader::Systemd)?;
assert_eq!(raw_entries.len(), 2);

let needs_migration: Vec<_> = raw_entries
Expand All @@ -942,7 +944,7 @@ mod tests {
assert_eq!(on_disk.len(), 2, "Both dirs visible after migration");

// GC filter correctly identifies all dirs as referenced
let bls_entries = list_type1_entries(&boot_dir)?;
let bls_entries = list_type1_entries(&boot_dir, Bootloader::Systemd)?;
let unreferenced = unreferenced_boot_binaries(&on_disk, &bls_entries);
assert!(
unreferenced.is_empty(),
Expand All @@ -953,7 +955,7 @@ mod tests {
root.upgrade(3, ChangeType::Kernel)?;

let boot_dir = root.boot_dir()?;
let raw_entries = get_sorted_type1_boot_entries(&boot_dir, true)?;
let raw_entries = get_sorted_type1_boot_entries(&boot_dir, true, Bootloader::Systemd)?;
// All entries (both migrated and new) should have the prefix
for entry in &raw_entries {
let (_, has_prefix) = entry.boot_artifact_info()?;
Expand All @@ -970,7 +972,7 @@ mod tests {
assert_eq!(on_disk.len(), 3, "Three boot dirs on disk");

// Only 2 BLS entries (primary + secondary), so one dir is unreferenced
let bls_entries = list_type1_entries(&boot_dir)?;
let bls_entries = list_type1_entries(&boot_dir, Bootloader::Systemd)?;
assert_eq!(bls_entries.len(), 2);
let unreferenced = unreferenced_boot_binaries(&on_disk, &bls_entries);
assert_eq!(
Expand Down
10 changes: 6 additions & 4 deletions crates/lib/src/bootc_composefs/rollback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn rollback_grub_uki_entries(boot_dir: &Dir) -> Result<()> {
#[context("Rolling back {bootloader} entries")]
fn rollback_composefs_entries(host: &Host, boot_dir: &Dir, bootloader: Bootloader) -> Result<()> {
// Get all boot entries sorted in descending order by sort-key
let mut all_configs = get_sorted_type1_boot_entries(&boot_dir, false)?;
let mut all_configs = get_sorted_type1_boot_entries(&boot_dir, false, bootloader)?;

// TODO(Johan-Liebert): Currently assuming there are only two deployments
assert!(all_configs.len() == 2);
Expand Down Expand Up @@ -252,10 +252,12 @@ pub(crate) async fn composefs_rollback(

let boot_dir = storage.require_boot_dir()?;

match &rollback_entry.bootloader.kind()? {
let bootloader = rollback_entry.require_bootloader()?;

match bootloader.kind()? {
BootloaderKind::GRUBClassic => match rollback_entry.boot_type {
BootType::Bls => {
rollback_composefs_entries(&host, boot_dir, rollback_entry.bootloader.clone())?;
rollback_composefs_entries(&host, boot_dir, bootloader)?;
}
BootType::Uki => {
rollback_grub_uki_entries(boot_dir)?;
Expand All @@ -264,7 +266,7 @@ pub(crate) async fn composefs_rollback(

BootloaderKind::BLSCompatible => {
// We use BLS entries for systemd UKI as well
rollback_composefs_entries(&host, boot_dir, rollback_entry.bootloader.clone())?;
rollback_composefs_entries(&host, boot_dir, bootloader)?;
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/lib/src/bootc_composefs/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use rustix::{

use crate::bootc_composefs::boot::BootType;
use crate::bootc_composefs::status::{
ComposefsCmdline, StagedDeployment, get_sorted_type1_boot_entries,
ComposefsCmdline, StagedDeployment, get_bootloader, get_sorted_type1_boot_entries,
};
use crate::parsers::bls_config::{BLSConfigType, EFIKey};
use crate::store::{BootedComposefs, Storage};
Expand Down Expand Up @@ -65,7 +65,7 @@ pub(crate) fn read_origin(sysroot: &Dir, deployment_id: &str) -> Result<Option<t
}

pub(crate) fn get_booted_bls(boot_dir: &Dir, booted_cfs: &BootedComposefs) -> Result<BLSConfig> {
let sorted_entries = get_sorted_type1_boot_entries(boot_dir, true)?;
let sorted_entries = get_sorted_type1_boot_entries(boot_dir, true, get_bootloader()?)?;

for entry in sorted_entries {
match &entry.cfg_type {
Expand Down
Loading