Skip to content
This repository was archived by the owner on Jun 13, 2026. It is now read-only.

Add graceful stop control command — fixes the power-cut-only shutdown - #24

Merged
kariy merged 1 commit into
mainfrom
graceful-stop
Jun 12, 2026
Merged

Add graceful stop control command — fixes the power-cut-only shutdown#24
kariy merged 1 commit into
mainfrom
graceful-stop

Conversation

@kariy

@kariy kariy commented Jun 12, 2026

Copy link
Copy Markdown
Member

Fixes #22.

What

Adds a stop verb to the virtio-serial control channel. The guest acknowledges (ok stopping) and then runs the existing teardown_and_halt: Katana gets a TERM (KILL after 30s), sync, unmount of the sealed data disk, luksClose, poweroff — and QEMU exits on the guest poweroff. Recent writes become durable across restarts instead of depending on ext2 writeback timing.

Layers

File Change
scripts/build-initrd.sh (guest init) stop handler — ack first (teardown closes the channel), then teardown_and_halt
start-vm.sh Cleanup requests graceful stop and waits up to 30s before falling back to SIGTERM/KILL — so an operator Ctrl-C now flushes the chain state
scripts/test-initrd.sh Smoke test exercises stop on every PR: ack, Teardown: poweroff in the serial log, QEMU exit within 60s
scripts/test-snp-e2e.sh Graceful stop replaces the 45s writeback sleep with no wait at all — boot 2 becomes a regression test for shutdown durability (stop immediately after writes; state must survive). Old releases whose initrd lacks stop reply err unknown-command and get the legacy 45s wait, keeping the E2E workflow valid for existing tags
README.md Protocol table + durability semantics

Notes

  • The init script is inside the measured initrd ⇒ the launch measurement changes at the next release. Verifiers re-pin from launch-measurement-<tag>.txt as usual.
  • The PR's own build-and-boot check exercises the new command end to end in plain QEMU.
  • After the next release is tagged, the SNP E2E hardware run will exercise the graceful path (and the durability regression) automatically.

🤖 Generated with Claude Code

Fixes #22. Every VM stop was a host-side power cut: QEMU SIGTERM never
reaches the guest and busybox init has no ACPI handling, so init's
careful teardown path (stop katana, sync, umount, luksClose, poweroff)
was unreachable from outside. Database writes still in the guest page
cache (ext2 writeback lags ~30s) were lost on stop — discovered when
the SNP E2E reboot test found a torn database seconds after genesis
initialization.

- init: new `stop` control verb — acknowledge with "ok stopping" (before
  teardown closes the channel), then run teardown_and_halt. QEMU exits
  on the guest poweroff.
- start-vm.sh: cleanup now requests a graceful stop first and waits up
  to 30s for the guest to power off, falling back to the existing
  SIGTERM/KILL path for wedged guests or pre-stop initrds.
- test-initrd.sh: the smoke test now exercises `stop` on every PR —
  ack, teardown evidence in the serial log, QEMU exit.
- test-snp-e2e.sh: graceful stop replaces the 45s writeback sleep, with
  no wait at all on the graceful path — boot 2 is now a regression test
  for shutdown durability. Releases whose initrd predates `stop` reply
  "err unknown-command" and get the legacy 45s wait, keeping the E2E
  workflow valid for old tags.
- README: document the command and the durability semantics.

The init script is part of the measured initrd, so this changes the
launch measurement at the next release.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kariy
kariy merged commit 0f37832 into main Jun 12, 2026
3 checks passed
@kariy
kariy deleted the graceful-stop branch June 12, 2026 19:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Guest has no host-triggerable graceful shutdown — every VM stop is a power cut

1 participant