From: NeilBrown Date: Tue, 4 Jul 2017 07:47:40 +0000 (+1000) Subject: fstab-generator: handle NFS "bg" mounts correctly. (#6103) X-Git-Tag: v234~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=65e1dee7dcf1668c25c32f0238c935708dbffbcf;p=thirdparty%2Fsystemd.git fstab-generator: handle NFS "bg" mounts correctly. (#6103) When "bg" is specified for NFS mounts, and if the server is not accessible, two behaviors are possible depending on networking details. If a definitive error is received, such a EHOSTUNREACH or ECONNREFUSED, mount.nfs will fork and continue in the background, while /bin/mount will report success. If no definitive error is reported but the connection times out instead, then the mount.nfs timeout will normally be longer than the systemd.mount timeout, so mount.nfs will be killed by systemd. In the first case the mount has appeared to succeed even though it hasn't. This can be confusing. Also the background mount.nfs will never get cleaned up, even if the mount unit is stopped. In the second case, mount.nfs is killed early and so the mount will not complete when the server comes back. Neither of these are ideal. This patch modifies the options when an NFS bg mount is detected to force an "fg" mount, but retain the default "retry" time of 10000 minutes that applies to "bg" mounts. It also imposes "nofail" behaviour and sets the TimeoutSec for the mount to "infinity" so the retry= time is allowed to complete. This provides near-identical behaviour to an NFS bg mount started directly by "mount -a". The only difference is that systemd will not wait for the first mount attempt, while "mount -a" will. Fixes #6046 --- diff --git a/man/systemd.mount.xml b/man/systemd.mount.xml index b4e2c79bdeb..98f71d2e7e5 100644 --- a/man/systemd.mount.xml +++ b/man/systemd.mount.xml @@ -161,8 +161,15 @@ The NFS mount option for NFS background mounts as documented in nfs5 - is not supported in /etc/fstab entries. The systemd mount option - provides similar functionality and should be used instead. + is detected by systemd-fstab-generator and the options + are transformed so that systemd fulfills the job-control implications of + that option. Specifically systemd-fstab-generator acts + as though x-systemd.mount-timout=infinity,retry=10000 was + prepended to the option list, and fg,nofail was appended. + Depending on specific requirements, it may be appropriate to provide some of + these options explicitly, or to make use of the + x-systemd.automount option described below instead + of using bg. When reading /etc/fstab a few special mount options are understood by systemd which influence how diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 0bbc6c71bc2..7688a75f125 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -358,6 +358,20 @@ static int add_mount( "Documentation=man:fstab(5) man:systemd-fstab-generator(8)\n", source); + if (STR_IN_SET(fstype, "nfs", "nfs4") && !automount && + fstab_test_yes_no_option(opts, "bg\0" "fg\0")) { + /* The default retry timeout that mount.nfs uses for 'bg' mounts + * is 10000 minutes, where as it uses 2 minutes for 'fg' mounts. + * As we are making 'bg' mounts look like an 'fg' mount to + * mount.nfs (so systemd can manage the job-control aspects of 'bg'), + * we need to explicitly preserve that default, and also ensure + * the systemd mount-timeout doesn't interfere. + * By placing these options first, they can be over-ridden by + * settings in /etc/fstab. */ + opts = strjoina("x-systemd.mount-timeout=infinity,retry=10000,", opts, ",fg"); + nofail = true; + } + if (!nofail && !automount) fprintf(f, "Before=%s\n", post);