]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
repart: Consider existing partitions when placing
authorAdrian Vovk <adrianvovk@gmail.com>
Thu, 5 Sep 2024 00:19:27 +0000 (20:19 -0400)
committerAdrian Vovk <adrianvovk@gmail.com>
Tue, 17 Sep 2024 18:06:49 +0000 (14:06 -0400)
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".

src/partition/repart.c

index b430d2d463d741aa605c3b7dbeba06c8f3f24053..e1608bd64dc6585dae65e595bc788b785a630ccb 100644 (file)
@@ -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];