From: Mike Yuan Date: Sun, 8 Dec 2024 20:30:12 +0000 (+0100) Subject: gpt-auto: take timeout opts in rootflags= into account X-Git-Tag: v258-rc1~1885^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f4a65d5f2d96069c6b7753023e7333d2afb1a0d5;p=thirdparty%2Fsystemd.git gpt-auto: take timeout opts in rootflags= into account 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. --- diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index 150417626c1..dbcef3b0a92 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -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