From 7cecc563163f539c497ecdf5ab00729fcd8c97c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 3 Dec 2019 16:06:47 +0100 Subject: [PATCH 1/2] cryptsetup-generator: unconfuse writing of the device timeout The code was using timeout=0 as the default option string. This option string was ultimately passed to generator_write_timeouts(), which only looks for comment=systemd.device-timeout= or x-systemd.device-timeout=, i.e. the whole call path was bogus. Let's rework this: generator_write_timeouts() now writes any timeouts if configured by the user. create_disk() writes out it's own timeout, but with lower priority. Since the code path that was calling timeout=0 was not effective, the only change is that we stop overwriting the timeout if explicitly configured by the user. In both code paths, ignore failure to write. --- src/cryptsetup/cryptsetup-generator.c | 22 +++++++++------------- src/shared/generator.c | 4 +++- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c index 811a9468c1..bf7a0fb2d5 100644 --- a/src/cryptsetup/cryptsetup-generator.c +++ b/src/cryptsetup/cryptsetup-generator.c @@ -362,7 +362,7 @@ static int create_disk( r = generator_write_timeouts(arg_dest, device, name, options, &filtered); if (r < 0) - return r; + log_warning_errno(r, "Failed to write device timeout drop-in: %m"); if (filtered) { filtered_escaped = specifier_escape(filtered); @@ -415,11 +415,11 @@ static int create_disk( return r; if (!noauto && !nofail) { - r = write_drop_in(arg_dest, dmname, 90, "device-timeout", - "# Automatically generated by systemd-cryptsetup-generator \n\n" + r = write_drop_in(arg_dest, dmname, 40, "device-timeout", + "# Automatically generated by systemd-cryptsetup-generator\n\n" "[Unit]\nJobTimeoutSec=0"); if (r < 0) - return log_error_errno(r, "Failed to write device drop-in: %m"); + log_warning_errno(r, "Failed to write device timeout drop-in: %m"); } return 0; @@ -646,7 +646,6 @@ static int add_proc_cmdline_devices(void) { crypto_device *d; HASHMAP_FOREACH(d, arg_disks, i) { - const char *options; _cleanup_free_ char *device = NULL; if (!d->create) @@ -662,14 +661,11 @@ static int add_proc_cmdline_devices(void) { if (!device) return log_oom(); - if (d->options) - options = d->options; - else if (arg_default_options) - options = arg_default_options; - else - options = "timeout=0"; - - r = create_disk(d->name, device, d->keyfile ?: arg_default_keyfile, d->keydev, options); + r = create_disk(d->name, + device, + d->keyfile ?: arg_default_keyfile, + d->keydev, + d->options ?: arg_default_options); if (r < 0) return r; } diff --git a/src/shared/generator.c b/src/shared/generator.c index 5b571681f2..06e1ab8031 100644 --- a/src/shared/generator.c +++ b/src/shared/generator.c @@ -237,10 +237,12 @@ int generator_write_timeouts( return log_error_errno(r, "Failed to make unit name from path: %m"); return write_drop_in_format(dir, unit, 50, "device-timeout", - "# Automatically generated by %s\n\n" + "# Automatically generated by %s\n" + "# from supplied options \"%s\"\n\n" "[Unit]\n" "JobRunningTimeoutSec=%s", program_invocation_short_name, + opts, timeout); } From ff757c9d294153a26a9dd2d9817d1985656f3002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 3 Dec 2019 17:04:26 +0100 Subject: [PATCH 2/2] hibernate-resume-generator: wait "infinitely" for the resume device This makes changes similar to the parent commit, but for hibernate-resume-generator. If resume= is specified on the kernel command line, we'll set JobRunningTimeoutSec=0 for the device. This matches what we do for the root device. In practice, other timeouts will take effect. For example dracut tries (and fails :[ ) to start dracut-emergency.service after some time. Fixes #7242, https://bugzilla.redhat.com/show_bug.cgi?id=1705522. --- .../hibernate-resume-generator.c | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/hibernate-resume/hibernate-resume-generator.c b/src/hibernate-resume/hibernate-resume-generator.c index 3f49f564d6..5e40933fdf 100644 --- a/src/hibernate-resume/hibernate-resume-generator.c +++ b/src/hibernate-resume/hibernate-resume-generator.c @@ -5,6 +5,7 @@ #include #include "alloc-util.h" +#include "dropin.h" #include "fstab-util.h" #include "generator.h" #include "log.h" @@ -68,18 +69,18 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat } static int process_resume(void) { - _cleanup_free_ char *name = NULL, *lnk = NULL; - const char *opts; + _cleanup_free_ char *service_unit = NULL, *device_unit = NULL, *lnk = NULL; int r; if (!arg_resume_device) return 0; - r = unit_name_from_path_instance("systemd-hibernate-resume", arg_resume_device, ".service", &name); + r = unit_name_from_path_instance("systemd-hibernate-resume", arg_resume_device, ".service", + &service_unit); if (r < 0) return log_error_errno(r, "Failed to generate unit name: %m"); - lnk = strjoin(arg_dest, "/" SPECIAL_SYSINIT_TARGET ".wants/", name); + lnk = strjoin(arg_dest, "/" SPECIAL_SYSINIT_TARGET ".wants/", service_unit); if (!lnk) return log_oom(); @@ -87,12 +88,21 @@ static int process_resume(void) { if (symlink(SYSTEM_DATA_UNIT_PATH "/systemd-hibernate-resume@.service", lnk) < 0) return log_error_errno(errno, "Failed to create symlink %s: %m", lnk); - if (arg_resume_options) - opts = arg_resume_options; - else - opts = arg_root_options; + r = unit_name_from_path(arg_resume_device, ".device", &device_unit); + if (r < 0) + return log_error_errno(r, "Failed to generate unit name: %m"); - r = generator_write_timeouts(arg_dest, arg_resume_device, arg_resume_device, opts, NULL); + r = write_drop_in(arg_dest, device_unit, 40, "device-timeout", + "# Automatically generated by systemd-cryptsetup-generator\n\n" + "[Unit]\nJobTimeoutSec=0"); + if (r < 0) + log_warning_errno(r, "Failed to write device timeout drop-in: %m"); + + r = generator_write_timeouts(arg_dest, + arg_resume_device, + arg_resume_device, + arg_resume_options ?: arg_root_options, + NULL); if (r < 0) return r;