[systemd-devel] [PATCH 4/4] mount: Add a new remote-fs* target to delay logins until home dirs are available
Colin Guthrie
colin at mageia.org
Mon Jul 2 01:15:55 PDT 2012
Previously, systemd-user-sessions.service started after remote-fs.target.
If the user had any NFS mounts defined, this prevented logins until these
were processed.
If the user was using NFS for their home directories, this configuration
makes sense, but equally, the user may have remote mounts defined that
are non-critical for logins and thus shouldn't delay login availability.
Even using the "nofail" mount option does not help as
systemd-user-sessions.service will still wait for remote-fs.target which
although it does not require units, it does still have to run, thus it
will wait for remote-fs-pre.target which in turn will wait for the
network to be ready. All these things will delay the startup.
Therefore, rather than start after remote-fs.target directly, instead
provide an more granular remote-fs-login.target that will only have
dependances of fstab entries not marked with nofail.
Thus if an NFS mount is not critical for logins, it should be marked
with nofail mount option and it will not delay the login availability.
---
Makefile.am | 1 +
man/systemd.special.xml | 19 +++++++++++++++++++
src/core/special.h | 1 +
src/fstab-generator/fstab-generator.c | 12 +++++++++++-
units/remote-fs-login.target | 9 +++++++++
units/systemd-user-sessions.service.in | 2 +-
6 files changed, 42 insertions(+), 2 deletions(-)
create mode 100644 units/remote-fs-login.target
diff --git a/Makefile.am b/Makefile.am
index 5789a13..2650f00 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -269,6 +269,7 @@ dist_systemunit_DATA = \
units/local-fs.target \
units/local-fs-pre.target \
units/remote-fs.target \
+ units/remote-fs-login.target \
units/remote-fs-pre.target \
units/network.target \
units/nss-lookup.target \
diff --git a/man/systemd.special.xml b/man/systemd.special.xml
index 6df89d0..361744e 100644
--- a/man/systemd.special.xml
+++ b/man/systemd.special.xml
@@ -78,6 +78,7 @@
<filename>reboot.target</filename>,
<filename>remote-fs.target</filename>,
<filename>remote-fs-pre.target</filename>,
+ <filename>remote-fs-login.target</filename>,
<filename>rescue.target</filename>,
<filename>rpcbind.target</filename>,
<filename>runlevel2.target</filename>,
@@ -533,6 +534,24 @@
</listitem>
</varlistentry>
<varlistentry>
+ <term><filename>remote-fs-login.target</filename></term>
+ <listitem>
+ <para>Similar to
+ <filename>remote-fs.target</filename>,
+ but only for remote mount points marked
+ without <option>nofail</option>.
+ Remote mounts with nofail are
+ considered to be non-critical to
+ the login process. If any such mount
+ points exist, remote-fs.target will
+ automatically require in this target.
+ systemd-user-sessions.service is ordered
+ after this target, thus ensuring logins
+ are only available when all (required)
+ remote mounts are ready.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
<term><filename>rescue.target</filename></term>
<listitem>
<para>A special target unit
diff --git a/src/core/special.h b/src/core/special.h
index f71f076..2486238 100644
--- a/src/core/special.h
+++ b/src/core/special.h
@@ -49,6 +49,7 @@
#define SPECIAL_LOCAL_FS_TARGET "local-fs.target" /* LSB's $local_fs */
#define SPECIAL_LOCAL_FS_PRE_TARGET "local-fs-pre.target"
#define SPECIAL_REMOTE_FS_TARGET "remote-fs.target" /* LSB's $remote_fs */
+#define SPECIAL_REMOTE_FS_LOGIN_TARGET "remote-fs-login.target"
#define SPECIAL_REMOTE_FS_PRE_TARGET "remote-fs-pre.target"
#define SPECIAL_SWAP_TARGET "swap.target"
#define SPECIAL_BASIC_TARGET "basic.target"
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index f832730..23d087b 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -219,7 +219,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
FILE *f = NULL;
bool noauto, nofail, automount, isbind, isnetwork;
int r;
- const char *post, *pre;
+ const char *post, *pre, *login = NULL;
assert(what);
assert(where);
@@ -249,6 +249,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
if (isnetwork) {
post = SPECIAL_REMOTE_FS_TARGET;
pre = SPECIAL_REMOTE_FS_PRE_TARGET;
+ login = SPECIAL_REMOTE_FS_LOGIN_TARGET;
} else {
post = SPECIAL_LOCAL_FS_TARGET;
pre = SPECIAL_LOCAL_FS_PRE_TARGET;
@@ -295,6 +296,15 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
"Before=%s\n",
post);
+ if (login && !nofail)
+ /* This is a network mount without nofail option, therefore
+ hold up logins */
+ fprintf(f,
+ "Before=%s\n"
+ "Wants=%s\n",
+ login,
+ login);
+
fprintf(f,
"\n"
"[Mount]\n"
diff --git a/units/remote-fs-login.target b/units/remote-fs-login.target
new file mode 100644
index 0000000..5e6b63c
--- /dev/null
+++ b/units/remote-fs-login.target
@@ -0,0 +1,9 @@
+# This file is part of systemd.
+#
+# systemd is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+[Unit]
+Description=Remote File Systems needed for Logins
diff --git a/units/systemd-user-sessions.service.in b/units/systemd-user-sessions.service.in
index 0869e73..0343f19 100644
--- a/units/systemd-user-sessions.service.in
+++ b/units/systemd-user-sessions.service.in
@@ -8,7 +8,7 @@
[Unit]
Description=Permit User Sessions
Documentation=man:systemd-user-sessions.service(8)
-After=remote-fs.target
+After=remote-fs-login.target
[Service]
Type=oneshot
--
1.7.11
More information about the systemd-devel
mailing list