gpt-auto-generator: write fsck override unit to "middle" generator dir

We generally let gpt-auto-generator write to the "late" generator dir,
so that the explicit fstab-generator can write to the "middle" one. And
I think we should leave it that way. But we also want to override the
generic systemd-fsck-root.service service potentially, and if we'd do
that in the "late" generator dir, it would be pointless, since that's
ordered *after* the static version hence would never be taken into
consdiration.

Hence clean this up: keep writing to the late dir for everything,
except for the fsck stuff.
This commit is contained in:
Lennart Poettering
2025-03-20 10:34:42 +01:00
parent 96386bb5a7
commit e5d2701bc2

View File

@@ -47,6 +47,7 @@ typedef enum MountPointFlags {
} MountPointFlags;
static const char *arg_dest = NULL;
static const char *arg_dest_late = NULL;
static bool arg_enabled = true;
static GptAutoRoot arg_auto_root = _GPT_AUTO_ROOT_INVALID;
static GptAutoRoot arg_auto_usr = _GPT_AUTO_ROOT_INVALID;
@@ -95,7 +96,7 @@ static int add_cryptsetup(
if (r < 0)
return log_error_errno(r, "Failed to generate unit name: %m");
r = generator_open_unit_file(arg_dest, /* source = */ NULL, n, &f);
r = generator_open_unit_file(arg_dest_late, /* source = */ NULL, n, &f);
if (r < 0)
return r;
@@ -142,27 +143,27 @@ 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);
r = generator_write_device_timeout(arg_dest_late, what, mount_opts, /* filtered = */ NULL);
if (r < 0)
return r;
r = generator_add_symlink(arg_dest, d, "wants", n);
r = generator_add_symlink(arg_dest_late, d, "wants", n);
if (r < 0)
return r;
const char *dmname = strjoina("dev-mapper-", e, ".device");
if (require) {
r = generator_add_symlink(arg_dest, "cryptsetup.target", "requires", n);
r = generator_add_symlink(arg_dest_late, "cryptsetup.target", "requires", n);
if (r < 0)
return r;
r = generator_add_symlink(arg_dest, dmname, "requires", n);
r = generator_add_symlink(arg_dest_late, dmname, "requires", n);
if (r < 0)
return r;
}
r = write_drop_in_format(arg_dest, dmname, 50, "job-timeout",
r = write_drop_in_format(arg_dest_late, dmname, 50, "job-timeout",
"# Automatically generated by systemd-gpt-auto-generator\n\n"
"[Unit]\n"
"JobTimeoutSec=infinity"); /* the binary handles timeouts anyway */
@@ -220,7 +221,7 @@ static int add_veritysetup(
return log_error_errno(r, "Failed to generate unit name: %m");
_cleanup_fclose_ FILE *f = NULL;
r = generator_open_unit_file(arg_dest, /* source= */ NULL, n, &f);
r = generator_open_unit_file(arg_dest_late, /* source= */ NULL, n, &f);
if (r < 0)
return r;
@@ -248,19 +249,19 @@ static int add_veritysetup(
if (r < 0)
return log_error_errno(r, "Failed to write file %s: %m", n);
r = generator_write_device_timeout(arg_dest, data_what, mount_opts, /* filtered= */ NULL);
r = generator_write_device_timeout(arg_dest_late, data_what, mount_opts, /* filtered= */ NULL);
if (r < 0)
return r;
r = generator_write_device_timeout(arg_dest, hash_what, mount_opts, /* filtered= */ NULL);
r = generator_write_device_timeout(arg_dest_late, hash_what, mount_opts, /* filtered= */ NULL);
if (r < 0)
return r;
r = generator_add_symlink(arg_dest, dd, "wants", n);
r = generator_add_symlink(arg_dest_late, dd, "wants", n);
if (r < 0)
return r;
r = generator_add_symlink(arg_dest, dh, "wants", n);
r = generator_add_symlink(arg_dest_late, dh, "wants", n);
if (r < 0)
return r;
@@ -270,7 +271,7 @@ static int add_veritysetup(
return log_oom();
r = write_drop_in_format(
arg_dest,
arg_dest_late,
dmname, 50, "job-timeout",
"# Automatically generated by systemd-gpt-auto-generator\n\n"
"[Unit]\n"
@@ -331,7 +332,7 @@ static int add_mount(
fstype, where);
}
r = generator_write_device_timeout(arg_dest, what, options, &opts_filtered);
r = generator_write_device_timeout(arg_dest_late, what, options, &opts_filtered);
if (r < 0)
return r;
@@ -339,7 +340,7 @@ static int add_mount(
if (r < 0)
return log_error_errno(r, "Failed to generate unit name: %m");
r = generator_open_unit_file(arg_dest, /* source = */ NULL, unit, &f);
r = generator_open_unit_file(arg_dest_late, /* source = */ NULL, unit, &f);
if (r < 0)
return r;
@@ -352,6 +353,10 @@ static int add_mount(
if (post)
fprintf(f, "Before=%s\n", post);
/* NB: here we do not write to arg_dest_late, but to arg_dest! We typically leave the normal
* generator drop-in dir for explicit configuration via systemd-fstab-generator or similar, and put
* out automatic configuration in the arg_dest_late directory. But this one is an exception, since we
* need to override the static version of the fsck root service file. */
r = generator_write_fsck_deps(f, arg_dest, what, where, fstype, opts_filtered);
if (r < 0)
return r;
@@ -382,25 +387,25 @@ static int add_mount(
return log_error_errno(r, "Failed to write unit %s: %m", unit);
if (FLAGS_SET(flags, MOUNT_VALIDATEFS)) {
r = generator_hook_up_validatefs(arg_dest, where, post);
r = generator_hook_up_validatefs(arg_dest_late, where, post);
if (r < 0)
return r;
}
if (FLAGS_SET(flags, MOUNT_GROWFS)) {
r = generator_hook_up_growfs(arg_dest, where, post);
r = generator_hook_up_growfs(arg_dest_late, where, post);
if (r < 0)
return r;
}
if (FLAGS_SET(flags, MOUNT_MEASURE)) {
r = generator_hook_up_pcrfs(arg_dest, where, post);
r = generator_hook_up_pcrfs(arg_dest_late, where, post);
if (r < 0)
return r;
}
if (post) {
r = generator_add_symlink(arg_dest, post, "requires", unit);
r = generator_add_symlink(arg_dest_late, post, "requires", unit);
if (r < 0)
return r;
}
@@ -514,7 +519,7 @@ static int add_partition_swap(DissectedPartition *p) {
if (r < 0)
return log_error_errno(r, "Failed to generate unit name: %m");
r = generator_open_unit_file(arg_dest, /* source = */ NULL, name, &f);
r = generator_open_unit_file(arg_dest_late, /* source = */ NULL, name, &f);
if (r < 0)
return r;
@@ -537,7 +542,7 @@ static int add_partition_swap(DissectedPartition *p) {
if (r < 0)
return log_error_errno(r, "Failed to write unit %s: %m", name);
return generator_add_symlink(arg_dest, SPECIAL_SWAP_TARGET, "wants", name);
return generator_add_symlink(arg_dest_late, SPECIAL_SWAP_TARGET, "wants", name);
}
static int add_automount(
@@ -573,7 +578,7 @@ static int add_automount(
if (r < 0)
return log_error_errno(r, "Failed to generate unit name: %m");
r = generator_open_unit_file(arg_dest, /* source = */ NULL, unit, &f);
r = generator_open_unit_file(arg_dest_late, /* source = */ NULL, unit, &f);
if (r < 0)
return r;
@@ -592,7 +597,7 @@ static int add_automount(
if (r < 0)
return log_error_errno(r, "Failed to write unit %s: %m", unit);
return generator_add_symlink(arg_dest, SPECIAL_LOCAL_FS_TARGET, "wants", unit);
return generator_add_symlink(arg_dest_late, SPECIAL_LOCAL_FS_TARGET, "wants", unit);
}
static int add_partition_xbootldr(DissectedPartition *p) {
@@ -715,11 +720,11 @@ static int add_partition_root_rw(DissectedPartition *p) {
return 0;
}
r = generator_enable_remount_fs_service(arg_dest);
r = generator_enable_remount_fs_service(arg_dest_late);
if (r < 0)
return r;
path = strjoina(arg_dest, "/systemd-remount-fs.service.d/50-remount-rw.conf");
path = strjoina(arg_dest_late, "/systemd-remount-fs.service.d/50-remount-rw.conf");
r = write_string_file(path,
"# Automatically generated by systemd-gpt-auto-generator\n\n"
@@ -744,7 +749,7 @@ static int add_partition_root_growfs(DissectedPartition *p) {
return 0;
}
return generator_hook_up_growfs(arg_dest, "/", SPECIAL_LOCAL_FS_TARGET);
return generator_hook_up_growfs(arg_dest_late, "/", SPECIAL_LOCAL_FS_TARGET);
}
static int add_partition_root_flags(DissectedPartition *p) {
@@ -852,7 +857,7 @@ static int add_root_mount(void) {
}
if (in_initrd()) {
r = generator_write_initrd_root_device_deps(arg_dest, bdev);
r = generator_write_initrd_root_device_deps(arg_dest_late, bdev);
if (r < 0)
return 0;
@@ -1282,7 +1287,8 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
static int run(const char *dest, const char *dest_early, const char *dest_late) {
int r;
assert_se(arg_dest = dest_late);
assert_se(arg_dest = dest);
assert_se(arg_dest_late = dest_late);
if (detect_container() > 0) {
log_debug("In a container, exiting.");