Skip to content

Commit e502bb0

Browse files
committed
reset: Move kernel code into bootc_kargs
Also cleans up some bugs from rebasing previous commits. Signed-off-by: ckyrouac <[email protected]>
1 parent ddb01c0 commit e502bb0

File tree

6 files changed

+32
-90
lines changed

6 files changed

+32
-90
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 & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ use crate::containerenv::ContainerExecutionInfo;
6060
use crate::deploy::{
6161
prepare_for_pull, pull_from_prepared, MergeState, PreparedImportMeta, PreparedPullResult,
6262
};
63-
use crate::kernel_cmdline::Cmdline;
6463
use crate::lsm;
6564
use crate::progress_jsonl::ProgressWriter;
6665
use crate::spec::{Bootloader, ImageReference};
@@ -2275,17 +2274,16 @@ pub(crate) async fn install_reset(opts: InstallResetOpts) -> Result<()> {
22752274
let prog: ProgressWriter = opts.progress.try_into()?;
22762275

22772276
let sysroot = &crate::cli::get_storage().await?;
2278-
let repo = &sysroot.repo();
2279-
let (booted_deployment, _deployments, host) =
2280-
crate::status::get_status_require_booted(sysroot)?;
2277+
let ostree = sysroot.get_ostree()?;
2278+
let repo = &ostree.repo();
2279+
let (booted_deployment, _deployments, host) = crate::status::get_status_require_booted(ostree)?;
22812280

2282-
let stateroots = list_stateroots(sysroot)?;
2283-
dbg!(&stateroots);
2281+
let stateroots = list_stateroots(ostree)?;
22842282
let target_stateroot = if let Some(s) = opts.stateroot {
22852283
s
22862284
} else {
22872285
let now = chrono::Utc::now();
2288-
let r = allocate_new_stateroot(&sysroot, &stateroots, now)?;
2286+
let r = allocate_new_stateroot(&ostree, &stateroots, now)?;
22892287
r.name
22902288
};
22912289

@@ -2325,7 +2323,7 @@ pub(crate) async fn install_reset(opts: InstallResetOpts) -> Result<()> {
23252323
.ok_or_else(|| anyhow!("Missing bootcfg for booted deployment"))?;
23262324
if let Some(options) = bootcfg.get("options") {
23272325
let options = options.split_ascii_whitespace().collect::<Vec<_>>();
2328-
crate::kernel::root_args_from_cmdline(&options)
2326+
crate::bootc_kargs::root_args_from_cmdline(&options)
23292327
.into_iter()
23302328
.map(ToOwned::to_owned)
23312329
.collect::<Vec<_>>()
@@ -2334,7 +2332,7 @@ pub(crate) async fn install_reset(opts: InstallResetOpts) -> Result<()> {
23342332
}
23352333
};
23362334

2337-
let kargs = crate::kargs::get_kargs_in_root(rootfs, std::env::consts::ARCH)?
2335+
let kargs = crate::bootc_kargs::get_kargs_in_root(rootfs, std::env::consts::ARCH)?
23382336
.into_iter()
23392337
.chain(root_kargs.into_iter())
23402338
.chain(opts.karg.unwrap_or_default())

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
//! Perform initial setup for a container image based system root
22
3-
use std::collections::HashSet;
4-
53
use anyhow::Result;
64
use fn_error_context::context;
75
use ostree::glib;
6+
use std::collections::HashSet;
87

98
use super::store::{gc_image_layers, LayeredImageState};
109
use super::{ImageReference, OstreeImageReference};
@@ -51,13 +50,6 @@ pub struct DeployOpts<'a> {
5150
pub no_clean: bool,
5251
}
5352

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-
6153
/// Write a container image to an OSTree deployment.
6254
///
6355
/// 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)