Skip to content

runsc: allow restoring from a FIFO statefile - #15553

Open
hugelgupf wants to merge 1 commit into
gvisor:masterfrom
hugelgupf:pr/restore-fifo-statefile
Open

hugelgupf wants to merge 1 commit into
gvisor:masterfrom
hugelgupf:pr/restore-fifo-statefile

Conversation

@hugelgupf

@hugelgupf hugelgupf commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Allow restoring from a FIFO at <image-path>/checkpoint.img. Restore only rejects an empty state file if the file is a regular file, and the state file header is now read in full, so a pipe that returns the header in short reads no longer fails with bad magic header.

Linux Fidelity

fs/stat.c:generic_fillattr() reports i_size_read(inode), and fs/pipe.c never sets i_size, so every pipe reports st_size == 0. POSIX only defines st_size for regular files and symlinks. fs/pipe.c:pipe_read() returns as soon as it has copied any data once the pipe is empty, so a read can return less than asked for.

Details

  • An empty stream still fails when the state file header is read.
  • This only applies to single-file checkpoints, because the pages file is read at offsets.
  • The metadata length, metadata, hash, and compressed chunk headers were already read with io.ReadFull; only the 8-byte magic header used a single read.
  • A stream that ends inside the header now fails with io.ErrUnexpectedEOF instead of bad magic header.

@hugelgupf

Copy link
Copy Markdown
Contributor Author

friendly ping

Comment thread runsc/boot/controller_test.go Resolved
Comment thread runsc/boot/controller_test.go Resolved
Comment thread runsc/boot/controller.go Resolved
@hugelgupf

Copy link
Copy Markdown
Contributor Author

ptal @milantracy

@hugelgupf
hugelgupf force-pushed the pr/restore-fifo-statefile branch from 257bccb to d9afd7c Compare November 4, 2026 22:47
@hugelgupf

Copy link
Copy Markdown
Contributor Author

Rebased onto current master. PTAL @milantracy

@hugelgupf

Copy link
Copy Markdown
Contributor Author

@milantracy friendly ping: all three of your comments are addressed (both defer f.Close()s, and the header read now uses io.ReadFull, so a short read from a pipe can't fail the magic check), and it's rebased onto master. Could you take another look and clear the change request?

@hugelgupf
hugelgupf force-pushed the pr/restore-fifo-statefile branch from d9afd7c to bc3639a Compare November 19, 2026 20:02
@hugelgupf

Copy link
Copy Markdown
Contributor Author

ping @milantracy

@hugelgupf

Copy link
Copy Markdown
Contributor Author

@milantracy friendly ping: ayushr2 approved this on 11-09, and it's signed off for DCO now. Is anything left from your review, or could you clear the change request?


🤖 Posted by an AI agent (Cursor · skill none) on behalf of @hugelgupf.

@hugelgupf
hugelgupf force-pushed the pr/restore-fifo-statefile branch from bc3639a to eac6adb Compare November 20, 2026 06:13
Restore rejected a statefile whose fstat st_size is 0, so a FIFO at
<image-path>/checkpoint.img never worked: pipes always report st_size 0.
Only apply the empty check to regular files. An empty stream still fails
when the statefile header is read. This applies to single-file
checkpoints only, because the pages file is read at offsets.

A read from a pipe can return fewer bytes than asked for. The statefile
reader read the 8-byte magic header with one Read, so a short read gave
ErrBadMagic. Read the header with io.ReadFull, like the metadata length,
metadata, and hash that follow it. The compressio readers already read
their fixed-size chunk headers and hashes in full. A stream that ends
inside the header now gives io.ErrUnexpectedEOF instead of ErrBadMagic.

Linux: generic_fillattr() reports i_size_read(inode), and fs/pipe.c
never sets i_size, so st_size is 0 for every pipe. pipe_read() returns
as soon as any data is available. POSIX only defines st_size for
regular files and symlinks.

Tests:
- TestStatefileShortReads (pkg/state/statefile) writes a statefile into
  an io.Pipe 1-3 bytes at a time, so every read is short, and reads it
  back with and without an integrity key, uncompressed and flate. With
  the header read reverted to one Read, every subtest fails with "bad
  magic header".
- TestRestoreReadersFromFIFO (runsc/boot) streams a statefile through a
  FIFO 1-3 bytes at a time, waiting for the FIFO to drain (FIONREAD)
  before each write, and reads it back through the restore path. It
  fails with "statefile cannot be empty" with the old size check, and
  with "bad magic header" with the old header read.
- TestRestoreReadersRejectEmptyRegularStateFile checks that an empty
  regular file is still rejected.
- //pkg/state/statefile:statefile_test, //runsc/boot:boot_test (FIFO
  tests 30 runs) and //pkg/compressio:compressio_test pass, as do
  TestCheckpointRestore and TestCheckpointResume in
  //runsc/container:container_test on systrap.

Assisted-by: Cortex Code
Signed-off-by: Chris Koch <[email protected]>
@hugelgupf
hugelgupf force-pushed the pr/restore-fifo-statefile branch from eac6adb to 8b433ed Compare November 20, 2026 17:38
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.

3 participants