Skip to content

Commit 0b6ab45

Browse files
composefs-backend: Fix bootc status for systemd-boot
Signed-off-by: Pragyan Poudyal <[email protected]>
1 parent 86cbda4 commit 0b6ab45

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();
@@ -358,41 +358,63 @@ pub(crate) async fn composefs_deployment_status() -> Result<Host> {
358358
}
359359
};
360360

361-
match boot_type {
362-
BootType::Bls => {
363-
let bls_config = get_sorted_bls_boot_entries(&boot_dir, false)?;
364-
let bls_config = bls_config
365-
.first()
366-
.ok_or(anyhow::anyhow!("First boot entry not found"))?;
367-
368-
match &bls_config.cfg_type {
369-
BLSConfigType::EFI { efi } => {
370-
host.status.rollback_queued = efi.contains(composefs_digest.as_ref());
371-
}
361+
let is_rollback_queued = match booted.bootloader {
362+
Bootloader::Grub => match boot_type {
363+
BootType::Bls => {
364+
let bls_config = get_sorted_type1_boot_entries(&boot_dir, false)?;
365+
let bls_config = bls_config
366+
.first()
367+
.ok_or(anyhow::anyhow!("First boot entry not found"))?;
372368

373-
BLSConfigType::NonEFI { options, .. } => {
374-
host.status.rollback_queued = !options
369+
match &bls_config.cfg_type {
370+
BLSConfigType::NonEFI { options, .. } => !options
375371
.as_ref()
376372
.ok_or(anyhow::anyhow!("options key not found in bls config"))?
377-
.contains(composefs_digest.as_ref());
373+
.contains(composefs_digest.as_ref()),
374+
375+
BLSConfigType::EFI { .. } => {
376+
anyhow::bail!("Found 'efi' field in Type1 boot entry")
377+
}
378+
BLSConfigType::Unknown => anyhow::bail!("Unknown BLS Config Type"),
378379
}
380+
}
379381

380-
BLSConfigType::Unknown => todo!(),
381-
};
382-
}
382+
BootType::Uki => {
383+
let mut s = String::new();
383384

384-
BootType::Uki => {
385-
let mut s = String::new();
385+
!get_sorted_uki_boot_entries(&boot_dir, &mut s)?
386+
.first()
387+
.ok_or(anyhow::anyhow!("First boot entry not found"))?
388+
.body
389+
.chainloader
390+
.contains(composefs_digest.as_ref())
391+
}
392+
},
386393

387-
host.status.rollback_queued = !get_sorted_uki_boot_entries(&boot_dir, &mut s)?
394+
// We will have BLS stuff and the UKI stuff in the same DIR
395+
Bootloader::Systemd => {
396+
let bls_config = get_sorted_type1_boot_entries(&boot_dir, false)?;
397+
let bls_config = bls_config
388398
.first()
389-
.ok_or(anyhow::anyhow!("First boot entry not found"))?
390-
.body
391-
.chainloader
392-
.contains(composefs_digest.as_ref())
399+
.ok_or(anyhow::anyhow!("First boot entry not found"))?;
400+
401+
match &bls_config.cfg_type {
402+
// For UKI boot
403+
BLSConfigType::EFI { efi } => efi.contains(composefs_digest.as_ref()),
404+
405+
// For boot entry Type1
406+
BLSConfigType::NonEFI { options, .. } => !options
407+
.as_ref()
408+
.ok_or(anyhow::anyhow!("options key not found in bls config"))?
409+
.contains(composefs_digest.as_ref()),
410+
411+
BLSConfigType::Unknown => anyhow::bail!("Unknown BLS Config Type"),
412+
}
393413
}
394414
};
395415

416+
host.status.rollback_queued = is_rollback_queued;
417+
396418
if host.status.rollback_queued {
397419
host.spec.boot_order = BootOrder::Rollback
398420
};
@@ -449,7 +471,7 @@ mod tests {
449471
tempdir.atomic_write("loader/entries/entry1.conf", entry1)?;
450472
tempdir.atomic_write("loader/entries/entry2.conf", entry2)?;
451473

452-
let result = get_sorted_bls_boot_entries(&tempdir, true).unwrap();
474+
let result = get_sorted_type1_boot_entries(&tempdir, true).unwrap();
453475

454476
let mut config1 = BLSConfig::default();
455477
config1.title = Some("Fedora 42.20250623.3.1 (CoreOS)".into());
@@ -472,7 +494,7 @@ mod tests {
472494
assert_eq!(result[0].sort_key.as_ref().unwrap(), "1");
473495
assert_eq!(result[1].sort_key.as_ref().unwrap(), "2");
474496

475-
let result = get_sorted_bls_boot_entries(&tempdir, false).unwrap();
497+
let result = get_sorted_type1_boot_entries(&tempdir, false).unwrap();
476498
assert_eq!(result[0].sort_key.as_ref().unwrap(), "2");
477499
assert_eq!(result[1].sort_key.as_ref().unwrap(), "1");
478500

0 commit comments

Comments
 (0)