fstab-generator: support for x-systemd.onfailure (#42440)
1. test-fstab-generator: fix inverted /mnt symlink guard The test-18-options.fstab.input scenario was guarded by a check that was always true on a normal system, so it was silently skipped and its fixtures had drifted out of sync with actual generator output. This commit fixes the guard and repairs the stale fixtures it exposed. 2. fstab-generator: support for x-systemd.onfailure Add support for the x-systemd.onfailure= fstab option in systemd-fstab-generator. This allows configuring OnFailure= dependencies for generated mount units directly through /etc/fstab. For example: /dev/sda1 /data ext4 defaults,x-systemd.onfailure=emergency.target 0 2 results in the generated mount unit containing: [Unit] OnFailure=emergency.target This makes it possible to attach recovery targets or services to mount failures directly from fstab configuration. Add documentation and generator tests.
This commit is contained in:
@@ -341,6 +341,7 @@ static int write_dependency(
|
||||
const char *where,
|
||||
const char *opts,
|
||||
const char *filter,
|
||||
const char *suffix,
|
||||
const char* const *unit_settings) {
|
||||
|
||||
_cleanup_strv_free_ char **unit_names = NULL;
|
||||
@@ -360,7 +361,9 @@ static int write_dependency(
|
||||
STRV_FOREACH(s, unit_names) {
|
||||
_cleanup_free_ char *mangled = NULL;
|
||||
|
||||
r = unit_name_mangle_with_suffix(*s, "as dependency", 0, ".mount", &mangled);
|
||||
r = suffix ?
|
||||
unit_name_mangle_with_suffix(*s, "as dependency", 0, suffix, &mangled) :
|
||||
unit_name_mangle(*s, 0, &mangled);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to generate dependency unit name for '%s': %m", where);
|
||||
|
||||
@@ -376,22 +379,24 @@ static int write_dependency(
|
||||
|
||||
static int write_after(FILE *f, const char *where, const char *opts) {
|
||||
return write_dependency(f, where, opts,
|
||||
"x-systemd.after\0", STRV_MAKE_CONST("After"));
|
||||
"x-systemd.after\0", /* suffix= */ ".mount", STRV_MAKE_CONST("After"));
|
||||
}
|
||||
|
||||
static int write_requires_after(FILE *f, const char *where, const char *opts) {
|
||||
return write_dependency(f, where, opts,
|
||||
"x-systemd.requires\0", STRV_MAKE_CONST("Requires", "After"));
|
||||
"x-systemd.requires\0", /* suffix= */ ".mount",
|
||||
STRV_MAKE_CONST("Requires", "After"));
|
||||
}
|
||||
|
||||
static int write_wants_after(FILE *f, const char *where, const char *opts) {
|
||||
return write_dependency(f, where, opts,
|
||||
"x-systemd.wants\0", STRV_MAKE_CONST("Wants", "After"));
|
||||
"x-systemd.wants\0", /* suffix= */ ".mount",
|
||||
STRV_MAKE_CONST("Wants", "After"));
|
||||
}
|
||||
|
||||
static int write_before(FILE *f, const char *where, const char *opts) {
|
||||
return write_dependency(f, where, opts,
|
||||
"x-systemd.before\0", STRV_MAKE_CONST("Before"));
|
||||
"x-systemd.before\0", /* suffix= */ ".mount", STRV_MAKE_CONST("Before"));
|
||||
}
|
||||
|
||||
static int write_mounts_for(
|
||||
@@ -426,6 +431,11 @@ static int write_mounts_for(
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int write_on_failure(FILE *f, const char *where, const char *opts) {
|
||||
return write_dependency(f, where, opts,
|
||||
"x-systemd.onfailure\0", /* suffix= */ NULL, STRV_MAKE_CONST("OnFailure"));
|
||||
}
|
||||
|
||||
static int write_extra_dependencies(FILE *f, const char *where, const char *opts) {
|
||||
int r;
|
||||
|
||||
@@ -460,6 +470,10 @@ static int write_extra_dependencies(FILE *f, const char *where, const char *opts
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = write_on_failure(f, where, opts);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user