Skip to content

Conversation

Johan-Liebert1
Copy link
Collaborator

@Johan-Liebert1 Johan-Liebert1 commented Aug 26, 2025

Move the composefs-setup-root code from composefs-rs to bootc-initramfs crate

Left /etc mount as overlayfs as bind-mounting requires copying files over to state /etc dir which I think is best done in https://github.com/bootc-dev/bootc/pull/1444/files#diff-0b4a5898665a82dc611bd0dd06f4fd3ac8c188e2439e1e2418a02c2d68ae7fe9R2139

@bootc-bot bootc-bot bot requested a review from cgwalters August 26, 2025 10:58
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a good refactoring that moves the composefs-setup-root logic into the bootc-initramfs crate, centralizing the initramfs-related code. The introduction of clap for command-line parsing is a definite improvement. My review focuses on correctness and maintainability. I've identified a critical memory safety issue, a high-severity bug where an error is silently ignored, and a few medium-severity issues to improve code clarity and fix an unused argument.

Comment on lines +97 to +99
#[arg(long, help = "Mountpoint (don't replace sysroot, for testing)")]
/// Mountpoint (don't replace sysroot, for testing)
pub target: Option<PathBuf>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The command-line argument target is defined here but it appears to be unused in the setup_root function. The logic in setup_root always uses args.sysroot as the mount destination. If target is intended for testing purposes to provide an alternative mount point, it should be utilized in the mounting logic.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well spotted!

fn ensure_dir(dirfd: impl AsFd, name: &str) -> rustix::io::Result<OwnedFd> {
match mkdirat(dirfd.as_fd(), name, 0o700.into()) {
Ok(()) | Err(Errno::EXIST) => {}
Err(err) => Err(err)?,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The use of Err(err)? in the match arm is a bit unconventional and can be confusing. It constructs a Result::Err variant only to immediately use the ? operator on it. A more direct and clearer way to propagate the error is to use a return statement.

Suggested change
Err(err) => Err(err)?,
Err(err) => return Err(err),

Comment on lines +201 to +207
let mount_type = match config.mount {
Some(mt) => mt,
None => match config.transient {
true => MountType::Transient,
false => default,
},
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The nested match statement to determine mount_type can be simplified for better readability. Using Option::unwrap_or with an if expression can make the logic more concise and easier to follow.

    let mount_type = config.mount.unwrap_or(if config.transient {
        MountType::Transient
    } else {
        default
    });


match mount_at(&sysroot_clone, &new_root, "sysroot") {
Ok(()) | Err(Errno::NOENT) => {}
Err(err) => Err(err)?,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The use of Err(err)? in this match arm is a bit unconventional. While correct, it can be made more explicit and readable. Using return Err(err.into()) would clearly show the error propagation and the conversion to an anyhow::Error.

        Err(err) => return Err(err.into()),

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW with stuff like this I personally am fine one marks it resolved without changing anything


let cmdline = match &args.cmdline {
Some(cmdline) => cmdline,
None => &std::fs::read_to_string("/proc/cmdline")?,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a new problem per se but this raises the now-more-obvious issue that we added a kargs parser into bootc, and not into composefs-boot...

Except though of course the "detect composefs" karg parsing is only on the composefs branch...

Let's just add a // TODO: Deduplicate this with composefs branch karg parser?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about using the new parser, but it's in bootc-lib and including the entire create for just one function didn't make much sense. Maybe we should move the cmdline parser to bootc/utils?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I've just added the TODO comment

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah +1 to moving the cmdline parser to bootc-utils, I'll go do that now

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels slightly large for utils? Some of the other crates we're adding are pretty small so a bootc-kargs crate seems nicer to me?

Or, slicing this differently...a general thing that's weird now is that lib contains most of the code.

But we could redo things so that there's e.g.:

  • utils
  • lib (general grab-bag of stuff like kargs, but not quite "utils")
  • core (what is currently lib)
  • cli

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I'll ask claude nicely to redo it into its own crate. I'll probably call it bootc-kernel-cmdline though to disambiguate from the stuff in crates/lib/src/bootc_kargs.rs.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

➡️ #1554

Move the composefs-setup-root code from composefs-rs to bootc-initramfs
crate

Signed-off-by: Johan-Liebert1 <[email protected]>
@cgwalters cgwalters merged commit 1dd55c2 into bootc-dev:main Aug 26, 2025
26 of 27 checks passed
gursewak1997 pushed a commit to gursewak1997/bootc that referenced this pull request Aug 28, 2025
…amfs

Move composefs setup root to bootc initramfs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants