]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
repart: if now minimal size is specified, default to 10M 16191/head
authorLennart Poettering <lennart@poettering.net>
Tue, 16 Jun 2020 12:38:44 +0000 (14:38 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 16 Jun 2020 13:48:58 +0000 (15:48 +0200)
Prompted by this discussion:

https://lists.freedesktop.org/archives/systemd-devel/2020-June/044669.html

man/repart.d.xml
src/partition/repart.c

index 648d32625f86c1b100bb32b2cf86131c437ab2fd..32df1e3d7f76d40aa7aa4c1c7422a6d16ba2ec94 100644 (file)
         <varname>SizeMaxBytes=</varname>) otherwise. If the backing device does not provide enough space to
         fulfill the constraints placing the partition will fail. For partitions that shall be created,
         depending on the setting of <varname>Priority=</varname> (see above) the partition might be dropped
-        and the placing algorithm restarted. By default no size constraints are set.</para></listitem>
+        and the placing algorithm restarted. By default a minimum size constraint of 10M and no maximum size
+        constraint is set.</para></listitem>
       </varlistentry>
 
       <varlistentry>
index 76fc8bd1c966cd123770fa64deafa0805bc97c8c..d3706fe1806513b16b7a607f8ed789edb9e4d375 100644 (file)
 #include "terminal-util.h"
 #include "utf8.h"
 
+/* If not configured otherwise use a minimal partition size of 10M */
+#define DEFAULT_MIN_SIZE (10*1024*1024)
+
+/* Hard lower limit for new partition sizes */
+#define HARD_MIN_SIZE 4096
+
 /* Note: When growing and placing new partitions we always align to 4K sector size. It's how newer hard disks
  * are designed, and if everything is aligned to that performance is best. And for older hard disks with 512B
  * sector size devices were generally assumed to have an even number of sectors, hence at the worst we'll
@@ -322,7 +328,9 @@ static uint64_t partition_min_size(const Partition *p) {
 
         /* Calculate the disk space we really need at minimum for this partition. If the partition already
          * exists the current size is what we really need. If it doesn't exist yet refuse to allocate less
-         * than 4K. */
+         * than 4K.
+         *
+         * DEFAULT_MIN_SIZE is the default SizeMin= we configure if nothing else is specified. */
 
         if (PARTITION_IS_FOREIGN(p)) {
                 /* Don't allow changing size of partitions not managed by us */
@@ -330,11 +338,8 @@ static uint64_t partition_min_size(const Partition *p) {
                 return p->current_size;
         }
 
-        sz = p->current_size != UINT64_MAX ? p->current_size : 4096;
-        if (p->size_min != UINT64_MAX)
-                return MAX(p->size_min, sz);
-
-        return sz;
+        sz = p->current_size != UINT64_MAX ? p->current_size : HARD_MIN_SIZE;
+        return MAX(p->size_min == UINT64_MAX ? DEFAULT_MIN_SIZE : p->size_min, sz);
 }
 
 static uint64_t partition_max_size(const Partition *p) {