Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/minimald/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ stdlib.workspace = true

# The guest (initramfs pid-1) boot path is Linux-only.
[target.'cfg(target_os = "linux")'.dependencies]
nix.workspace = true
tokio-vsock.workspace = true
11 changes: 0 additions & 11 deletions crates/minimald/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use std::{
};
use tokio::{
io::{AsyncRead, AsyncWrite},
net::UnixStream,
sync::{Mutex, MutexGuard},
};

Expand Down Expand Up @@ -155,16 +154,6 @@ impl Connection {
)
}

/// Thin wrapper over [`Connection::from_stream`] for the UDS transport.
pub(crate) async fn from_socket(
s: UnixStream,
c: Arc<RuConfig>,
serv: ServerStateHandle,
was_local_uds: bool,
) -> (ConnectionHandle, RunningSession<ConnectionHandler>) {
Self::from_stream(s, c, serv, was_local_uds).await
}

pub(crate) fn pending_config_mut(&mut self, id: ChannelId) -> Option<&mut ChannelConfig> {
let c = self.channels.get_mut(&id)?;
if c.closed {
Expand Down
34 changes: 19 additions & 15 deletions crates/minimald/src/guest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,32 @@ fn raw_mount(
}

/// Enter the generic upstream guest rootfs from the initramfs. Mounts the rootfs
/// block `device` (ext4, read-only) at `newroot`, brings up the
/// pseudo-filesystems + a writable tmpfs (for session state) inside it, then
/// chroots in. minimald (static, already running) keeps executing with the
/// rootfs as its filesystem view, so `/bin/sh` and its libs resolve. The
/// `newroot/{dev,proc,sys,run}` mountpoints must exist in the rootfs (the
/// generic microvm-rootfs provides them).
pub fn enter_rootfs(device: &str, newroot: &str) -> std::io::Result<()> {
std::fs::create_dir_all(newroot)?;
raw_mount(device, newroot, "ext4", libc::MS_RDONLY)?;
raw_mount("devtmpfs", &format!("{newroot}/dev"), "devtmpfs", 0)?;
raw_mount("proc", &format!("{newroot}/proc"), "proc", 0)?;
raw_mount("sysfs", &format!("{newroot}/sys"), "sysfs", 0)?;
raw_mount("tmpfs", &format!("{newroot}/run"), "tmpfs", 0)?;
/// block `device` (ext4, read-only), brings up the pseudo-filesystems +
/// a writable tmpfs (for session state) inside it, then chroots in.
///
/// NOTE: The rootfs at the time this function is called is expected to be the initramfs.
/// If it is instead another filesystem, then its memory will not be reclaimed.
///
/// The `/{dev,proc,sys,run}` mountpoints must already exist on the provided rootfs
/// device.
pub fn enter_rootfs(device: &str) -> std::io::Result<()> {
const NEWROOT: &str = "/newroot";
std::fs::create_dir_all(NEWROOT)?;
raw_mount(device, NEWROOT, "ext4", libc::MS_RDONLY)?;
raw_mount("devtmpfs", &format!("{NEWROOT}/dev"), "devtmpfs", 0)?;
raw_mount("proc", &format!("{NEWROOT}/proc"), "proc", 0)?;
raw_mount("sysfs", &format!("{NEWROOT}/sys"), "sysfs", 0)?;
raw_mount("tmpfs", &format!("{NEWROOT}/run"), "tmpfs", 0)?;

let to_io = |_| std::io::Error::new(std::io::ErrorKind::InvalidInput, "NUL in chroot path");
let c_newroot = CString::new(newroot).map_err(to_io)?;
let c_newroot = CString::new(NEWROOT).map_err(to_io)?;
// SAFETY: `chroot(2)` with a valid C string for the new root.
if unsafe { libc::chroot(c_newroot.as_ptr()) } != 0 {
return Err(std::io::Error::last_os_error());
}
std::env::set_current_dir("/")?;
tracing::info!(device, "entered upstream rootfs (chroot)");

tracing::info!(device, "switched to upstream rootfs (pivot_root)");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Fix misleading root-switch log text.

Line 124 reports pivot_root, but this function calls libc::chroot (Line 119). Please align the message with actual behavior to avoid misleading ops/debugging signals.

Suggested patch
-    tracing::info!(device, "switched to upstream rootfs (pivot_root)");
+    tracing::info!(device, "entered upstream rootfs (chroot)");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
tracing::info!(device, "switched to upstream rootfs (pivot_root)");
tracing::info!(device, "entered upstream rootfs (chroot)");
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/minimald/src/guest.rs` at line 124, The log message incorrectly states
"pivot_root" while the code actually calls libc::chroot; update the
tracing::info! invocation to accurately reflect the operation (e.g., "switched
to upstream rootfs (chroot)" or "changed rootfs via chroot") so logs match the
libc::chroot call and avoid misleading debugging; locate the tracing::info! call
near the libc::chroot usage in guest.rs and change the message string
accordingly.

Ok(())
}

Expand Down
Loading
Loading