]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
gpt-auto: take timeout opts in rootflags= into account 35518/head
authorMike Yuan <me@yhndnzj.com>
Sun, 8 Dec 2024 20:30:12 +0000 (21:30 +0100)
committerMike Yuan <me@yhndnzj.com>
Mon, 9 Dec 2024 18:59:29 +0000 (19:59 +0100)
We document that rootflags= is honored for gpt-auto,
but only fstab-generator actually carried the logic for
x-systemd.device-timeout= and .mount-timeout=.
Apply that to gpt-auto too.

src/gpt-auto-generator/gpt-auto-generator.c

index 150417626c15bd26fe678feb3c6bf2ce782f5de4..dbcef3b0a92223099b79acaa5f7a4307cd131b4f 100644 (file)
@@ -56,6 +56,7 @@ STATIC_DESTRUCTOR_REGISTER(arg_root_options, freep);
 static int add_cryptsetup(
                 const char *id,
                 const char *what,
+                const char *mount_opts,
                 bool rw,
                 bool require,
                 bool measure,
@@ -128,6 +129,10 @@ static int add_cryptsetup(
         if (r < 0)
                 return log_error_errno(r, "Failed to write file %s: %m", n);
 
+        r = generator_write_device_timeout(arg_dest, what, mount_opts, /* filtered = */ NULL);
+        if (r < 0)
+                return r;
+
         r = generator_add_symlink(arg_dest, d, "wants", n);
         if (r < 0)
                 return r;
@@ -180,7 +185,7 @@ static int add_mount(
                 const char *description,
                 const char *post) {
 
-        _cleanup_free_ char *unit = NULL, *crypto_what = NULL;
+        _cleanup_free_ char *unit = NULL, *crypto_what = NULL, *opts_filtered = NULL;
         _cleanup_fclose_ FILE *f = NULL;
         int r;
 
@@ -196,7 +201,9 @@ static int add_mount(
         log_debug("Adding %s: %s fstype=%s", where, what, fstype ?: "(any)");
 
         if (streq_ptr(fstype, "crypto_LUKS")) {
-                r = add_cryptsetup(id, what, rw, /* require= */ true, measure, &crypto_what);
+                /* Mount options passed are determined by partition_pick_mount_options(), whose result
+                 * is known to not contain timeout options. */
+                r = add_cryptsetup(id, what, /* mount_opts = */ NULL, rw, /* require= */ true, measure, &crypto_what);
                 if (r < 0)
                         return r;
 
@@ -213,6 +220,10 @@ static int add_mount(
                                         fstype, where);
         }
 
+        r = generator_write_device_timeout(arg_dest, what, options, &opts_filtered);
+        if (r < 0)
+                return r;
+
         r = unit_name_from_path(where, ".mount", &unit);
         if (r < 0)
                 return log_error_errno(r, "Failed to generate unit name: %m");
@@ -248,8 +259,12 @@ static int add_mount(
         if (fstype)
                 fprintf(f, "Type=%s\n", fstype);
 
-        if (options)
-                fprintf(f, "Options=%s\n", options);
+        if (opts_filtered)
+                fprintf(f, "Options=%s\n", opts_filtered);
+
+        r = generator_write_mount_timeout(f, where, opts_filtered);
+        if (r < 0)
+                return r;
 
         r = fflush_and_check(f);
         if (r < 0)
@@ -368,7 +383,7 @@ static int add_partition_swap(DissectedPartition *p) {
         }
 
         if (streq_ptr(p->fstype, "crypto_LUKS")) {
-                r = add_cryptsetup("swap", p->node, /* rw= */ true, /* require= */ true, /* measure= */ false, &crypto_what);
+                r = add_cryptsetup("swap", p->node, /* mount_opts = */ NULL, /* rw= */ true, /* require= */ true, /* measure= */ false, &crypto_what);
                 if (r < 0)
                         return r;
                 what = crypto_what;
@@ -646,7 +661,7 @@ static int add_root_cryptsetup(void) {
         /* If a device /dev/gpt-auto-root-luks appears, then make it pull in systemd-cryptsetup-root.service, which
          * sets it up, and causes /dev/gpt-auto-root to appear which is all we are looking for. */
 
-        return add_cryptsetup("root", "/dev/gpt-auto-root-luks", /* rw= */ true, /* require= */ false, /* measure= */ true, NULL);
+        return add_cryptsetup("root", "/dev/gpt-auto-root-luks", arg_root_options, /* rw= */ true, /* require= */ false, /* measure= */ true, NULL);
 #else
         return 0;
 #endif