From: Yu Watanabe Date: Sun, 4 Sep 2022 09:48:15 +0000 (+0900) Subject: repart: set new size for foreign partitions at first X-Git-Tag: v252-rc1~222^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bf99aed6e82d679d7a5ec3244255c63282c820ce;p=thirdparty%2Fsystemd.git repart: set new size for foreign partitions at first Otherwise, the new size may be larger than the acquired one. --- diff --git a/src/partition/repart.c b/src/partition/repart.c index b23d74bee4c..368c2cd2892 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -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; }