Skip to content

Commit 2b995c3

Browse files
kargs: Handle addition/removal of kargs from kargs.d
Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent 2f51c81 commit 2b995c3

File tree

2 files changed

+49
-29
lines changed

2 files changed

+49
-29
lines changed

crates/lib/src/bootc_composefs/boot.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ pub(crate) fn setup_composefs_bls_boot(
381381
repo: crate::store::ComposefsRepository,
382382
id: &Sha512HashValue,
383383
entry: &ComposefsBootEntry<Sha512HashValue>,
384-
mounted_erofs: &Dir
384+
mounted_erofs: &Dir,
385385
) -> Result<String> {
386386
let id_hex = id.to_hex();
387387

@@ -446,10 +446,16 @@ pub(crate) fn setup_composefs_bls_boot(
446446
}
447447
};
448448

449-
kargs_from_composefs_filesystem(mounted_erofs, &mut cmdline_refs)?;
450-
451449
let is_upgrade = matches!(setup_type, BootSetupType::Upgrade(..));
452450

451+
let current_root = if is_upgrade {
452+
Some(&Dir::open_ambient_dir("/", ambient_authority()).context("Opening root")?)
453+
} else {
454+
None
455+
};
456+
457+
kargs_from_composefs_filesystem(mounted_erofs, current_root, &mut cmdline_refs)?;
458+
453459
let (entry_paths, _tmpdir_guard) = match bootloader {
454460
Bootloader::Grub => {
455461
let root = Dir::open_ambient_dir(&root_path, ambient_authority())
@@ -1076,7 +1082,7 @@ pub(crate) fn setup_composefs_boot(
10761082
repo,
10771083
&id,
10781084
entry,
1079-
&mounted_fs
1085+
&mounted_fs,
10801086
)?;
10811087

10821088
boot_digest = Some(digest);

crates/lib/src/bootc_kargs.rs

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,49 @@ impl Config {
4545
}
4646
}
4747

48+
/// Compute the diff between existing and remote kargs
49+
/// Apply the diff to the new kargs
50+
fn compute_apply_kargs_diff(
51+
existing_kargs: &Cmdline,
52+
remote_kargs: &Cmdline,
53+
new_kargs: &mut Cmdline,
54+
) {
55+
// Calculate the diff between the existing and remote kargs
56+
let added_kargs: Vec<_> = remote_kargs
57+
.iter()
58+
.filter(|item| !existing_kargs.iter().any(|existing| *item == existing))
59+
.collect();
60+
let removed_kargs: Vec<_> = existing_kargs
61+
.iter()
62+
.filter(|item| !remote_kargs.iter().any(|remote| *item == remote))
63+
.collect();
64+
65+
tracing::debug!("kargs: added={:?} removed={:?}", added_kargs, removed_kargs);
66+
67+
// Apply the diff to the system kargs
68+
for arg in &removed_kargs {
69+
new_kargs.remove_exact(arg);
70+
}
71+
for arg in &added_kargs {
72+
new_kargs.add(arg);
73+
}
74+
}
75+
4876
/// Looks for files in usr/lib/bootc/kargs.d and parses cmdline agruments
4977
pub(crate) fn kargs_from_composefs_filesystem(
5078
new_fs: &Dir,
51-
cmdline: &mut Cmdline,
79+
current_root: Option<&Dir>,
80+
new_kargs: &mut Cmdline,
5281
) -> Result<()> {
5382
let remote_kargs = get_kargs_in_root(new_fs, std::env::consts::ARCH)?;
54-
cmdline.extend(&remote_kargs);
83+
84+
let existing_kargs = match current_root {
85+
Some(root) => get_kargs_in_root(root, std::env::consts::ARCH)?,
86+
None => Cmdline::new(),
87+
};
88+
89+
compute_apply_kargs_diff(&existing_kargs, &remote_kargs, new_kargs);
90+
5591
Ok(())
5692
}
5793

@@ -185,29 +221,7 @@ pub(crate) fn get_kargs(
185221
// Fetch the kernel arguments from the new root
186222
let remote_kargs = get_kargs_from_ostree(repo, &fetched_tree, sys_arch)?;
187223

188-
// Calculate the diff between the existing and remote kargs
189-
let added_kargs: Vec<_> = remote_kargs
190-
.iter()
191-
.filter(|item| !existing_kargs.iter().any(|existing| *item == existing))
192-
.collect();
193-
let removed_kargs: Vec<_> = existing_kargs
194-
.iter()
195-
.filter(|item| !remote_kargs.iter().any(|remote| *item == remote))
196-
.collect();
197-
198-
tracing::debug!(
199-
"kargs: added={:?} removed={:?}",
200-
&added_kargs,
201-
removed_kargs
202-
);
203-
204-
// Apply the diff to the system kargs
205-
for arg in &removed_kargs {
206-
kargs.remove_exact(arg);
207-
}
208-
for arg in &added_kargs {
209-
kargs.add(arg);
210-
}
224+
compute_apply_kargs_diff(&existing_kargs, &remote_kargs, &mut kargs);
211225

212226
Ok(kargs)
213227
}

0 commit comments

Comments
 (0)