1
0
mirror of https://github.com/containers/bootc.git synced 2026-02-05 06:45:13 +01:00

33 Commits

Author SHA1 Message Date
Daniele Guarascio
13d5db68aa Update workspace to Rust edition 2024
Migrate all crates from edition 2021 to 2024. This includes
updating Cargo.toml files and fixing code compatibility issues.

The MSRV is bumped to 1.85.0 to support edition 2024.

Note: global_init() requires #[allow(unsafe_code)] for
std::env::set_var which is now unsafe in edition 2024.
This is safe because the function is called early in main()
before any threads are spawned.

Closes: #1414

Signed-off-by: Daniele Guarascio <guarascio.daniele@gmail.com>
2026-01-12 17:38:26 +01:00
John Eckersberg
809b18b52f kernel_cmdline: Manually impl semantically-correct equivalence for Cmdline
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-11-13 15:46:24 -05:00
John Eckersberg
35e64a42cd kernel_cmdline: impl PartialOrd/Ord/PartialEq/Eq for Parameter/ParameterKey
We need to be able to check equality on Cmdline by comparing sorted
parameters.

Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-11-13 15:46:24 -05:00
John Eckersberg
c1e4a7adea kernel_cmdline: Standardize Deref/AsRef impls across types
Implement generic AsRef in terms of Deref as suggested in:

https://doc.rust-lang.org/std/convert/trait.AsRef.html#generic-implementations

I'm not 100% sold on this since in some case (like the change to the
tests here) you have to end up doing `&*` coercion to get the right
type, but this at least makes everything consistent.

Would be a bit nicer when/if str_as_str[1] stabilizes, at least for
the most common UTF-8 case.

[1] https://github.com/rust-lang/rust/issues/130366

Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-11-13 15:46:24 -05:00
John Eckersberg
b01ffa82e0 kernel_cmdline: Add some more derives for Cmdline
Prep so we can parse these directly via clap

Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-11-13 15:46:24 -05:00
John Eckersberg
d6a269fd62 kernel_cmdline: Simplify Display impl for utf8::Parameter
Really we want to just return the original slice that the Parameter
was created from.  This also aligns with how Cmdline and ParameterKey
impl Display.

Where this really matters the most is to ensure we retain the quoting
that the parameter was created with, so I added a test just to sanity
check that.  Before this change the test would fail because "foo"
would be stripped of its quotes and just rendered as foo unquoted.

Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-11-12 13:40:29 -05:00
John Eckersberg
5c962c1196 kernel_cmdline: Implement Deref for Cmdline
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-11-12 13:40:29 -05:00
John Eckersberg
c1ae4237dc kernel_cmdline: Add CmdlineOwned alias for Cmdline<'static>
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-11-10 13:12:40 -05:00
John Eckersberg
43061f0c28 kernel_cmdline: Add remove_exact method
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-11-10 13:12:40 -05:00
John Eckersberg
87bcbd9ae9 kernel_cmdline: Fix parsing/equivalence of "outside" quoted args
Primary motivation here is that these two should be equivalent:

foo="quoted value"
"foo=quoted value"

This also adds tests for a few more oddball cases that weren't covered
before but clarify the expected kernel behavior.

Closes: #1737
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-11-07 14:22:20 -05:00
John Eckersberg
a64ae8994c kernel_cmdline: Consolidate parsing and add iter_bytes/iter_str
This commit refactors the kernel_cmdline parsing implementation to
reduce code duplication and provide a clearer separation of concerns.

Key changes:

1. Introduced CmdlineIterBytes as a dedicated iterator for splitting
   the command line into raw parameter byte slices. This centralizes
   the quote-aware whitespace splitting logic in one place.

2. Refactored CmdlineIter to wrap CmdlineIterBytes instead of
   duplicating the splitting logic. This eliminates redundant code
   and ensures consistent behavior.

3. Consolidated Parameter::parse and Parameter::parse_one into a
   single parse() method. Parameter::parse now uses CmdlineIterBytes
   directly to find the first parameter, then passes it to
   parse_internal() which assumes the input is already a single
   parameter.

