fstab-generator: add x-systemd.mount-timeout (#4603)

This adds a new systemd fstab option x-systemd.mount-timeout. The option
adds a timeout value that specifies how long systemd waits for the mount
command to finish. It allows to mount huge btrfs volumes without issues.

This is equivalent to adding option TimeoutSec= to [Mount] section in a
mount unit file.

fixes #4055
This commit is contained in:
Christian Hesse 2016-11-11 15:08:57 +01:00 committed by Zbigniew Jędrzejewski-Szmek
parent 9f7672b3bc
commit 110773f6c9
2 changed files with 37 additions and 3 deletions

View File

@ -240,6 +240,25 @@
</listitem>
</varlistentry>
<varlistentry>
<term><option>x-systemd.mount-timeout=</option></term>
<listitem><para>Configure how long systemd should wait for the
mount command to finish before giving up on an entry from
<filename>/etc/fstab</filename>. Specify a time in seconds or
explicitly append a unit such as <literal>s</literal>,
<literal>min</literal>, <literal>h</literal>,
<literal>ms</literal>.</para>
<para>Note that this option can only be used in
<filename>/etc/fstab</filename>, and will be
ignored when part of the <varname>Options=</varname>
setting in a unit file.</para>
<para>See <varname>TimeoutSec=</varname> below for
details.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>noauto</option></term>
<term><option>auto</option></term>

View File

@ -141,13 +141,14 @@ static bool mount_in_initrd(struct mntent *me) {
streq(me->mnt_dir, "/usr");
}
static int write_idle_timeout(FILE *f, const char *where, const char *opts) {
static int write_timeout(FILE *f, const char *where, const char *opts,
const char *filter, const char *variable) {
_cleanup_free_ char *timeout = NULL;
char timespan[FORMAT_TIMESPAN_MAX];
usec_t u;
int r;
r = fstab_filter_options(opts, "x-systemd.idle-timeout\0", NULL, &timeout, NULL);
r = fstab_filter_options(opts, filter, NULL, &timeout, NULL);
if (r < 0)
return log_warning_errno(r, "Failed to parse options: %m");
if (r == 0)
@ -159,11 +160,21 @@ static int write_idle_timeout(FILE *f, const char *where, const char *opts) {
return 0;
}
fprintf(f, "TimeoutIdleSec=%s\n", format_timespan(timespan, sizeof(timespan), u, 0));
fprintf(f, "%s=%s\n", variable, format_timespan(timespan, sizeof(timespan), u, 0));
return 0;
}
static int write_idle_timeout(FILE *f, const char *where, const char *opts) {
return write_timeout(f, where, opts,
"x-systemd.idle-timeout\0", "TimeoutIdleSec");
}
static int write_mount_timeout(FILE *f, const char *where, const char *opts) {
return write_timeout(f, where, opts,
"x-systemd.mount-timeout\0", "TimeoutSec");
}
static int write_requires_after(FILE *f, const char *opts) {
_cleanup_strv_free_ char **names = NULL, **units = NULL;
_cleanup_free_ char *res = NULL;
@ -327,6 +338,10 @@ static int add_mount(
if (r < 0)
return r;
r = write_mount_timeout(f, where, opts);
if (r < 0)
return r;
if (!isempty(filtered) && !streq(filtered, "defaults"))
fprintf(f, "Options=%s\n", filtered);