From bf99aed6e82d679d7a5ec3244255c63282c820ce Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 4 Sep 2022 18:48:15 +0900 Subject: [PATCH] repart: set new size for foreign partitions at first Otherwise, the new size may be larger than the acquired one. --- src/partition/repart.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/partition/repart.c b/src/partition/repart.c index b23d74bee4..368c2cd289 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; }