4. Added iter_bytes() and iter_str() methods to Cmdline for cases
   where users need raw byte slices or strings without full Parameter
   parsing overhead.

5. Removed utf8::Parameter::parse_one() in favor of a simplified
   parse() that wraps the bytes implementation.

Assisted-by: Claude Code (Sonnet 4.5)
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-11-05 11:21:40 -05:00
John Eckersberg
0efad6afea kernel_cmdline: Add Cmdline::new()
This creates an empty, owned ('static) Cmdline.

Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-11-05 11:21:40 -05:00
John Eckersberg
59f0bde094 kernel_cmdline: Derive Clone for Cmdline
No reason not to, generally useful.

Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-11-05 11:21:40 -05:00
John Eckersberg
27b6189f2e kernel_cmdline: Avoid unnecessary unwraps in add/add_or_modify
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-11-03 14:34:09 -05:00
John Eckersberg
04805bb348 kernel_cmdline: Add algorithmic complexity comments to Extend impls
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-11-03 14:34:09 -05:00
John Eckersberg
658cea060e kernel_cmdline: Add some more ergonomic/convenience methods
Implement Deref / AsRef / Clone in a few places where it makes sense.

Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-11-03 14:34:09 -05:00
John Eckersberg
bed52b7be5 kernel_cmdline: Add Cmdline::add method for both bytes and utf8 modules
Add a new `add` method to both `bytes::Cmdline` and `utf8::Cmdline`
that appends parameters without modifying existing ones. Unlike
`add_or_modify`, this method preserves duplicate keys with different
values (e.g., multiple `console=` parameters), which is valid for
certain kernel parameters.

The method returns `Action::Added` when a new parameter is appended,
and `Action::Existed` when the exact parameter already exists.

Assisted-by: Claude Code (Sonnet 4.5)
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-11-03 14:34:09 -05:00
John Eckersberg
78d62537fb kernel_cmdline: Derive Default for Cmdline
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-11-03 14:34:09 -05:00
John Eckersberg
c0bd9250ad kernel_cmdline: impl IntoIterator and Extend for Cmdline
This makes it ergonomic to take two `Cmdline`s and update one by
appending the parameters in the other.

Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-11-03 14:34:09 -05:00
John Eckersberg
534c0177a9 kernel_cmdline: Update add_or_modify to better describe action taken
In some cases it will be important to differentiate whether we added a
net-new parameter vs. modifying an existing parameter.

Motivated by trying to update bootc_kargs to use kernel_cmdline.  We
want to parse the booted kargs, and then merge with any args defined
in kargs.d.  But it should error if a value in kargs.d already exists
in the booted system with a different value.  The previous API did not
provide enough visibility to make this determiniation.

Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-11-03 14:34:09 -05:00
John Eckersberg
7f8c71ec92 kernel_cmdline: impl From<String> for utf8::Cmdline
This is an obvious thing one might want to do.  Ensures we can make an
owned Cmdline directly from an owned String.

Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-11-03 14:34:09 -05:00
Colin Walters
19e82be849 Merge pull request #1444 from bootc-dev/composefs-backend
Add a composefs backend
2025-09-15 15:44:48 -04:00
Pragyan Poudyal
8ac9eae698 Add a composefs backend
This adds a new off-by default feature to enable
a new composefs-native backend for bootc. This
is all still a live work in progress, but
we're landing this first tranche of work to help
avoid continual issues with rebasing.

Thanks to everyone who worked on it!

xref https://github.com/bootc-dev/bootc/issues/1190

Co-authored-by: John Eckersberg <jeckersb@redhat.com>
Co-authored-by: Robert Sturla <robertsturla@outlook.com>
Co-authored-by: Colin Walters <walters@verbum.org>
Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
2025-09-15 18:19:46 +05:30
John Eckersberg
8d68526cc2 kernel_cmdline: rename parse to parse_one and add new parse method
The (now-named) parse_one method is not particularly useful outside of
`CmdlineIter`.  Almost always end users don't care about extra
unparsed content, they just want the `Option<Parameter>`.

This greatly improves ergnomics for users so they can create
parameters like...

`Parameter::parse("foo=bar").unwrap()`

... knowing at the call-site that "foo=bar" is a valid parameter so
the `unwrap()` is safe.

Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-09-12 17:15:20 -04:00
John Eckersberg
78b677bded kernel_cmdline: add_or_modify and remove should take borrowed input
There's no reason these need to be owned.

Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-09-12 17:15:20 -04:00
John Eckersberg
1cf09f39df kernel_cmdline: impl Display for utf8::Cmdline
We already impl AsRef<str> but this just makes it more convenient to
render the command line for users.

Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-09-12 17:15:20 -04:00
John Eckersberg
02b06c01a6 kernel_cmdline: Consistently take AsRef + ?Sized references where possible
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-09-12 17:15:20 -04:00
John Eckersberg
0555eac76d kernel_cmdline: Add parameter manipulation methods
Add `add_or_modify` and `remove` methods to `Cmdline` in both `bytes`
and `utf8` modules, along with unit tests.

Closes: #1596
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-09-11 17:34:40 -04:00
John Eckersberg
6cede27df1 kernel_cmdline: More improvements and fixes
- Removed `From<bytes::Parameter>` implementation for
  `utf8::Parameter` and similar for `utf8::ParameterKey`.  This was
  public and would allow end-users to construct utf8 parameters from
  non-utf8 data.  Replaced internally with `from_bytes` in the places
  where we know we can safely convert known-UTF-8 data.

- Added `TryFrom<bytes::Paramter>` implementation for
  `utf8::Parameter` to allow checked conversions, plus tests.

- Added `iter_utf8` and `find_utf8` to `bytes::Cmdline`, plus tests.

- Updated `find_root_args_to_inherit` in bootc to use these
  improvements.  Notably bootc will now allow non-UTF8 data in the
  kernel cmdline, *unless* it occurs in parameters that bootc is
  explicitly looking for.

- Added more tests to `find_root_args_to_inherit` to validate expected
  functionality with non-UTF-8 data.

- Fixed a parser bug that gemini pointed out with unmatched quotes,
  plus tests to check for that.

Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-09-11 10:24:09 -04:00
John Eckersberg
5454ceca5a kernel_cmdline: Refactor into separate bytes and utf8 modules
Split the kernel command line parsing functionality into two focused
modules. The `bytes` module handles raw byte parsing without UTF-8
requirements, matching kernel behavior for arbitrary byte
sequences. The `utf8` module provides string-based parsing for cases
where UTF-8 validation is needed.  The `utf8` module reuses the
`bytes` module primitives where possible, and uses the fact that
`utf8::Cmdline` can only be constructed from valid UTF-8 to do
unchecked conversions between the two.

Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-09-09 16:58:40 -04:00
John Eckersberg
4335ba154b kernel_cmdline: Refactor parsing to improve quote and whitespace handling
This moves the bulk of the parsing logic into `Parameter`.  Its
`parse` method returns a 2-tuple, its items being:

1.  An `Option<Parameter>` which contains the parsed `Parameter`.
This will be `None` if the provided input is empty or contains only
whitespace.

2.  A byte slice of the rest of the input which was not consumed by
the yielded `Parameter`.

This also adds new tests for some cases that would fail under the
previous parser implementation.

Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-09-05 18:58:36 -04:00
John Eckersberg
04860d513a kernel_cmdline: remove cfg(test) for require_value_* methods
This appears to have been accidentally added somewhere along the way,
and I would like to use these in composefs-boot.

Also fixes duplicate docstring copy/paste error on
`require_value_of_utf8`.

Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-08-29 11:09:17 -04:00
John Eckersberg
26a51a6ce2 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 <noreply@anthropic.com>
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
2025-08-26 13:30:44 -04:00