Skip to content

Commit e069f7c

Browse files
Copilotcgwalters
andauthored
Add bootc loader-entries set-options-for-source command
Adds support for merging disparate kernel argument sources into the single BLS entry `options` field. Each source (e.g., TuneD, admin, bootc kargs.d) can independently manage its own set of kernel arguments, tracked via `# x-ostree-options-source-<name>` magic comments in BLS config files. Changes: - Extend BLS parser to parse/preserve source-tracking magic comments - Add new `loader_entries` module with set-options-for-source logic - Add `bootc loader-entries set-options-for-source` CLI command - Add unit tests for merge logic and BLS roundtrip See: ostreedev/ostree#3570 See: #899 Co-authored-by: cgwalters <244096+cgwalters@users.noreply.github.com> Agent-Logs-Url: https://github.com/bootc-dev/bootc/sessions/ce7bf603-8a51-4bd9-8653-6e1221a2bdc6
1 parent 5cbb111 commit e069f7c

File tree

4 files changed

+454
-2
lines changed

4 files changed

+454
-2
lines changed

crates/lib/src/cli.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,56 @@ pub(crate) enum StateOpts {
714714
WipeOstree,
715715
}
716716

717+
/// Options for the `set-options-for-source` subcommand.
718+
#[derive(Debug, Parser, PartialEq, Eq)]
719+
pub(crate) struct SetOptionsForSourceOpts {
720+
/// The name of the source that owns these kernel arguments.
721+
///
722+
/// Must contain only alphanumeric characters, hyphens, or underscores.
723+
/// Examples: "tuned", "admin", "bootc-kargs-d"
724+
#[clap(long)]
725+
pub(crate) source: String,
726+
727+
/// The kernel arguments to set for this source.
728+
///
729+
/// If not provided, the source is removed and its options are
730+
/// dropped from the merged `options` line.
731+
#[clap(long)]
732+
pub(crate) options: Option<String>,
733+
734+
/// Path to the system root. Defaults to "/".
735+
#[clap(long, default_value = "/")]
736+
pub(crate) root: String,
737+
}
738+
739+
/// Operations on Boot Loader Specification (BLS) entries.
740+
///
741+
/// These commands support managing kernel arguments from multiple independent
742+
/// sources (e.g., TuneD, admin, bootc kargs.d) by tracking argument ownership
743+
/// via magic comments in BLS config files.
744+
///
745+
/// See <https://github.com/ostreedev/ostree/pull/3570>
746+
#[derive(Debug, clap::Subcommand, PartialEq, Eq)]
747+
pub(crate) enum LoaderEntriesOpts {
748+
/// Set or update the kernel arguments owned by a specific source.
749+
///
750+
/// Each source's arguments are tracked via `# x-ostree-options-source-<name>`
751+
/// comments in BLS config files. The `options` line is recomputed as the
752+
/// merge of all tracked sources plus any untracked (pre-existing) options.
753+
///
754+
/// ## Examples
755+
///
756+
/// Add TuneD kernel arguments:
757+
/// bootc loader-entries set-options-for-source --source tuned --options "isolcpus=1-3 nohz_full=1-3"
758+
///
759+
/// Update TuneD kernel arguments:
760+
/// bootc loader-entries set-options-for-source --source tuned --options "isolcpus=0-7"
761+
///
762+
/// Remove TuneD kernel arguments:
763+
/// bootc loader-entries set-options-for-source --source tuned
764+
SetOptionsForSource(SetOptionsForSourceOpts),
765+
}
766+
717767
impl InternalsOpts {
718768
/// The name of the binary we inject into /usr/lib/systemd/system-generators
719769
const GENERATOR_BIN: &'static str = "bootc-systemd-generator";
@@ -813,6 +863,11 @@ pub(crate) enum Opt {
813863
/// Stability: This interface may change in the future.
814864
#[clap(subcommand, hide = true)]
815865
Image(ImageOpts),
866+
/// Operations on Boot Loader Specification (BLS) entries.
867+
///
868+
/// Manage kernel arguments from multiple independent sources.
869+
#[clap(subcommand)]
870+
LoaderEntries(LoaderEntriesOpts),
816871
/// Execute the given command in the host mount namespace
817872
#[clap(hide = true)]
818873
ExecInHostMountNamespace {
@@ -1805,6 +1860,16 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
18051860
Opt::ExecInHostMountNamespace { args } => {
18061861
crate::install::exec_in_host_mountns(args.as_slice())
18071862
}
1863+
Opt::LoaderEntries(opts) => match opts {
1864+
LoaderEntriesOpts::SetOptionsForSource(opts) => {
1865+
crate::loader_entries::set_options_for_source(
1866+
&opts.root,
1867+
&opts.source,
1868+
opts.options.as_deref(),
1869+
)?;
1870+
Ok(())
1871+
}
1872+
},
18081873
Opt::Status(opts) => super::status::status(opts).await,
18091874
Opt::Internals(opts) => match opts {
18101875
InternalsOpts::SystemdGenerator {

crates/lib/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ pub(crate) mod journal;
8282
mod k8sapitypes;
8383
mod kernel;
8484
mod lints;
85+
mod loader_entries;
8586
mod lsm;
8687
pub(crate) mod metadata;
8788
mod parsers;

0 commit comments

Comments
 (0)