]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
repart: do not assign new size larger than acquired or the specified maximum
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 4 Sep 2022 09:54:52 +0000 (18:54 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 8 Sep 2022 20:35:41 +0000 (05:35 +0900)
The acquired size may be larger than the requested maximum. So, let's
cap the value.

Note, at the final phase, the acquired size should be larger than the
requested minimum. Hence, the assertion about that is added.

src/partition/repart.c

index 368c2cd2892f8e4efbc5c6702784ac110ea20c4d..4857579977567249f6a6c4545702dc4c8eb38dce 100644 (file)
@@ -796,7 +796,8 @@ static bool context_grow_partitions_phase(
                                  * assigning this shouldn't impact the shares of the other
                                  * partitions. */
 
-                                p->new_size = MAX(round_down_size(share, context->grain_size), rsz);
+                                assert(share >= rsz);
+                                p->new_size = CLAMP(round_down_size(share, context->grain_size), rsz, xsz);
                                 charge = true;
                         }
 
@@ -822,7 +823,8 @@ static bool context_grow_partitions_phase(
                                 p->new_padding = xsz;
                                 charge = try_again = true;
                         } else if (phase == PHASE_DISTRIBUTE) {
-                                p->new_padding = MAX(round_down_size(share, context->grain_size), rsz);
+                                assert(share >= rsz);
+                                p->new_padding = CLAMP(round_down_size(share, context->grain_size), rsz, xsz);
                                 charge = true;
                         }