Skip to content

audit: v0.8.1 flow read, five fixes and docs - #346

Merged
CMGS merged 9 commits into
masterfrom
audit/v0.8.1-flow-read
Nov 30, 2026
Merged

CMGS merged 9 commits into
masterfrom
audit/v0.8.1-flow-read

Conversation

@CMGS

@CMGS CMGS commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

What

A flow read of v0.8.1. The per-file ledger was at zero for every lens, but 115 of the 258 production files sat in no declared flow, so the windows that cross them had never been walked. Seven new flows cover them, and an eighth reader re-read vm resize independently. This PR carries what the read found.

Fixes

Where Defect Fix
meta/json/store.go A json-engine commit renames its file in under the flock and fsyncs after it drops the flock. A second writer in that gap rotated the unsynced file into .prev and unlinked the last generation on disk. A power loss before either fsync finished could leave main and .prev both empty: every verb on the namespace fails as corrupt until a manual repair. The rotation syncs main first.
daemon/cache.go A full subscriber queue (128) dropped events without a sign. A client that was reading kept a VM at its old state until it changed again; one pass that changes more than 128 VMs is enough. The subscriber is removed and its stream closed, so the client reconnects to a fresh snapshot.
cmd/vm/status.go vm status --event compared seven fields and the disk size was not one of them, so a storage-only vm resize emitted no MODIFIED. The size is part of the comparison.
hypervisor/resize.go The disk tools run to their end on a cancel, but the record update after them used the canceled context: the disk was grown and the old size stayed on record until the same resize ran again. Once the disk has grown the record is written on a detached context, as vm start does after a launch.
hypervisor/restore.go The commit that marks the VM stopped after the kill logged its error and the restore went on; the final commit then opened a second compute interval over the one still open. The restore returns the error before it touches the run dir; the next restore or start closes the interval once.
cmd/vm/resize.go, docs/windows.md The grow hint for a Windows cloud image named growpart and resize2fs, and the docs named Disk Management. Neither works on the published win11 image: a Recovery partition sits right behind C:. The hint says what is in the way and points at a new docs section with the steps measured on hardware and what they cost.
README.md, docs/install.md Install commands downloaded v0.7.8, which has none of vm resize. v0.8.1.
docs/daemon.md The ledger section named only SIGKILL as losing an entry. It also names power loss (the ledger is not fsynced), and the events section says the stream is closed for a reader 128 events behind.

Each code fix has a test that fails on v0.8.1.

Kept without code

  • Ledger entries are written after their commit (updateVM, the delete protocol, snapshot create and remove). A process death between the two loses the entry. docs/daemon.md states this contract, and downstream tolerates an unpaired endpoint.
  • A .tmp-* file after a SIGKILL inside a json commit. One stray copy per kill inside a millisecond window; it is never read.
  • vm restore --from-dir on a directory whose snapshot files are symlinks passes preflight and then cannot populate. cocoon's export writes regular files only and no known producer writes symlinks.
  • Two snapshot export --to-dir runs into one directory at once can mix their files. The target directory belongs to the caller.
  • qemu-img resize is killed by a cancel. A qcow2 grow is crash-consistent; the retry runs it again.

Read with no finding

Balloon runtime, bridge NIC lifecycle, the lock and lease primitives, and the independent read of vm resize. Reports name the windows and the lines that close each.

Decisions for the maintainer

  • About 14 µs per json-engine commit. The added fsync showed in 8 of 8 paired runs: +2.4 % on a 594 µs durable update. It buys the end of a window in which a power loss could leave a namespace unreadable. sqlite, the default, does not change.
  • The Windows steps delete the Recovery partition. They are what makes C: grow on the published image, and the guest loses its recovery environment. The docs say so and name the alternative (recreate Recovery behind C:), which was not tested. Placing Recovery ahead of C: in the image build would remove the problem at its source; that belongs to cocoonstack/windows.

Size and cost

  • Production code +74 / -36, net +38. Tests +163. Docs +26 / -13. No comment added on balance.
  • Hot paths: one fsync call per json-engine commit (measured below). vm start, clone, stop, restore and rm do no new work on their success path, and the timing row shows none.

Gates: golangci-lint 0 issues on linux and darwin, fmt, vet, go mod tidy -diff, asl on both; go test -race on darwin (39 packages) and in a linux container (40 packages).

Coverage

Hardware: bare metal, x86_64, kernel 6.12, XFS; Cloud Hypervisor v56.0.0-dev-5fd961f7 and the pinned Firecracker fork build; head e635963 against v0.8.0 (6d4952a) for the regression and timing, against v0.8.1 for the store benchmark. The contrasts and thresholds were written down before the run. The last two commits of this branch (the Windows hint and docs) came after the run and change no measured path.

