Skip to content

Commit ac444e5

Browse files
committed
reset: Move kernel code into bootc_kargs
Also cleans up some bugs from rebasing previous commits.
1 parent 145cfdf commit ac444e5

File tree

6 files changed

+33
-89
lines changed

6 files changed

+33
-89
lines changed

crates/lib/src/bootc_kargs.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ use crate::store::Storage;
1919
/// The relative path to the kernel arguments which may be embedded in an image.
2020
const KARGS_PATH: &str = "usr/lib/bootc/kargs.d";
2121

22+
/// The default root filesystem mount specification.
23+
pub(crate) const ROOT: &str = "root=";
24+
/// This is used by dracut.
25+
pub(crate) const INITRD_ARG_PREFIX: &str = "rd.";
26+
/// The kernel argument for configuring the rootfs flags.
27+
pub(crate) const ROOTFLAGS: &str = "rootflags=";
28+
2229
/// The kargs.d configuration file.
2330
#[derive(Deserialize)]
2431
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
@@ -54,6 +61,18 @@ pub(crate) fn get_kargs_in_root(d: &Dir, sys_arch: &str) -> Result<Vec<String>>
5461
Ok(ret)
5562
}
5663

64+
pub(crate) fn root_args_from_cmdline<'a>(cmdline: &'a [&str]) -> Vec<&'a str> {
65+
cmdline
66+
.iter()
67+
.filter(|arg| {
68+
arg.starts_with(ROOT)
69+
|| arg.starts_with(ROOTFLAGS)
70+
|| arg.starts_with(INITRD_ARG_PREFIX)
71+
})
72+
.copied()
73+
.collect()
74+
}
75+
5776
/// Load kargs.d files from the target ostree commit root
5877
pub(crate) fn get_kargs_from_ostree_root(
5978
repo: &ostree::Repo,

crates/lib/src/deploy.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ async fn deploy(
587587
// doesn't use this API).
588588
let (stateroot, override_kargs) = match &from {
589589
MergeState::MergeDeployment(deployment) => {
590-
let kargs = crate::kargs::get_kargs(sysroot, &deployment, image)?;
590+
let kargs = crate::bootc_kargs::get_kargs(sysroot, &deployment, image)?;
591591
(deployment.stateroot().into(), kargs)
592592
}
593593
MergeState::Reset { stateroot, kargs } => (stateroot.clone(), kargs.clone()),
@@ -614,7 +614,7 @@ async fn deploy(
614614
.map(|s| s.as_str())
615615
.collect::<Vec<_>>();
616616
opts.override_kernel_argv = Some(&override_kargs);
617-
let deployments = sysroot.deployments();
617+
let deployments = ostree.deployments();
618618
let merge_deployment = merge_deployment.map(|m| &deployments[m]);
619619
let origin = glib::KeyFile::new();
620620
origin.load_from_data(&origin_data, glib::KeyFileFlags::NONE)?;
@@ -664,7 +664,8 @@ pub(crate) enum MergeState {
664664
impl MergeState {
665665
/// Initialize using the default merge deployment for the given stateroot.
666666
pub(crate) fn from_stateroot(sysroot: &Storage, stateroot: &str) -> Result<Self> {
667-
let merge_deployment = sysroot.merge_deployment(Some(stateroot)).ok_or_else(|| {
667+
let ostree = sysroot.get_ostree()?;
668+
let merge_deployment = ostree.merge_deployment(Some(stateroot)).ok_or_else(|| {
668669
anyhow::anyhow!("No merge deployment found for stateroot {stateroot}")
669670
})?;
670671
Ok(Self::MergeDeployment(merge_deployment))
@@ -696,13 +697,11 @@ pub(crate) async fn stage(
696697
bootc.image.reference = &spec.image.image,
697698
bootc.image.transport = &spec.image.transport,
698699
bootc.manifest_digest = image.manifest_digest.as_ref(),
699-
bootc.stateroot = stateroot,
700700
"Staging image for deployment: {} (digest: {})",
701701
spec.image,
702702
image.manifest_digest
703703
);
704704

705-
let ostree = sysroot.get_ostree()?;
706705
let mut subtask = SubTaskStep {
707706
subtask: "merging".into(),
708707
description: "Merging Image".into(),

crates/lib/src/install.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ use crate::containerenv::ContainerExecutionInfo;
5858
use crate::deploy::{
5959
prepare_for_pull, pull_from_prepared, MergeState, PreparedImportMeta, PreparedPullResult,
6060
};
61-
use crate::kernel_cmdline::Cmdline;
6261
use crate::lsm;
6362
use crate::progress_jsonl::ProgressWriter;
6463
use crate::spec::ImageReference;
@@ -2093,17 +2092,17 @@ pub(crate) async fn install_reset(opts: InstallResetOpts) -> Result<()> {
20932092
let prog: ProgressWriter = opts.progress.try_into()?;
20942093

20952094
let sysroot = &crate::cli::get_storage().await?;
2096-
let repo = &sysroot.repo();
2097-
let (booted_deployment, _deployments, host) =
2098-
crate::status::get_status_require_booted(sysroot)?;
2095+
let ostree = sysroot.get_ostree()?;
2096+
let repo = &ostree.repo();
2097+
let (booted_deployment, _deployments, host) = crate::status::get_status_require_booted(ostree)?;
20992098

2100-
let stateroots = list_stateroots(sysroot)?;
2099+
let stateroots = list_stateroots(ostree)?;
21012100
dbg!(&stateroots);
21022101
let target_stateroot = if let Some(s) = opts.stateroot {
21032102
s
21042103
} else {
21052104
let now = chrono::Utc::now();
2106-
let r = allocate_new_stateroot(&sysroot, &stateroots, now)?;
2105+
let r = allocate_new_stateroot(&ostree, &stateroots, now)?;
21072106
r.name
21082107
};
21092108

@@ -2143,7 +2142,7 @@ pub(crate) async fn install_reset(opts: InstallResetOpts) -> Result<()> {
21432142
.ok_or_else(|| anyhow!("Missing bootcfg for booted deployment"))?;
21442143
if let Some(options) = bootcfg.get("options") {
21452144
let options = options.split_ascii_whitespace().collect::<Vec<_>>();
2146-
crate::kernel::root_args_from_cmdline(&options)
2145+
crate::bootc_kargs::root_args_from_cmdline(&options)
21472146
.into_iter()
21482147
.map(ToOwned::to_owned)
21492148
.collect::<Vec<_>>()
@@ -2152,7 +2151,7 @@ pub(crate) async fn install_reset(opts: InstallResetOpts) -> Result<()> {
21522151
}
21532152
};
21542153

2155-
let kargs = crate::kargs::get_kargs_in_root(rootfs, std::env::consts::ARCH)?
2154+
let kargs = crate::bootc_kargs::get_kargs_in_root(rootfs, std::env::consts::ARCH)?
21562155
.into_iter()
21572156
.chain(root_kargs.into_iter())
21582157
.chain(opts.karg.unwrap_or_default())

crates/ostree-ext/src/container/deploy.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! Perform initial setup for a container image based system root
22
3-
use std::collections::HashSet;
4-
3+
#[cfg(feature = "bootc")]
54
use anyhow::Result;
65
use fn_error_context::context;
76
use ostree::glib;
7+
use std::collections::HashSet;
88

99
use super::store::{gc_image_layers, LayeredImageState};
1010
use super::{ImageReference, OstreeImageReference};
@@ -51,13 +51,6 @@ pub struct DeployOpts<'a> {
5151
pub no_clean: bool,
5252
}
5353

54-
// Access the file descriptor for a sysroot
55-
#[allow(unsafe_code)]
56-
#[cfg(feature = "bootc")]
57-
pub(crate) fn sysroot_fd(sysroot: &ostree::Sysroot) -> BorrowedFd<'_> {
58-
unsafe { BorrowedFd::borrow_raw(sysroot.fd()) }
59-
}
60-
6154
/// Write a container image to an OSTree deployment.
6255
///
6356
/// This API is currently intended for only an initial deployment.

crates/ostree-ext/src/sysroot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl Deref for SysrootLock {
4040

4141
/// Access the file descriptor for a sysroot
4242
#[allow(unsafe_code)]
43-
pub fn sysroot_fd(sysroot: &ostree::Sysroot) -> BorrowedFd {
43+
pub fn sysroot_fd(sysroot: &ostree::Sysroot) -> BorrowedFd<'_> {
4444
unsafe { BorrowedFd::borrow_raw(sysroot.fd()) }
4545
}
4646

lib/src/kernel.rs

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)