Skip to content

Commit 2db3be9

Browse files
composefs/boot: Get os_id from mounted EROFS
Instead of reading the in memory filesystem to get /usr/lib/os-release get it from the mounted EROFS. This is also prep for providing backwards compatibility due to our newly introduced prefix `bootc_composefs-` where we'll need to create new boot entries and we can get the `os_id` from the mounted root Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent f3d2d4e commit 2db3be9

File tree

1 file changed

+13
-32
lines changed
  • crates/lib/src/bootc_composefs

1 file changed

+13
-32
lines changed

crates/lib/src/bootc_composefs/boot.rs

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161
//! 1. **Primary**: New/upgraded deployment (default boot target)
6262
//! 2. **Secondary**: Currently booted deployment (rollback option)
6363
64-
use std::ffi::OsStr;
6564
use std::fs::create_dir_all;
65+
use std::io::Read;
6666
use std::io::Write;
6767
use std::path::Path;
6868

@@ -451,41 +451,22 @@ fn write_bls_boot_entries_to_disk(
451451
}
452452

453453
/// Parses /usr/lib/os-release and returns (id, title, version)
454-
fn parse_os_release(
455-
fs: &crate::store::ComposefsFilesystem,
456-
repo: &crate::store::ComposefsRepository,
457-
) -> Result<Option<(String, Option<String>, Option<String>)>> {
454+
/// Expects a referenece to the root of the filesystem, or the root
455+
/// of a mounted EROFS
456+
pub fn parse_os_release(root: &Dir) -> Result<Option<(String, Option<String>, Option<String>)>> {
458457
// Every update should have its own /usr/lib/os-release
459-
let (dir, fname) = fs
460-
.root
461-
.split(OsStr::new("/usr/lib/os-release"))
462-
.context("Getting /usr/lib/os-release")?;
463-
464-
let os_release = dir
465-
.get_file_opt(fname)
466-
.context("Getting /usr/lib/os-release")?;
458+
let file = root
459+
.open_optional("usr/lib/os-release")
460+
.context("Opening usr/lib/os-release")?;
467461

468-
let Some(os_rel_file) = os_release else {
462+
let Some(mut os_rel_file) = file else {
469463
return Ok(None);
470464
};
471465

472-
let file_contents = match read_file(os_rel_file, repo) {
473-
Ok(c) => c,
474-
Err(e) => {
475-
tracing::warn!("Could not read /usr/lib/os-release: {e:?}");
476-
return Ok(None);
477-
}
478-
};
479-
480-
let file_contents = match std::str::from_utf8(&file_contents) {
481-
Ok(c) => c,
482-
Err(e) => {
483-
tracing::warn!("/usr/lib/os-release did not have valid UTF-8: {e}");
484-
return Ok(None);
485-
}
486-
};
466+
let mut file_contents = String::new();
467+
os_rel_file.read_to_string(&mut file_contents)?;
487468

488-
let parsed = OsReleaseInfo::parse(file_contents);
469+
let parsed = OsReleaseInfo::parse(&file_contents);
489470

490471
let os_id = parsed
491472
.get_value(&["ID"])
@@ -521,7 +502,7 @@ pub(crate) fn setup_composefs_bls_boot(
521502
) -> Result<String> {
522503
let id_hex = id.to_hex();
523504

524-
let (root_path, esp_device, mut cmdline_refs, fs, bootloader) = match setup_type {
505+
let (root_path, esp_device, mut cmdline_refs, _, bootloader) = match setup_type {
525506
BootSetupType::Setup((root_setup, state, postfetch, fs)) => {
526507
// root_setup.kargs has [root=UUID=<UUID>, "rw"]
527508
let mut cmdline_options = Cmdline::new();
@@ -668,7 +649,7 @@ pub(crate) fn setup_composefs_bls_boot(
668649
let boot_digest = compute_boot_digest(usr_lib_modules_vmlinuz, &repo)
669650
.context("Computing boot digest")?;
670651

671-
let osrel = parse_os_release(fs, &repo)?;
652+
let osrel = parse_os_release(mounted_erofs)?;
672653

673654
let (os_id, title, version, sort_key) = match osrel {
674655
Some((id_str, title_opt, version_opt)) => (

0 commit comments

Comments
 (0)