mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-11 05:17:44 +03:00
Implemented x-systemd.{required,wanted}-by= options
Teaches systemd-fstab-generator these two unit options, creating appropriate dependencies on the generated .mount units. When used, they override any other automatically generated dependencies, such as local-fs.target, and are NOT suppressed by noauto. The new options are ignored for /, in the same way that noauto is ignored. Fixes: #14380 Signed-off-by: Antonio Russo <antonio.e.russo@gmail.com>
This commit is contained in:
parent
81248e7f3e
commit
be02c1cf42
@ -226,6 +226,21 @@
|
||||
for details.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>x-systemd.wanted-by=</option></term>
|
||||
<term><option>x-systemd.required-by=</option></term>
|
||||
|
||||
<listitem><para>In the created mount unit, configures a
|
||||
<varname>WantedBy=</varname> or <varname>RequiredBy=</varname>
|
||||
dependency on another unit. This option may be
|
||||
specified more than once. If this is specified, the normal
|
||||
automatic dependencies on the created mount unit, e.g.,
|
||||
<filename>local-fs.target</filename>, are not automatically
|
||||
created. See <varname>WantedBy=</varname> and <varname>RequiredBy=</varname> in
|
||||
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
|
||||
for details.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>x-systemd.requires-mounts-for=</option></term>
|
||||
|
||||
|
@ -306,6 +306,7 @@ static int add_mount(
|
||||
*automount_name = NULL,
|
||||
*filtered = NULL,
|
||||
*where_escaped = NULL;
|
||||
_cleanup_strv_free_ char **wanted_by = NULL, **required_by = NULL;
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
int r;
|
||||
|
||||
@ -327,6 +328,14 @@ static int add_mount(
|
||||
mount_point_ignore(where))
|
||||
return 0;
|
||||
|
||||
r = fstab_extract_values(opts, "x-systemd.wanted-by", &wanted_by);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = fstab_extract_values(opts, "x-systemd.required-by", &required_by);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (path_equal(where, "/")) {
|
||||
if (flags & NOAUTO)
|
||||
log_warning("Ignoring \"noauto\" for root device");
|
||||
@ -334,7 +343,13 @@ static int add_mount(
|
||||
log_warning("Ignoring \"nofail\" for root device");
|
||||
if (flags & AUTOMOUNT)
|
||||
log_warning("Ignoring automount option for root device");
|
||||
if (!strv_isempty(wanted_by))
|
||||
log_warning("Ignoring \"x-systemd.wanted-by=\" for root device");
|
||||
if (!strv_isempty(required_by))
|
||||
log_warning("Ignoring \"x-systemd.required-by=\" for root device");
|
||||
|
||||
required_by = strv_free(required_by);
|
||||
wanted_by = strv_free(wanted_by);
|
||||
SET_FLAG(flags, NOAUTO | NOFAIL | AUTOMOUNT, false);
|
||||
}
|
||||
|
||||
@ -451,14 +466,28 @@ static int add_mount(
|
||||
return r;
|
||||
}
|
||||
|
||||
if (!(flags & NOAUTO) && !(flags & AUTOMOUNT)) {
|
||||
r = generator_add_symlink(dest, post,
|
||||
(flags & NOFAIL) ? "wants" : "requires", name);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
if (!FLAGS_SET(flags, AUTOMOUNT)) {
|
||||
if (!FLAGS_SET(flags, NOAUTO) && strv_isempty(wanted_by) && strv_isempty(required_by)) {
|
||||
r = generator_add_symlink(dest, post,
|
||||
(flags & NOFAIL) ? "wants" : "requires", name);
|
||||
if (r < 0)
|
||||
return r;
|
||||
} else {
|
||||
char **s;
|
||||
|
||||
if (flags & AUTOMOUNT) {
|
||||
STRV_FOREACH(s, wanted_by) {
|
||||
r = generator_add_symlink(dest, *s, "wants", name);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
STRV_FOREACH(s, required_by) {
|
||||
r = generator_add_symlink(dest, *s, "requires", name);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
r = unit_name_from_path(where, ".automount", &automount_name);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to generate unit name: %m");
|
||||
|
Loading…
Reference in New Issue
Block a user