templates: add fork-only template registry and promotion lifecycle#213
Draft
sjmiller609 wants to merge 1 commit intomainfrom
Draft
templates: add fork-only template registry and promotion lifecycle#213sjmiller609 wants to merge 1 commit intomainfrom
sjmiller609 wants to merge 1 commit intomainfrom
Conversation
Introduces a templates package and Standby-instance promotion path so later PRs can wire fork-from-template into firecracker. The registry persists one JSON file per template under <data>/templates/<id>/, with fork refcount accounting and Delete-blocked-when-in-use. The instance manager owns the registry because template lifecycle is coupled to instance lifecycle: promotion guards on Standby+HasSnapshot, deletion clears IsTemplate on the source instance, and forks (PR 3) will increment the refcount. Hypervisor wire-up is deferred — this PR ships the registry, the StoredMetadata flags, and the manager helpers (templateGuard, templateForFork, validateForkResolvedFromTemplate) so PR 3 can plug in.
This was referenced May 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
lib/templatespackage with a JSON file-backedRegistry(Save/Get/GetByName/List/Delete + IncrementForkCount/DecrementForkCount).Templatemodel with hypervisor type/version, image+digest, vCPU/memory, fork refcount, and a reservedHotPagesPathfield for PR 8.lib/instancestemplate plumbing: promote/list/get/delete pluspaths.TemplatesDir()etc.IsTemplate/TemplateID/ForkOfTemplateon instance metadata; the manager owns atemplates.Registryit constructs at startup.Why
Foundation for snapshot fan-out: templates are the durable "tagged Standby instance promoted to fork-only parent" record that downstream PRs (shared mem-file, GC, UFFD page server) hang off of. Splitting it out keeps each follow-up reviewable.
Test plan
go test ./lib/templates/...go test ./lib/instances/...for unit coverage of new metadata fields🤖 Generated with Claude Code