From: Adrian Vovk Date: Thu, 5 Sep 2024 00:19:27 +0000 (-0400) Subject: repart: Consider existing partitions when placing X-Git-Tag: v257-rc1~415^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=78e9059208c0a161ee6dc95c122ca7810b49a033;p=thirdparty%2Fsystemd.git repart: Consider existing partitions when placing Fixes an oversight in `context_allocate_partitions` that makes it succeed in cases where it should fail. Essentially, there was nothing actually enforcing SizeMinBytes= and PaddingMinBytes= for partitions that exist, only for new partitions. This behavior is inconsistent with the docs, which state that existing partitions will be grown to at least the specified minimum size, and that "If the backing device does not provide enough space to fulfill the constraints placing the partition will fail". --- diff --git a/src/partition/repart.c b/src/partition/repart.c index b430d2d463d..e1608bd64dc 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -977,14 +977,22 @@ static bool context_allocate_partitions(Context *context, uint64_t *ret_largest_ uint64_t required; FreeArea *a = NULL; - /* Skip partitions we already dropped or that already exist */ - if (p->dropped || PARTITION_EXISTS(p)) + if (p->dropped || PARTITION_IS_FOREIGN(p)) continue; /* How much do we need to fit? */ required = partition_min_size_with_padding(context, p); assert(required % context->grain_size == 0); + /* For existing partitions, we should verify that they'll actually fit */ + if (PARTITION_EXISTS(p)) { + if (p->current_size + p->current_padding < required) + return false; /* 😢 We won't be able to grow to the required min size! */ + + continue; + } + + /* For new partitions, see if there's a free area big enough */ for (size_t i = 0; i < context->n_free_areas; i++) { a = context->free_areas[i];