]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
repart: Add support for reading mkfs options from environment
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 9 Mar 2023 19:33:04 +0000 (20:33 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 10 Mar 2023 08:33:39 +0000 (09:33 +0100)
docs/ENVIRONMENT.md
src/home/homework-luks.c
src/partition/repart.c
src/shared/mkfs-util.c
src/shared/mkfs-util.h

index 3e957113e74c04ef4ca4fb50831cc6af9104f668..3ec5573ff9524e0ee4059331c6fc9ae8473a1f95 100644 (file)
@@ -520,3 +520,9 @@ SYSTEMD_HOME_DEBUG_SUFFIX=foo \
   systemd-stub. Normally, requested measurement of resources is conditionalized
   on kernels that have booted with `systemd-stub`. With this environment
   variable the test for that my be bypassed, for testing purposes.
+
+`systemd-repart`:
+
+* `$SYSTEMD_REPART_MKFS_OPTIONS_<FSTYPE>` – configure additional arguments to use for
+  `mkfs` when formatting partition file systems. There's one variable for each
+  of the supported file systems.
index 8912b3df5241fa97072ebc11273a3d06353ea013..ac3d2b417c631080a029dfd6d5268a955d77be55 100644 (file)
@@ -2119,25 +2119,6 @@ static int home_truncate(
         return !trunc; /* Return == 0 if we managed to truncate, > 0 if we managed to allocate */
 }
 
-static int mkfs_options_for_fstype(const char *fstype, char ***ret) {
-        _cleanup_(strv_freep) char **l = NULL;
-        const char *e;
-        char *n;
-
-        assert(fstype);
-
-        n = strjoina("SYSTEMD_HOME_MKFS_OPTIONS_", fstype);
-        e = getenv(ascii_strupper(n));
-        if (e) {
-                l = strv_split(e, NULL);
-                if (!l)
-                        return -ENOMEM;
-        }
-
-        *ret = TAKE_PTR(l);
-        return 0;
-}
-
 int home_create_luks(
                 UserRecord *h,
                 HomeSetup *setup,
@@ -2371,9 +2352,10 @@ int home_create_luks(
 
         log_info("Setting up LUKS device %s completed.", setup->dm_node);
 
-        r = mkfs_options_for_fstype(fstype, &extra_mkfs_options);
+        r = mkfs_options_from_env("HOME", fstype, &extra_mkfs_options);
         if (r < 0)
                 return log_error_errno(r, "Failed to determine mkfs command line options for '%s': %m", fstype);
+
         r = make_filesystem(setup->dm_node, fstype, user_record_user_name_and_realm(h), NULL, fs_uuid, user_record_luks_discard(h), 0, extra_mkfs_options);
         if (r < 0)
                 return r;
index 4e0c5dd785cfaf2dce135fac52930141685fa80c..d80ba573df5b8d8d88be9b36859356f00432134a 100644 (file)
@@ -4092,6 +4092,7 @@ static int context_mkfs(Context *context) {
                 _cleanup_hashmap_free_ Hashmap *denylist = NULL;
                 _cleanup_(rm_rf_physical_and_freep) char *root = NULL;
                 _cleanup_(partition_target_freep) PartitionTarget *t = NULL;
+                _cleanup_strv_free_ char **extra_mkfs_options = NULL;
 
                 if (p->dropped)
                         continue;
@@ -4143,8 +4144,14 @@ static int context_mkfs(Context *context) {
                                 return r;
                 }
 
+                r = mkfs_options_from_env("REPART", p->format, &extra_mkfs_options);
+                if (r < 0)
+                        return log_error_errno(r,
+                                               "Failed to determine mkfs command line options for '%s': %m",
+                                               p->format);
+
                 r = make_filesystem(partition_target_path(t), p->format, strempty(p->new_label), root,
-                                    p->fs_uuid, arg_discard, context->sector_size, NULL);
+                                    p->fs_uuid, arg_discard, context->sector_size, extra_mkfs_options);
                 if (r < 0)
                         return r;
 
@@ -5413,6 +5420,7 @@ static int context_minimize(Context *context) {
                 _cleanup_(rm_rf_physical_and_freep) char *root = NULL;
                 _cleanup_(unlink_and_freep) char *temp = NULL;
                 _cleanup_(loop_device_unrefp) LoopDevice *d = NULL;
+                _cleanup_strv_free_ char **extra_mkfs_options = NULL;
                 _cleanup_close_ int fd = -EBADF;
                 sd_id128_t fs_uuid;
                 uint64_t fsz;
@@ -5477,8 +5485,14 @@ static int context_minimize(Context *context) {
                                 return r;
                 }
 
+                r = mkfs_options_from_env("REPART", p->format, &extra_mkfs_options);
+                if (r < 0)
+                        return log_error_errno(r,
+                                               "Failed to determine mkfs command line options for '%s': %m",
+                                               p->format);
+
                 r = make_filesystem(d ? d->node : temp, p->format, strempty(p->new_label), root, fs_uuid,
-                                    arg_discard, context->sector_size, NULL);
+                                    arg_discard, context->sector_size, extra_mkfs_options);
                 if (r < 0)
                         return r;
 
@@ -5532,7 +5546,7 @@ static int context_minimize(Context *context) {
                         return log_error_errno(r, "Failed to make loopback device of %s: %m", temp);
 
                 r = make_filesystem(d ? d->node : temp, p->format, strempty(p->new_label), root, p->fs_uuid,
-                                    arg_discard, context->sector_size, NULL);
+                                    arg_discard, context->sector_size, extra_mkfs_options);
                 if (r < 0)
                         return r;
 
index d64ef0d47a0b60e3193aab3dad7147a595172d5e..7e620391e3560cf9ffd9dd3e407fe9a0d191d2f9 100644 (file)
@@ -520,3 +520,24 @@ int make_filesystem(
 
         return 0;
 }
+
+int mkfs_options_from_env(const char *component, const char *fstype, char ***ret) {
+        _cleanup_(strv_freep) char **l = NULL;
+        const char *e;
+        char *n;
+
+        assert(component);
+        assert(fstype);
+        assert(ret);
+
+        n = strjoina("SYSTEMD_", component, "_MKFS_OPTIONS_", fstype);
+        e = getenv(ascii_strupper(n));
+        if (e) {
+                l = strv_split(e, NULL);
+                if (!l)
+                        return -ENOMEM;
+        }
+
+        *ret = TAKE_PTR(l);
+        return 0;
+}
index b99ec3c0ad3a5cf8338defb3a6221d8f4d2f4537..75ea58543a1e4c51f5122cfb68719bebaa892e25 100644 (file)
@@ -20,3 +20,5 @@ int make_filesystem(
                 bool discard,
                 uint64_t sector_size,
                 char * const *extra_mkfs_args);
+
+int mkfs_options_from_env(const char *component, const char *fstype, char ***ret);