Case How Result
Functional regression (r.sh: CH and FC, CNI NICs, clone, restore, hibernate, disk and NIC hot-plug, cloud image, snapshots, gc) hardware 113 pass, 1 fail. The fail is a stale contrast of the script: it expects the base to accept a qcow2 with a backing file, and v0.8.0 refuses it like the head
Timing, six operations, 24 rounds, two copies of each binary (p50 ms: base / head / base copy / head copy) hardware clone 83.0 / 83.6 / 89.4 / 87.3; cold start 66.9 / 66.5 / 66.8 / 66.8; start on a running VM 47.5 / 47.3 / 47.6 / 47.5; stop 94.3 / 87.6 / 92.1 / 93.6; rm 52.2 / 52.7 / 50.2 / 65.1; total 433 / 438 / 452 / 460. Every head-minus-base gap is inside the gap between two copies of one binary
json-engine durable update, 400 updates over 100 records, 8 paired runs hardware base median 237838 µs, head 243623 µs: +14.5 µs per update, +2.4 %, head higher in 8 of 8 pairs
sqlite durable update, the unchanged control, 4 paired runs hardware 23301 against 23090 µs: no difference
json create, 8 processes on one store, 6 paired runs hardware +1.2 %, head higher in 5 of 6 pairs
SIGTERM to vm resize --storage while resize2fs runs (a stand-in sleeps 3 s first) hardware exit status 0, filesystem and record at 20G, the VM boots, marker kept. Before: exit 1 and the old size on record until a rerun
Windows 11 image, vm resize --storage +10G, then Resize-Partition alone hardware the disk grows to 50G; C: stays at 41995468800 bytes, because partition 4 (Recovery, 829 MB) follows it. This is what the first hint of this branch told users to do
Same, with reagentc /disable, removal of the Recovery partition, then Resize-Partition hardware C: grows to 53564390912 bytes and reads the same after a cold boot; Windows RE goes from Enabled to Disabled. The run selected the partition by type; the docs remove it by number (disk 0, partition 4 on this image, from a listing of C:'s disk), so a Recovery partition elsewhere stays. That form was not rerun
json rotation order, and a crash at the new step unit tests main is synced before the link; the store recovers from a crash there
Stream cut-off at 129 events in one pass unit test 128 delivered, then closed; a new subscriber is served
Storage-only change in the event diff unit test differs
Resize canceled while the first disk tool runs unit test with stand-in tools and a FIFO gate returns success, record at the new size
Restore whose stop commit fails unit test with a store that fails once error, run dir untouched, interval still open, nothing emitted
The power-loss window of the json rotation itself not run a power loss cannot be injected between two commits; the fix is an ordering change and the test pins the order
Recreating the Recovery partition behind a grown C: not run named in the docs as untested

CMGS added 9 commits November 30, 2026 22:05
A commit renames its new file in under the flock and fsyncs only after it drops the flock. A second writer that took the flock in that gap rotated the unsynced file into .prev and unlinked the last generation that was on disk. A power loss before either fsync finished could then leave main and .prev both without data, and every verb on that namespace failed as corrupt until a manual repair.

The rotation now syncs main first. It costs one fsync call on a file that is clean whenever the writer before has finished its own.
…osed

A full subscriber queue dropped the event and said nothing, so a client that was reading kept a VM at its old state until that VM changed again; one pass that changes more than 128 VMs is enough. The subscriber is now removed and its stream closed: the client reconnects and gets a fresh snapshot. The pass still never blocks.

docs/daemon.md also says that a power loss can lose the last ledger entries, which the ledger never fsyncs.
The event diff compared id, name, state, vCPUs, memory, IPs and image. Since vm resize the disk size changes too, and a resize of only the disk emitted no MODIFIED.
The disk tools run to their end on a cancel, but the record update after them used the canceled context, so the command failed with the disk grown and the old size on record until the same resize was run again. Once the disk has grown the record is written on a detached context, as vm start does after a launch.

The hint for a Windows cloud image names a Windows command; it named growpart and resize2fs.
…t commit

The commit that marks the VM stopped after the kill logged its error and the restore went on. The final commit then set a new start over the interval that was still open: the ledger got a second compute.start and the first never got its stop. The restore now returns the error before it touches the run dir; the VMM is dead and the record still open, so the next restore or start closes the interval once.
… steps

On the published win11 image a Recovery partition sits right behind C:, so Resize-Partition alone leaves C: at its old size after vm resize --storage; the hint named that command and the docs named Disk Management, and neither works. The hint now says what is in the way, and docs/windows.md has the steps measured on hardware (reagentc /disable, remove the Recovery partition, Resize-Partition) with what they cost: the guest loses its recovery environment.
…covery partition

The example piped every partition of type Recovery on every disk into Remove-Partition. Only the one directly behind C: is in the way: the steps now list C:'s disk and remove that partition by disk and partition number.
…ve letter

The text tells the reader to take two numbers from the listing, and the listing showed only one of them.
@CMGS
CMGS merged commit b5f3170 into master Nov 30, 2026
4 checks passed
@CMGS
CMGS deleted the audit/v0.8.1-flow-read branch November 30, 2026 16:04
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.

1 participant