feat(minvmd): add krun_add_vsock_port2 FFI binding and host UDS bridge - #345
Conversation
- Add `krun_add_vsock_port2` FFI declaration in `krun/raw.rs` with a `listen: bool` direction flag; covered by the block-level SAFETY comment. - Wrap it in `krun/ctx.rs` as `Context::add_vsock_port2` with a per-call SAFETY comment naming pointer-lifetime and ownership invariants. - New `sock.rs`: `resolve_uds_path` (XDG_RUNTIME_DIR/minimal/minimald.sock, fallback ~/.minimal/local/minimald.sock), `prepare_socket_dir` (0700 parent dir), `verify_socket_permissions` (0600 check). `VSOCK_BRIDGE_PORT=2222` matches the guest-side stub (build-rootfs.sh: vsock_port_bridge=2222). - `VmConfig::apply` (macOS) resolves the UDS path, prepares its parent dir, and registers the vsock bridge with `listen=true` before boot. - `VmError::Io` variant added to carry filesystem errors from `apply`. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds host UDS↔vsock bridge support: new VmError I/O variant, libkrun FFI ChangesHost UDS↔vsock bridge for minimald
Sequence DiagramssequenceDiagram
participant VmConfig
participant sock as "sock module"
participant ctx as "Context"
participant libkrun as "libkrun FFI"
VmConfig->>sock: resolve_uds_path()
sock-->>VmConfig: PathBuf (XDG or home)
VmConfig->>sock: prepare_socket_dir(&path)
sock-->>VmConfig: Ok() or io::Error
VmConfig->>ctx: add_vsock_port2(2222, &path, true)
ctx->>ctx: CString(path)
ctx->>libkrun: krun_add_vsock_port2(ctx_id, port, cstr, listen)
libkrun-->>ctx: i32 return code
ctx->>ctx: check_backend(code)
ctx-->>VmConfig: Ok() or VmError
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with 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.
Inline comments:
In `@crates/minvmd/src/sock.rs`:
- Around line 30-39: resolve_uds_path currently uses
dirs::home_dir().unwrap_or_default() which yields an empty PathBuf and produces
a relative socket path when the home directory is unknown; update
resolve_uds_path to handle the None case explicitly by either returning a
Result<PathBuf, VmError> (propagate an error) or falling back to a safe absolute
path (e.g., /tmp/minimal/minimald.sock) instead of joining on an empty PathBuf,
and ensure callers of resolve_uds_path are adjusted to handle the Result if you
choose the error-return approach.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: aa0406b6-c5e2-4aa4-9b14-853fa25c51af
📒 Files selected for processing (6)
crates/minvmd/src/error.rscrates/minvmd/src/krun/ctx.rscrates/minvmd/src/krun/raw.rscrates/minvmd/src/lib.rscrates/minvmd/src/sock.rscrates/minvmd/src/vm.rs
There was a problem hiding this comment.
Generated by sdd-review for issue #345 · ● 15.4M
This comment has been minimized.
This comment has been minimized.
Replace unwrap_or_default() on dirs::home_dir() with .expect() so an unset HOME yields a clear panic rather than a silent relative path that would place the socket in the working directory (R3.2). Call verify_socket_permissions() in the boot parent after the READY marker is received. By that point libkrun has created and started listening on the minimald bridge socket, making the parent process the correct call site for the R3.2 ownership check. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Commit pushed:
|
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with 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.
Inline comments:
In `@crates/minvmd/src/cmd/boot.rs`:
- Around line 126-127: resolve_uds_path() can panic via an expect and must not
abort the non-fatal permission-check in boot; change the code calling
resolve_uds_path() in boot.rs to handle its Result instead of assuming
infallible: call resolve_uds_path() and if it returns Err(e) log a warning
(e.g., warn! or similar) and skip verify_socket_permissions, otherwise pass the
Ok(uds_path) into verify_socket_permissions(&uds_path) and handle its Err by
warning but continuing. Ensure no expect/unwrap remains around
resolve_uds_path() so boot continues on HOME-unset cases.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3fe2e4e9-d851-431f-a341-975a97bf394e
📒 Files selected for processing (2)
crates/minvmd/src/cmd/boot.rscrates/minvmd/src/sock.rs
🚧 Files skipped from review as they are similar to previous changes (1)
- crates/minvmd/src/sock.rs
When HOME is unset and XDG_RUNTIME_DIR is absent, the .expect() in resolve_uds_path() would panic. The boot permission-check path is non-fatal, so a panic there aborts the process after vm-up has already been printed. Change resolve_uds_path() to return io::Result<PathBuf>: - Returns Err with IoErrorKind::NotFound when dirs::home_dir() is None - boot.rs: match on Result, warn-and-skip on Err (non-fatal path) - vm.rs: propagate Err as VmError::Io (critical pre-boot path) - sock.rs tests: add .unwrap() to the three call sites Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Commit pushed:
|
Fixes clippy collapsible_if (-D warnings) failing build-macos. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
krun_add_vsock_port2(listen=true) binds the host UDS and returns EEXIST when the path already exists, which fails boot-e2e on persistent runners where the socket survives a prior run. Remove a pre-existing socket before registering; refuse to clobber any non-socket path. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
sdd-validate · Implementation boundary · Clean passBoundary resolved: Implementation — all 7 changed files are Rust source code in Task: #327 (R3.1, R3.2) · Feature: #311 ( Gate 1: Proof artifacts re-executed and passing
Gate 2: Changed files within task scope
Gate 3: No real credentials in the diff✅ Pass — no secrets, tokens, keys, or credentials in the diff. Result: No Blocker findings. 2 Warnings (out-of-scope files that are functionally necessary), 1 Info (test deferred to consumer CI). Feature #311 already carries
|
Closes #327
Implements R3.1 and R3.2 from the minvmd host-daemon spec.
Changes
krun/raw.rs—krun_add_vsock_port2FFI declaration (R3.1)Adds the
krun_add_vsock_port2declaration inside the existingunsafe extern "C"block with the block-level// SAFETY:comment. The newlisten: boolflag controls bridge direction:truemeans libkrun listens on the host UDS and bridges to the guest (listen=truefor the minimald bridge);falseis equivalent to the existingkrun_add_vsock_port(guest initiates, used for the READY marker).krun/ctx.rs—Context::add_vsock_port2safe wrapper (R3.1)Wraps
krun_add_vsock_port2with the same CString/lifetime discipline as the existingadd_vsock_port, plus a per-call// SAFETY:comment naming pointer-lifetime, value-passing, and ownership invariants.sock.rs— new: host UDS path resolution and socket-dir management (R3.2)VSOCK_BRIDGE_PORT = 2222— matches the guest-side stub (build-rootfs.sh:vsock_port_bridge=2222,socat VSOCK-LISTEN:2222,fork EXEC:cat).resolve_uds_path()→$XDG_RUNTIME_DIR/minimal/minimald.sock; fallback~/.minimal/local/minimald.sockviadirs::home_dir().prepare_socket_dir(path)— creates the parent dir with mode 0700 (recursive).verify_socket_permissions(path)— checks the socket file is 0600 (owner-only).VSOCK_BRIDGE_PORTdoc comment.vm.rs— register the vsock bridge before boot (R3.1)VmConfig::apply(macOS only) now callssock::resolve_uds_path(),sock::prepare_socket_dir(), andctx.add_vsock_port2(VSOCK_BRIDGE_PORT, &uds_path, true)beforekrun_start_enter. No changes toVmConfig::neworvmm_child.rs.error.rs—VmError::IovariantAdded to carry filesystem errors from
prepare_socket_dirthroughapply's return type.lib.rs—pub mod sockProof artifacts
Test (
cargo test -p minvmd sock::):(The post-step cleanup runs
cargo fmt+cargo clippy --fixon the runner since the agent environment has no crates.io access.)File —
crates/minvmd/src/krun/raw.rsnow contains:krun_add_vsock_port2declaration withlisten: boolparameter inside theunsafe extern "C"block covered by the block-level// SAFETY:comment (R3.1).crates/minvmd/src/krun/ctx.rswraps it asContext::add_vsock_port2with host UDS path and listen flag (R3.1).Next step
Merging this PR closes #327. Once every task sub-issue of the tracking issue (#311) is closed, the pipeline advances to
sdd:donefor a final human review and close.Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
index.crates.ioSee Network Configuration for more information.
Summary by CodeRabbit