Skip to content

Put back a Firecracker fork source that a killed restore left parked - #613

Draft
yummybomb wants to merge 2 commits into
hypeship/fork-pending-recoveryfrom
hypeship/fork-parked-source-recovery
Draft

yummybomb wants to merge 2 commits into
hypeship/fork-pending-recoveryfrom
hypeship/fork-parked-source-recovery

Conversation

@yummybomb

Copy link
Copy Markdown
Contributor

Summary

Startup puts back a Firecracker fork source that a killed restore left renamed aside, and the metadata loader no longer reads a directory as the guest its metadata names.

Split out of #555. Stacked on the fork recovery PR.

Why

When a Firecracker fork's snapshot state cannot be rewritten for its new path, the restore renames the source to <id>.fork-bak.<time> and links the source path to the fork while the snapshot loads. A kill inside that window leaves the link and the backup in place.

What changes

  • RecoverParkedForkSources runs under the data directory lock, before instances are listed, and renames the backup back. It acts only when the link points at a Firecracker fork that records that source. Any other layout is left as it is and logged, and the API still starts.
  • A link with no backup is removed when its target verifies the same way. An aliased restore replaces a dangling link instead of failing with "file exists".
  • loadMetadata rejects a directory whose metadata names another guest. Listings that fail on unreadable guests skip such a directory.
  • Network admission keeps the IP and MAC in a backup reserved, and refuses a new allocation if a backup cannot be read.
  • The owner checks from Delete forks that a restart interrupted #555 are dropped: under the lock a parked source has no live fork owner.

Testing

Unit tests cover the recovered layouts (link with backup, backup alone, dangling link), the refused ones (link to another fork, an ordinary directory at the source path, two backups), recovery going on past a refused source, the listing skip, and the network reservations.

On a staging host I could not make the fallback fire: every fork there rewrote its snapshot state, because source and fork paths have the same length. So the layout was made by hand on a stopped API (source renamed to a backup, source path linked to a pending standby fork that records it):

Build Result
main GET /instances/<source id> returned the fork. The backup was listed as the source. Layout unchanged
this branch Source put back, link removed, pending fork deleted, one instance listed

Not covered

  • The kill itself. The window was not reached by a real restore, so this shows what recovery does with the layout, not that the layout occurs.
  • listAllocations holds the alias read lock across the whole guest scan.

When a Firecracker fork's snapshot state cannot be rewritten for its new
path, the restore renames the source directory to <id>.fork-bak.<time>
and links the source path to the fork while the snapshot loads. Killing
the API there left the source ID resolving to the fork, and the backup
listed as a second guest.

Startup now renames the backup back, under the data directory lock and
before instances are listed. It acts only when the link points at a
Firecracker fork that records that source. Any other layout is left as
it is and logged, and the API still starts. A link with no backup is
removed when its target verifies the same way, and an aliased restore
replaces a dangling link instead of failing with "file exists".

The metadata loader rejects a directory whose metadata names another
guest, so a parked source, its link or a fork copy cut short by an older
binary can no longer be read as the guest it names. Listings that fail
on unreadable guests skip such a directory. Network admission keeps the
IP and MAC in a backup reserved until the source is put back.
An allocation is no longer derived from metadata that names another
guest, so a fixture without an ID has no allocation.

This branch has not been deployed

No deployments
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