Declarative Apply: grow, create, and shrink partitions; remove Run#23
Declarative Apply: grow, create, and shrink partitions; remove Run#23eriknordmark wants to merge 2 commits into
Conversation
cf4f1d5 to
358f8d8
Compare
|
@deitch ready for review. Note the open question in the description: this moves the existing grow/shrink CLI under a |
|
It is a good open question. I do think |
|
@deitch done — folded
Tests were ported from One thing I dropped: the |
00c8469 to
6972d7f
Compare
Apply is the single entry point for reconciling a GPT disk to a desired set of partitions in an idempotent, restart-safe pass. It grows a partition to at least its size, creates it (with an empty filesystem) when absent, and optionally shrinks one partition to free space -- to an explicit size, or (when the size is zero) only as much as the grows and creates need. An existing partition is matched by GUID or by name/label/uuid; with no disk given, the disk is discovered from the identifiers and kernel device names are resolved via sysfs. A created partition's GPT entry is published only by the final table write, so an interrupted run converges on re-run. Run is removed, and the cmd/resizer CLI collapses from resize/apply subcommands into a single bare `resizer [disk]`. Apply's Go signature is unchanged, so existing callers (e.g. EVE's storage-resizer) are unaffected. Implements diskfs#22. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Not required by this PR. Since the previous pin, go-diskfs gained a squashfs read fix for images with no fragment or xattr table (#413) and an added GPT round-trip test (#414); the resizer depends on neither. Bumped only to keep the module on current go-diskfs master. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
6972d7f to
e5802c9
Compare
|
@deitch follow-up now that this is polished for review: restructured into two commits — the declarative |
Reconcile a GPT disk to a desired set of partitions in a single, idempotent,
restart-safe pass.
Applygrows partitions, creates absent ones (with anempty filesystem), and optionally shrinks one to free space.
This began as "create a partition as part of a resize" (#22) and, following
review, folds the remaining
Runcapabilities intoApplyand removesRun,so there is a single entry point that can do it all.
Behavior
desiredis monotonically non-destructive: absent ⇒ create, smaller than itssize ⇒ grow (relocate + copy, partition number preserved), already ≥ size ⇒
no-op (never shrunk).
PartitionSpeclocates an existing partition to grow byMatch(name/label/uuid); withoutMatchit is keyed by GUID, and an absentGUID is created (the GUID becomes the created partition's identity). A matched
partition's type/label are asserted so it never operates on an unexpected disk.
size, or — when the size is 0 — shrink-to-fit (only as much as the grows and
creates need). When nil, nothing can be shrunk by accident.
identifiers; by-name (e.g.
sda3) identifiers are resolved to UUIDs via sysfs.write, so "entry present ⇒ filesystem present" and an interrupted create
converges on re-run.
Go API
Apply(disk, desired []PartitionSpec, shrink *ShrinkSpec, fixErrors, dryRun)—the signature is unchanged, so existing callers (e.g. EVE's storage-resizer)
need no code change.
PartitionSpecgains an optionalMatch PartitionIdentifier;ShrinkSpec.Size == 0requests shrink-to-fit.Run,PartitionChange, andNewPartitionChangeare removed.CLI
The
resize/applysubcommands collapse into a single bare command:--partitiontakesguid=ormatch=<id>plusminsize=(and optionallabel=,type=,index=,fs=);--shrinktakesidentifier:value[:size](sizeoptional for to-fit); the disk is an optional positional argument.
--preserve-numbersis dropped — partition numbers are always preserved.
Tests
Suites ported from
RuntoApply, plus new coverage for by-name/labelmatching, shrink-to-fit, disk discovery, and name resolution. The full
end-to-end suite, the opt-in SIGKILL chaos soak, and
golangci-lintall pass.Commits
Two commits: the declarative
Applyfeature (grow/create/shrink, removeRun,single bare
resizerCLI, tests + README) and a separate go-diskfs re-pin tocurrent master.