Skip to content

Commit 95fe0dc

Browse files
composefs-backend: Fix bootc status for systemd-boot
Signed-off-by: Pragyan Poudyal <[email protected]>
1 parent 30a66a4 commit 95fe0dc

File tree

2 files changed

+54
-32
lines changed

2 files changed

+54
-32
lines changed

crates/lib/src/bootc_composefs/rollback.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use fn_error_context::context;
88
use rustix::fs::{fsync, renameat_with, AtFlags, RenameFlags};
99

1010
use crate::bootc_composefs::boot::BootType;
11-
use crate::bootc_composefs::status::{composefs_deployment_status, get_sorted_bls_boot_entries};
11+
use crate::bootc_composefs::status::{composefs_deployment_status, get_sorted_type1_boot_entries};
1212
use crate::{
1313
bootc_composefs::{boot::get_efi_uuid_source, status::get_sorted_uki_boot_entries},
1414
composefs_consts::{
@@ -110,7 +110,7 @@ pub(crate) fn rollback_composefs_bls() -> Result<()> {
110110
// After this:
111111
// all_configs[0] -> booted depl
112112
// all_configs[1] -> rollback depl
113-
let mut all_configs = get_sorted_bls_boot_entries(&boot_dir, false)?;
113+
let mut all_configs = get_sorted_type1_boot_entries(&boot_dir, false)?;
114114

115115
// Update the indicies so that they're swapped
116116
for (idx, cfg) in all_configs.iter_mut().enumerate() {

crates/lib/src/bootc_composefs/status.rs

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use fn_error_context::context;
77

88
use crate::{
99
bootc_composefs::boot::{get_esp_partition, get_sysroot_parent_dev, BootType},
10-
composefs_consts::{BOOT_LOADER_ENTRIES, COMPOSEFS_CMDLINE, USER_CFG},
10+
composefs_consts::{COMPOSEFS_CMDLINE, TYPE1_ENT_PATH, USER_CFG},
1111
parsers::{
1212
bls_config::{parse_bls_config, BLSConfig, BLSConfigType},
1313
grub_menuconfig::{parse_grub_menuentry_file, MenuEntry},
@@ -91,14 +91,14 @@ pub(crate) fn get_sorted_uki_boot_entries<'a>(
9191
parse_grub_menuentry_file(str)
9292
}
9393

94-
#[context("Getting sorted BLS entries")]
95-
pub(crate) fn get_sorted_bls_boot_entries(
94+
#[context("Getting sorted Type1 boot entries")]
95+
pub(crate) fn get_sorted_type1_boot_entries(
9696
boot_dir: &Dir,
9797
ascending: bool,
9898
) -> Result<Vec<BLSConfig>> {
9999
let mut all_configs = vec![];
100100

101-
for entry in boot_dir.read_dir(format!("loader/{BOOT_LOADER_ENTRIES}"))? {
101+
for entry in boot_dir.read_dir(TYPE1_ENT_PATH)? {
102102
let entry = entry?;
103103

104104
let file_name = entry.file_name();
@@ -374,41 +374,63 @@ pub(crate) async fn composefs_deployment_status() -> Result<Host> {
374374
}
375375
};
376376

377-
match boot_type {
378-
BootType::Bls => {
379-
let bls_config = get_sorted_bls_boot_entries(&boot_dir, false)?;
380-
let bls_config = bls_config
381-
.first()
382-
.ok_or(anyhow::anyhow!("First boot entry not found"))?;
383-
384-
match &bls_config.cfg_type {
385-
BLSConfigType::EFI { efi } => {
386-
host.status.rollback_queued = efi.contains(composefs_digest.as_ref());
387-
}
377+
let is_rollback_queued = match booted.bootloader {
378+
Bootloader::Grub => match boot_type {
379+
BootType::Bls => {
380+
let bls_config = get_sorted_type1_boot_entries(&boot_dir, false)?;
381+
let bls_config = bls_config
382+
.first()
383+
.ok_or(anyhow::anyhow!("First boot entry not found"))?;
388384

389-
BLSConfigType::NonEFI { options, .. } => {
390-
host.status.rollback_queued = !options
385+
match &bls_config.cfg_type {
386+
BLSConfigType::NonEFI { options, .. } => !options
391387
.as_ref()
392388
.ok_or(anyhow::anyhow!("options key not found in bls config"))?
393-
.contains(composefs_digest.as_ref());
389+
.contains(composefs_digest.as_ref()),
390+
391+
BLSConfigType::EFI { .. } => {
392+
anyhow::bail!("Found 'efi' field in Type1 boot entry")
393+
}
394+
BLSConfigType::Unknown => anyhow::bail!("Unknown BLS Config Type"),
394395
}
396+
}
395397

396-
BLSConfigType::Unknown => todo!(),
397-
};
398-
}
398+
BootType::Uki => {
399+
let mut s = String::new();
399400

400-
BootType::Uki => {
401-
let mut s = String::new();
401+
!get_sorted_uki_boot_entries(&boot_dir, &mut s)?
402+
.first()
403+
.ok_or(anyhow::anyhow!("First boot entry not found"))?
404+
.body
405+
.chainloader
406+
.contains(composefs_digest.as_ref())
407+
}
408+
},
402409

403-
host.status.rollback_queued = !get_sorted_uki_boot_entries(&boot_dir, &mut s)?
410+
// We will have BLS stuff and the UKI stuff in the same DIR
411+
Bootloader::Systemd => {
412+
let bls_config = get_sorted_type1_boot_entries(&boot_dir, false)?;
413+
let bls_config = bls_config
404414
.first()
405-
.ok_or(anyhow::anyhow!("First boot entry not found"))?
406-
.body
407-
.chainloader
408-
.contains(composefs_digest.as_ref())
415+
.ok_or(anyhow::anyhow!("First boot entry not found"))?;
416+
417+
match &bls_config.cfg_type {
418+
// For UKI boot
419+
BLSConfigType::EFI { efi } => efi.contains(composefs_digest.as_ref()),
420+
421+
// For boot entry Type1
422+
BLSConfigType::NonEFI { options, .. } => !options
423+
.as_ref()
424+
.ok_or(anyhow::anyhow!("options key not found in bls config"))?
425+
.contains(composefs_digest.as_ref()),
426+
427+
BLSConfigType::Unknown => anyhow::bail!("Unknown BLS Config Type"),
428+
}
409429
}
410430
};
411431

432+
host.status.rollback_queued = is_rollback_queued;
433+
412434
if host.status.rollback_queued {
413435
host.spec.boot_order = BootOrder::Rollback
414436
};
@@ -465,7 +487,7 @@ mod tests {
465487
tempdir.atomic_write("loader/entries/entry1.conf", entry1)?;
466488
tempdir.atomic_write("loader/entries/entry2.conf", entry2)?;
467489

468-
let result = get_sorted_bls_boot_entries(&tempdir, true).unwrap();
490+
let result = get_sorted_type1_boot_entries(&tempdir, true).unwrap();
469491

470492
let mut config1 = BLSConfig::default();
471493
config1.title = Some("Fedora 42.20250623.3.1 (CoreOS)".into());
@@ -488,7 +510,7 @@ mod tests {
488510
assert_eq!(result[0].sort_key.as_ref().unwrap(), "1");
489511
assert_eq!(result[1].sort_key.as_ref().unwrap(), "2");
490512

491-
let result = get_sorted_bls_boot_entries(&tempdir, false).unwrap();
513+
let result = get_sorted_type1_boot_entries(&tempdir, false).unwrap();
492514
assert_eq!(result[0].sort_key.as_ref().unwrap(), "2");
493515
assert_eq!(result[1].sort_key.as_ref().unwrap(), "1");
494516

0 commit comments

Comments
 (0)