]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
repart: set new size for foreign partitions at first
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 4 Sep 2022 09:48:15 +0000 (18:48 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 8 Sep 2022 20:35:41 +0000 (05:35 +0900)
Otherwise, the new size may be larger than the acquired one.

src/partition/repart.c

index b23d74bee4c0ea652de43486e141735eb21a12eb..368c2cd2892f8e4efbc5c6702784ac110ea20c4d 100644 (file)
@@ -717,6 +717,9 @@ static uint64_t scale_by_weight(uint64_t value, uint64_t weight, uint64_t weight
 }
 
 typedef enum GrowPartitionPhase {
+        /* The zeroth phase: do not touch foreign partitions (i.e. those we don't manage). */
+        PHASE_FOREIGN,
+
         /* The first phase: we charge partitions which need more (according to constraints) than their weight-based share. */
         PHASE_OVERCHARGE,
 
@@ -765,7 +768,13 @@ static bool context_grow_partitions_phase(
                         rsz = partition_min_size(context, p);
                         xsz = partition_max_size(context, p);
 
-                        if (phase == PHASE_OVERCHARGE && rsz > share) {
+                        if (phase == PHASE_FOREIGN && PARTITION_IS_FOREIGN(p)) {
+                                /* Never change of foreign partitions (i.e. those we don't manage) */
+
+                                p->new_size = p->current_size;
+                                charge = true;
+
+                        } else if (phase == PHASE_OVERCHARGE && rsz > share) {
                                 /* This partition needs more than its calculated share. Let's assign
                                  * it that, and take this partition out of all calculations and start
                                  * again. */
@@ -787,12 +796,7 @@ static bool context_grow_partitions_phase(
                                  * assigning this shouldn't impact the shares of the other
                                  * partitions. */
 
-                                if (PARTITION_IS_FOREIGN(p))
-                                        /* Never change of foreign partitions (i.e. those we don't manage) */
-                                        p->new_size = p->current_size;
-                                else
-                                        p->new_size = MAX(round_down_size(share, context->grain_size), rsz);
-
+                                p->new_size = MAX(round_down_size(share, context->grain_size), rsz);
                                 charge = true;
                         }