Skip to content

Commit 26a51a6

Browse files
jeckersbclaude
andcommitted
Move kernel cmdline parsing to dedicated crate
Creates a new dedicated crate for kernel command line parsing functionality, moving it out of bootc-lib for better separation of concerns and modularity. Changes: - Create new bootc-kernel-cmdline crate under crates/kernel_cmdline/ - Move kernel_cmdline.rs from bootc-lib to the new crate as lib.rs - Add bootc-kernel-cmdline dependency to bootc-lib - Update imports in bootc-lib to use bootc_kernel_cmdline:: namespace - Add missing Debug derive and documentation to fix lints 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Signed-off-by: John Eckersberg <[email protected]>
1 parent 1dd55c2 commit 26a51a6

File tree

6 files changed

+43
-11
lines changed

6 files changed

+43
-11
lines changed

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/kernel_cmdline/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "bootc-kernel-cmdline"
3+
description = "Kernel command line parsing utilities for bootc"
4+
version = "0.0.0"
5+
edition = "2021"
6+
license = "MIT OR Apache-2.0"
7+
repository = "https://github.com/bootc-dev/bootc"
8+
9+
[dependencies]
10+
# Workspace dependencies
11+
anyhow = { workspace = true }
12+
13+
[dev-dependencies]
14+
similar-asserts = { workspace = true }
15+
static_assertions = { workspace = true }
16+
17+
[lints]
18+
workspace = true

crates/lib/src/kernel_cmdline.rs renamed to crates/kernel_cmdline/src/lib.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ use std::borrow::Cow;
88
use anyhow::Result;
99

1010
/// This is used by dracut.
11-
pub(crate) const INITRD_ARG_PREFIX: &str = "rd.";
11+
pub const INITRD_ARG_PREFIX: &str = "rd.";
1212
/// The kernel argument for configuring the rootfs flags.
13-
pub(crate) const ROOTFLAGS: &str = "rootflags";
13+
pub const ROOTFLAGS: &str = "rootflags";
1414

1515
/// A parsed kernel command line.
1616
///
1717
/// Wraps the raw command line bytes and provides methods for parsing and iterating
1818
/// over individual parameters. Uses copy-on-write semantics to avoid unnecessary
1919
/// allocations when working with borrowed data.
20-
pub(crate) struct Cmdline<'a>(Cow<'a, [u8]>);
20+
#[derive(Debug)]
21+
pub struct Cmdline<'a>(Cow<'a, [u8]>);
2122

2223
impl<'a, T: AsRef<[u8]> + ?Sized> From<&'a T> for Cmdline<'a> {
2324
/// Creates a new `Cmdline` from any type that can be referenced as bytes.
@@ -128,7 +129,7 @@ impl<'a> Cmdline<'a> {
128129
///
129130
/// Handles quoted values and treats dashes and underscores in keys as equivalent.
130131
#[derive(Debug, Eq)]
131-
pub(crate) struct ParameterKey<'a>(&'a [u8]);
132+
pub struct ParameterKey<'a>(&'a [u8]);
132133

133134
impl<'a> std::ops::Deref for ParameterKey<'a> {
134135
type Target = [u8];
@@ -148,7 +149,7 @@ impl<'a> From<&'a [u8]> for ParameterKey<'a> {
148149
///
149150
/// Otherwise the same as [`ParameterKey`].
150151
#[derive(Debug, Eq)]
151-
pub(crate) struct ParameterKeyStr<'a>(&'a str);
152+
pub struct ParameterKeyStr<'a>(&'a str);
152153

153154
impl<'a> From<&'a str> for ParameterKeyStr<'a> {
154155
fn from(value: &'a str) -> Self {
@@ -158,7 +159,7 @@ impl<'a> From<&'a str> for ParameterKeyStr<'a> {
158159

159160
/// A single kernel command line parameter.
160161
#[derive(Debug, Eq)]
161-
pub(crate) struct Parameter<'a> {
162+
pub struct Parameter<'a> {
162163
/// The full original value
163164
pub parameter: &'a [u8],
164165
/// The parameter key as raw bytes
@@ -169,7 +170,7 @@ pub(crate) struct Parameter<'a> {
169170

170171
/// A single kernel command line parameter.
171172
#[derive(Debug, PartialEq, Eq)]
172-
pub(crate) struct ParameterStr<'a> {
173+
pub struct ParameterStr<'a> {
173174
/// The original value
174175
pub parameter: &'a str,
175176
/// The parameter key
@@ -179,6 +180,9 @@ pub(crate) struct ParameterStr<'a> {
179180
}
180181

181182
impl<'a> Parameter<'a> {
183+
/// Convert this parameter to a UTF-8 string parameter, if possible.
184+
///
185+
/// Returns `None` if the parameter contains invalid UTF-8.
182186
pub fn to_str(&self) -> Option<ParameterStr<'a>> {
183187
let Ok(parameter) = std::str::from_utf8(self.parameter) else {
184188
return None;

crates/lib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ include = ["/src", "LICENSE-APACHE", "LICENSE-MIT"]
1616
[dependencies]
1717
# Internal crates
1818
bootc-blockdev = { package = "bootc-internal-blockdev", path = "../blockdev", version = "0.0.0" }
19+
bootc-kernel-cmdline = { path = "../kernel_cmdline", version = "0.0.0" }
1920
bootc-mount = { path = "../mount" }
2021
bootc-sysusers = { path = "../sysusers" }
2122
bootc-tmpfiles = { path = "../tmpfiles" }

crates/lib/src/install.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ use self::baseline::InstallBlockDeviceOpts;
5656
use crate::boundimage::{BoundImage, ResolvedBoundImage};
5757
use crate::containerenv::ContainerExecutionInfo;
5858
use crate::deploy::{prepare_for_pull, pull_from_prepared, PreparedImportMeta, PreparedPullResult};
59-
use crate::kernel_cmdline::Cmdline;
6059
use crate::lsm;
6160
use crate::progress_jsonl::ProgressWriter;
6261
use crate::spec::ImageReference;
6362
use crate::store::Storage;
6463
use crate::task::Task;
6564
use crate::utils::sigpolicy_from_opt;
65+
use bootc_kernel_cmdline::Cmdline;
6666
use bootc_mount::Filesystem;
6767

6868
/// The toplevel boot directory
@@ -1639,9 +1639,9 @@ fn find_root_args_to_inherit(cmdline: &Cmdline, root_info: &Filesystem) -> Resul
16391639
.context("Parsing root= karg")?;
16401640
// If we have a root= karg, then use that
16411641
let (mount_spec, kargs) = if let Some(root) = root {
1642-
let rootflags = cmdline.find_str(crate::kernel_cmdline::ROOTFLAGS);
1642+
let rootflags = cmdline.find_str(bootc_kernel_cmdline::ROOTFLAGS);
16431643
let inherit_kargs =
1644-
cmdline.find_all_starting_with_str(crate::kernel_cmdline::INITRD_ARG_PREFIX);
1644+
cmdline.find_all_starting_with_str(bootc_kernel_cmdline::INITRD_ARG_PREFIX);
16451645
(
16461646
root.to_owned(),
16471647
rootflags

crates/lib/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ mod docgen;
3434
mod bootloader;
3535
mod containerenv;
3636
mod install;
37-
mod kernel_cmdline;
3837

3938
#[cfg(feature = "composefs-backend")]
4039
#[allow(dead_code)]

0 commit comments

Comments
 (0)