Commit 1fa2172
feat(vz-backend): Phase 2 Day 3 — lifecycle + console forwarder
Replace the Phase 1 fail-closed stubs in VzProvider::load /
start / stop / status / info / http_port with real
VZVirtualMachine lifecycle wiring routed through
VzMachineHandle. On Apple Silicon, `VzProvider::load` now
validates the assembled VZVirtualMachineConfiguration,
instantiates a VZVirtualMachine on the shared serial dispatch
queue and spawns a kernel-console → tracing forwarder so guest
printk output flows into the same `vm_console` target crosvm
uses on Linux. The lifecycle methods drive Apple's completion-
handler blocks (block2) onto Tokio oneshots via
DispatchQueue::exec_sync; the queue is one-per-provider, per
Phase 0 §D pitfall #10.
Two new modules under ffi/:
- ffi/lifecycle.rs (437 LOC): VmState ↔ VZVirtualMachineState
mapping, SendableVm Send wrapper with documented invariants,
VzMachineHandle (validate → init → start/stop/current_state),
and a pure format_validate_error helper that decorates
Apple's entitlement error with the Day-4 codesign-script hint
before it ever reaches the operator.
- ffi/console_forwarder.rs (223 LOC): spawn_console_forwarder
emits one tracing event per guest line with vm_id attached,
exits cleanly on EOF, has a test-only shutdown_and_join for
deterministic test cleanup. Production never joins it — Vz
retains the kernel-console NSFileHandle until the VM drops,
so the forwarder exits naturally with the VzMachineHandle.
Not in Day 3 (deliberate, see PLAN.md):
- scripts/dev/sign-elastos-vz/ and the entitlements plist
(Day 4).
- elastos vm-debug boot CLI command (Day 4).
- Actual end-to-end guest boot validation on this Mac — that
needs codesign first.
- VZVirtualMachineDelegate via objc2::define_class!
(Day 5+, for crash details / network disconnect).
`set_session_for_vm`, `set_network_for_vm` and
`append_boot_args_for_vm` keep returning PHASE_1_STUB_MESSAGE —
they require late-bound mutation of a now-frozen
VZVirtualMachineConfiguration, which we'll handle by reshaping
the API to "set before load" in a later day.
Tests: 59 passing (was 51). Eight new / updated:
- ffi::lifecycle: vm_state mapping (all 10 variants),
unknown-variant raw-int round-trip, entitlement-hint
constant, format_validate_error embeds hint when Apple flags
entitlement, format_validate_error passes other errors
through unmodified.
- ffi::console_forwarder: EOF exit + clean join, timeout when
writer stays open, blank-line skip.
- provider: capsule-not-found for missing rootfs (replaces
Phase 1 stub assertion), lifecycle methods fail-closed with
CapsuleNotFound for an unloaded handle (replaces the
blanket PHASE_1_STUB_MESSAGE check).
Gates: cargo build --workspace, cargo test -p elastos-vz,
cargo clippy --workspace --all-targets -- -D warnings,
cargo fmt --check, scripts/check-linux-untouched.sh bcf5a0a,
mac-vz-feature-check exit 0 — all green.
On unsigned dev binaries `VzMachineHandle::new` fails with the
operator-friendly entitlement-hint message; Day 4 ships the
codesign script that lets the same path proceed to first boot.
Anchors: docs/vz-backend/PLAN.md (Phase 2), PHASE_0_SCOPE.md
§B/§D, PRINCIPLES.md "fail closed", state.md "support boundary".
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent bf3baef commit 1fa2172
5 files changed
Lines changed: 1029 additions & 176 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
0 commit comments