Repository navigation
repart: Keep new partitions after existing same-type partitions - #43470
Conversation
5a430a7 to
d7d0e25
Compare
|
Looks good, but please squash it into a single commit and drop the Signed-off-by. |
aa3d4cd to
60dfb46
Compare
All eight review lenses completed again on the reworked head ( The rework is a clear improvement: Two previously reported findings remain open, and one new build-breaking problem was found: moving numbering from free-area order to definition order changes the numbers that the existing Must fix
Suggestions
Nits
The seven ShellCheck SC2140 comments on this pull request were filed against the earlier |
| LIST_FOREACH(partitions, p, context->partitions) | ||
| if (PARTITION_EXISTS(p) && !PARTITION_IS_FOREIGN(p) && | ||
| sd_id128_equal(p->type.uuid, partition->type.uuid)) | ||
| partno = MAX(partno, p->partno + 1); |
There was a problem hiding this comment.
Claude: nit: The scan just below deliberately guards with p->partno != UINT64_MAX before touching p->partno, but this loop evaluates p->partno + 1 unguarded. It is safe today because context_unload_partition_table() resets partno to UINT64_MAX and clears current_partition together (lines 4218/4222), so PARTITION_EXISTS(p) implies a valid number. But if that pairing ever breaks, the sentinel wraps to 0 and silently disables the whole adjustment rather than failing. Either mirror the existing style with p->partno != UINT64_MAX && in the condition, or add assert(p->partno != UINT64_MAX); to document the dependency.
| "No free partition number available after existing partitions of type %s.", | ||
| SD_ID128_TO_UUID_STRING(type_uuid)); | ||
|
|
||
| partno = MAX(partno, p->partno + 1); |
There was a problem hiding this comment.
Claude: must-fix: The new floor never falls back to a free lower slot, so a table that previously worked can now fail the whole run permanently. partno only ever rises (MAX(partno, p->partno + 1)) and freed low slots are never reclaimed, so if any existing partition of the requested type sits high in the entry array, every lower hole is skipped and find_unused_partno() fails even though dozens of slots are free. Before this change find_first_unused_partno() returned the first hole and the run succeeded.
Concrete case: a GPT whose only linux-generic partition is at partno 127 of 128, plus a definition that adds another linux-generic. context_assign_partnos() fails, so context_ponder() fails, so systemd-repart --dry-run=no refuses the disk. That is the ExecStart= of units/systemd-repart.service, which is not covered by the unit's SuccessExitStatus=76 77, so the unit fails at boot and the root filesystem is never grown. The entry count comes from the on-disk GPT header, so for --image= on an untrusted or merely unusual image this is externally influenced input.
The condition is also self-inflicted and monotone: repeated create/delete churn of one type walks that type's maximum upward, after which every subsequent invocation fails with no recovery short of manual repartitioning. Consider falling back to a free lower slot (with a warning) when no slot is available above the floor, or confining the failure to the affected partition (drop/defer it) rather than aborting the whole run.
e726a3e to
aedfbe5
Compare
When a partition is deleted from a table containing multiple partitions of the same type, filling the resulting partition-number gap can place a new partition before an existing partition matched to an earlier definition. This changes definition matching on the next invocation and breaks idempotency. Keep new partitions after existing partitions of the same type. If no partition table slot is available after them, fall back to the first unused slot. Which existing partition is matched to which definition is still determined by partition type and partition number order, as documented, and is unchanged by this. Fixes systemd#43449
aedfbe5 to
0a14ef7
Compare
Fixes #43449
Summary
systemd-repartcould fill a low-numbered partition-table gapwith a new partition of the same GPT type as an existing partition.
Because same-type partitions are matched according to definition order, this
could change the mapping on the next invocation and break idempotency.
Fix
partitions of the same GPT type.
for other types.
filling partition-number gaps.
repeated invocation.
Tests