Skip to content

Commit 0334639

Browse files
jeckersbcgwalters
authored andcommitted
Use Cmdline for kargs fields in InstallConfigOpts and RootSetup
Plus all of the various places this trickles down. Signed-off-by: John Eckersberg <[email protected]>
1 parent c1e4a7a commit 0334639

File tree

4 files changed

+73
-43
lines changed

4 files changed

+73
-43
lines changed

crates/lib/src/bootc_composefs/boot.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::path::Path;
55

66
use anyhow::{anyhow, Context, Result};
77
use bootc_blockdev::find_parent_devices;
8+
use bootc_kernel_cmdline::utf8::Cmdline;
89
use bootc_mount::inspect_filesystem_of_dir;
910
use bootc_mount::tempmount::TempMount;
1011
use camino::{Utf8Path, Utf8PathBuf};
@@ -380,13 +381,17 @@ pub(crate) fn setup_composefs_bls_boot(
380381
let (root_path, esp_device, cmdline_refs, fs, bootloader) = match setup_type {
381382
BootSetupType::Setup((root_setup, state, fs)) => {
382383
// root_setup.kargs has [root=UUID=<UUID>, "rw"]
383-
let mut cmdline_options = String::from(root_setup.kargs.join(" "));
384+
let mut cmdline_options = Cmdline::new();
384385

385-
if state.composefs_options.insecure {
386-
cmdline_options.push_str(&format!(" {COMPOSEFS_CMDLINE}=?{id_hex}"));
386+
cmdline_options.extend(&root_setup.kargs);
387+
388+
let composefs_cmdline = if state.composefs_options.insecure {
389+
format!("{COMPOSEFS_CMDLINE}=?{id_hex}")
387390
} else {
388-
cmdline_options.push_str(&format!(" {COMPOSEFS_CMDLINE}={id_hex}"));
389-
}
391+
format!("{COMPOSEFS_CMDLINE}={id_hex}")
392+
};
393+
394+
cmdline_options.extend(&Cmdline::from(&composefs_cmdline));
390395

391396
// Locate ESP partition device
392397
let esp_part = esp_in(&root_setup.device_info)?;
@@ -407,12 +412,10 @@ pub(crate) fn setup_composefs_bls_boot(
407412
(
408413
Utf8PathBuf::from("/sysroot"),
409414
get_esp_partition(&sysroot_parent)?.0,
410-
[
411-
format!("root=UUID={}", this_arch_root()),
412-
RW_KARG.to_string(),
413-
format!("{COMPOSEFS_CMDLINE}={id_hex}"),
414-
]
415-
.join(" "),
415+
Cmdline::from(format!(
416+
"root=UUID={} {RW_KARG} {COMPOSEFS_CMDLINE}={id_hex}",
417+
this_arch_root()
418+
)),
416419
fs,
417420
bootloader,
418421
)

crates/lib/src/install.rs

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ pub(crate) struct InstallConfigOpts {
196196
///
197197
/// Example: --karg=nosmt --karg=console=ttyS0,115200n8
198198
#[clap(long)]
199-
pub(crate) karg: Option<Vec<String>>,
199+
pub(crate) karg: Option<Vec<CmdlineOwned>>,
200200

201201
/// The path to an `authorized_keys` that will be injected into the `root` account.
202202
///
@@ -920,7 +920,6 @@ async fn install_container(
920920
merged_ostree_root.downcast_ref().unwrap(),
921921
std::env::consts::ARCH,
922922
)?;
923-
let kargsd = kargsd.iter_str().collect::<Vec<_>>();
924923

925924
// If the target uses aboot, then we need to set that bootloader in the ostree
926925
// config before deploying the commit
@@ -942,28 +941,36 @@ async fn install_container(
942941
}
943942

944943
// Keep this in sync with install/completion.rs for the Anaconda fixups
945-
let install_config_kargs = state
946-
.install_config
947-
.as_ref()
948-
.and_then(|c| c.kargs.as_ref())
949-
.into_iter()
950-
.flatten()
951-
.map(|s| s.as_str());
944+
let install_config_kargs = state.install_config.as_ref().and_then(|c| c.kargs.as_ref());
945+
952946
// Final kargs, in order:
953947
// - root filesystem kargs
954948
// - install config kargs
955949
// - kargs.d from container image
956950
// - args specified on the CLI
957-
let kargs = root_setup
958-
.kargs
959-
.iter()
960-
.map(|v| v.as_str())
961-
.chain(install_config_kargs)
962-
.chain(kargsd)
963-
.chain(state.config_opts.karg.iter().flatten().map(|v| v.as_str()))
964-
.collect::<Vec<_>>();
951+
let mut kargs = Cmdline::new();
952+
953+
kargs.extend(&root_setup.kargs);
954+
955+
if let Some(install_config_kargs) = install_config_kargs {
956+
for karg in install_config_kargs {
957+
kargs.extend(&Cmdline::from(karg.as_str()));
958+
}
959+
}
960+
961+
kargs.extend(&kargsd);
962+
963+
if let Some(cli_kargs) = state.config_opts.karg.as_ref() {
964+
for karg in cli_kargs {
965+
kargs.extend(karg);
966+
}
967+
}
968+
969+
// Finally map into &[&str] for ostree_container
970+
let kargs_strs: Vec<&str> = kargs.iter_str().collect();
971+
965972
let mut options = ostree_container::deploy::DeployOpts::default();
966-
options.kargs = Some(kargs.as_slice());
973+
options.kargs = Some(kargs_strs.as_slice());
967974
options.target_imgref = Some(&state.target_imgref);
968975
options.proxy_cfg = proxy_cfg;
969976
options.skip_completion = true; // Must be set to avoid recursion!
@@ -1077,7 +1084,7 @@ pub(crate) struct RootSetup {
10771084
/// True if we should skip finalizing
10781085
skip_finalize: bool,
10791086
boot: Option<MountSpec>,
1080-
pub(crate) kargs: Vec<String>,
1087+
pub(crate) kargs: CmdlineOwned,
10811088
}
10821089

10831090
fn require_boot_uuid(spec: &MountSpec) -> Result<&str> {
@@ -1631,7 +1638,7 @@ async fn install_to_filesystem_impl(
16311638
cleanup: Cleanup,
16321639
) -> Result<()> {
16331640
if matches!(state.selinux_state, SELinuxFinalState::ForceTargetDisabled) {
1634-
rootfs.kargs.push("selinux=0".to_string());
1641+
rootfs.kargs.extend(&Cmdline::from("selinux=0"));
16351642
}
16361643
// Drop exclusive ownership since we're done with mutation
16371644
let rootfs = &*rootfs;
@@ -2167,6 +2174,8 @@ pub(crate) async fn install_to_filesystem(
21672174
kargs.push(bootarg);
21682175
}
21692176

2177+
let kargs = Cmdline::from(kargs.join(" "));
2178+
21702179
let skip_finalize =
21712180
matches!(fsopts.replace, Some(ReplaceMode::Alongside)) || fsopts.skip_finalize;
21722181
let mut rootfs = RootSetup {

crates/lib/src/install/baseline.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use super::State;
3030
use super::RUN_BOOTC;
3131
use super::RW_KARG;
3232
use crate::task::Task;
33+
use bootc_kernel_cmdline::utf8::Cmdline;
3334
#[cfg(feature = "install-to-disk")]
3435
use bootc_mount::is_mounted_in_pid1_mountns;
3536

@@ -424,13 +425,30 @@ pub(crate) fn install_create_rootfs(
424425
fstype: MountSpec::AUTO.into(),
425426
options: Some("ro".into()),
426427
});
427-
let kargs = root_blockdev_kargs
428-
.into_iter()
429-
.flatten()
430-
.chain([rootarg, RW_KARG.to_string()].into_iter())
431-
.chain(bootarg)
432-
.chain(state.config_opts.karg.clone().into_iter().flatten())
433-
.collect::<Vec<_>>();
428+
429+
let mut kargs = Cmdline::new();
430+
431+
// Add root blockdev kargs (e.g., LUKS parameters)
432+
if let Some(root_blockdev_kargs) = root_blockdev_kargs {
433+
for karg in root_blockdev_kargs {
434+
kargs.extend(&Cmdline::from(karg.as_str()));
435+
}
436+
}
437+
438+
// Add root= and rw argument
439+
kargs.extend(&Cmdline::from(format!("{rootarg} {RW_KARG}")));
440+
441+
// Add boot= argument if present
442+
if let Some(bootarg) = bootarg {
443+
kargs.extend(&Cmdline::from(bootarg.as_str()));
444+
}
445+
446+
// Add CLI kargs
447+
if let Some(cli_kargs) = state.config_opts.karg.as_ref() {
448+
for karg in cli_kargs {
449+
kargs.extend(karg);
450+
}
451+
}
434452

435453
bootc_mount::mount(&rootdev, &physical_root_path)?;
436454
let target_rootfs = Dir::open_ambient_dir(&physical_root_path, cap_std::ambient_authority())?;

crates/lib/src/parsers/bls_config.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#![allow(dead_code)]
66

77
use anyhow::{anyhow, Result};
8-
use bootc_kernel_cmdline::utf8::Cmdline;
8+
use bootc_kernel_cmdline::utf8::{Cmdline, CmdlineOwned};
99
use camino::Utf8PathBuf;
1010
use composefs_boot::bootloader::EFI_EXT;
1111
use core::fmt;
@@ -15,7 +15,7 @@ use uapi_version::Version;
1515

1616
use crate::composefs_consts::COMPOSEFS_CMDLINE;
1717

18-
#[derive(Debug, PartialEq, PartialOrd, Eq, Default)]
18+
#[derive(Debug, PartialEq, Eq, Default)]
1919
pub enum BLSConfigType {
2020
EFI {
2121
/// The path to the EFI binary, usually a UKI
@@ -27,7 +27,7 @@ pub enum BLSConfigType {
2727
/// The paths to the initrd images.
2828
initrd: Vec<Utf8PathBuf>,
2929
/// Kernel command line options.
30-
options: Option<String>,
30+
options: Option<CmdlineOwned>,
3131
},
3232
#[default]
3333
Unknown,
@@ -229,7 +229,7 @@ pub(crate) fn parse_bls_config(input: &str) -> Result<BLSConfig> {
229229
"version" => version = Some(value),
230230
"linux" => linux = Some(Utf8PathBuf::from(value)),
231231
"initrd" => initrd.push(Utf8PathBuf::from(value)),
232-
"options" => options = Some(value),
232+
"options" => options = Some(CmdlineOwned::from(value)),
233233
"machine-id" => machine_id = Some(value),
234234
"sort-key" => sort_key = Some(value),
235235
"efi" => efi = Some(Utf8PathBuf::from(value)),
@@ -301,7 +301,7 @@ mod tests {
301301
assert_eq!(config.version, "2");
302302
assert_eq!(linux, "/boot/7e11ac46e3e022053e7226a20104ac656bf72d1a84e3a398b7cce70e9df188b6/vmlinuz-5.14.10");
303303
assert_eq!(initrd, vec!["/boot/7e11ac46e3e022053e7226a20104ac656bf72d1a84e3a398b7cce70e9df188b6/initramfs-5.14.10.img"]);
304-
assert_eq!(options, Some("root=UUID=abc123 rw composefs=7e11ac46e3e022053e7226a20104ac656bf72d1a84e3a398b7cce70e9df188b6".to_string()));
304+
assert_eq!(&*options.unwrap(), "root=UUID=abc123 rw composefs=7e11ac46e3e022053e7226a20104ac656bf72d1a84e3a398b7cce70e9df188b6");
305305
assert_eq!(config.extra.get("custom1"), Some(&"value1".to_string()));
306306
assert_eq!(config.extra.get("custom2"), Some(&"value2".to_string()));
307307

0 commit comments

Comments
 (0)