Skip to content

qemu: open serial log with O_APPEND via chardev#209

Merged
sjmiller609 merged 1 commit intomainfrom
hypeship/qemu-serial-append
May 8, 2026
Merged

qemu: open serial log with O_APPEND via chardev#209
sjmiller609 merged 1 commit intomainfrom
hypeship/qemu-serial-append

Conversation

@sjmiller609
Copy link
Copy Markdown
Collaborator

@sjmiller609 sjmiller609 commented May 7, 2026

Summary

Switch the QEMU serial console from -serial file:<path> to a chardev with append=on:

-chardev file,id=serial0,path=<path>,append=on -serial chardev:serial0

-serial file: opens the path with plain O_WRONLY|O_CREAT, so QEMU writes at its internal fd offset. If the file is externally truncated (e.g. by rotateLogIfNeeded's copytruncate), the next write lands at the stale offset, creating a sparse hole of NUL bytes from byte 0 to that offset. Downstream log readers chunk those NULs and choke.

append=on makes QEMU pass O_APPEND, so every write atomically seeks to EOF — post-truncate writes correctly resume at byte 0.

This only addresses QEMU. Cloud Hypervisor's serial.mode=File does not expose an append flag and needs a separate fix (likely switching to Socket/Pipe mode with hypeman owning the file fd).

Test plan

  • go test ./lib/hypervisor/qemu/... passes
  • Updated TestBuildArgs_SerialLog to assert the new chardev args
  • Boot a VM with this build, run for long enough to trigger rotateLogIfNeeded, verify the post-rotation app.log has no sparse NUL hole

Note

Low Risk
Low risk: changes only QEMU CLI argument construction for serial logging and updates unit tests; main risk is QEMU arg compatibility/behavior differences across versions.

Overview
Switches QEMU serial logging from -serial file:<path> to a -chardev file,...,append=on plus -serial chardev:serial0, ensuring writes use O_APPEND and don’t create sparse NUL holes after external log truncation/rotation.

Updates TestBuildArgs_SerialLog to assert the new -chardev and chardev:serial0 arguments.

Reviewed by Cursor Bugbot for commit d90aac8. Bugbot is set up for automated code reviews on this repo. Configure here.

Use -chardev file,append=on for the serial console instead of -serial
file:. The latter opens the path with plain O_WRONLY|O_CREAT, so QEMU
writes at its internal fd offset. When a copytruncate-style log rotation
truncates the file out from under it, the next write lands at the stale
offset, leaving a sparse hole of NUL bytes from byte 0 onward.

With append=on QEMU uses O_APPEND, so every write atomically seeks to
EOF and post-truncate writes correctly resume at byte 0.
@sjmiller609 sjmiller609 marked this pull request as ready for review May 7, 2026 22:10
@firetiger-agent
Copy link
Copy Markdown

Firetiger deploy monitoring skipped

This PR didn't match the auto-monitor filter configured on your GitHub connection:

Any PR that changes the kernel API. Monitor changes to API endpoints (packages/api/cmd/api/) and Temporal workflows (packages/api/lib/temporal) in the kernel repo

Reason: PR modifies QEMU hypervisor configuration, not kernel API endpoints or Temporal workflows; unclear if this touches packages/api/cmd/api/ or packages/api/lib/temporal.

To monitor this PR anyway, reply with @firetiger monitor this.

@sjmiller609 sjmiller609 requested a review from rgarcia May 7, 2026 23:28
Copy link
Copy Markdown
Contributor

@rgarcia rgarcia left a comment

Choose a reason for hiding this comment

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

lgtm

@sjmiller609 sjmiller609 merged commit d32a762 into main May 8, 2026
11 checks passed
@sjmiller609 sjmiller609 deleted the hypeship/qemu-serial-append branch May 8, 2026 00:00
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.

2 participants