git: 62db233e1fd2 - stable/12 - mount_nfs: Add a "bgnow" NFS mount option

From: Rick Macklem <rmacklem_at_FreeBSD.org>
Date: Thu, 27 Jan 2022 00:14:32 UTC
The branch stable/12 has been updated by rmacklem:

URL: https://cgit.FreeBSD.org/src/commit/?id=62db233e1fd23827fa90527ac90c4d98c9644ef5

commit 62db233e1fd23827fa90527ac90c4d98c9644ef5
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2022-01-11 16:20:01 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2022-01-27 00:13:15 +0000

    mount_nfs: Add a "bgnow" NFS mount option
    
    The "bg" option does not go background until the initial mount
    attempt fails, which can take 60+ seconds.
    
    This new "bgnow" option goes background immediately, avoiding
    the 60+ second delay, if the NFS server is not yet available.
    
    The man page update is a content change.
    
    PR:             260764
    
    (cherry picked from commit 08a8d16cbb269d4c2be02eb67351c59d16f4ecb9)
---
 sbin/mount_nfs/mount_nfs.8 | 14 +++++++++++++-
 sbin/mount_nfs/mount_nfs.c | 23 +++++++++++++++++++----
 2 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/sbin/mount_nfs/mount_nfs.8 b/sbin/mount_nfs/mount_nfs.8
index 41fc8310fa84..3d881a24e84a 100644
--- a/sbin/mount_nfs/mount_nfs.8
+++ b/sbin/mount_nfs/mount_nfs.8
@@ -28,7 +28,7 @@
 .\"	@(#)mount_nfs.8	8.3 (Berkeley) 3/29/95
 .\" $FreeBSD$
 .\"
-.Dd January 17, 2021
+.Dd January 11, 2022
 .Dt MOUNT_NFS 8
 .Os
 .Sh NAME
@@ -127,6 +127,18 @@ trying the mount in the background.
 Useful for
 .Xr fstab 5 ,
 where the file system mount is not critical to multiuser operation.
+.It Cm bgnow
+Like
+.Cm bg ,
+fork off a child to keep trying the mount in the background,
+but do not attempt to mount in the foreground first.
+This eliminates a
+60+ second timeout when the server is not responding.
+Useful for speeding up the boot process of a client when the server is
+likely to be unavailable.
+This is often the case for interdependent servers
+such as cross-mounted servers (each of two servers is an NFS client of
+the other) and for cluster nodes that must boot before the file servers.
 .It Cm deadthresh Ns = Ns Aq Ar value
 Set the
 .Dq "dead server threshold"
diff --git a/sbin/mount_nfs/mount_nfs.c b/sbin/mount_nfs/mount_nfs.c
index 473370ee0209..78ebf6269062 100644
--- a/sbin/mount_nfs/mount_nfs.c
+++ b/sbin/mount_nfs/mount_nfs.c
@@ -100,10 +100,11 @@ struct nfhret {
 	long		fhsize;
 	u_char		nfh[NFS3_FHSIZE];
 };
-#define	BGRND	1
-#define	ISBGRND	2
-#define	OF_NOINET4	4
-#define	OF_NOINET6	8
+#define	BGRND		0x01
+#define	ISBGRND		0x02
+#define	OF_NOINET4	0x04
+#define	OF_NOINET6	0x08
+#define	BGRNDNOW	0x10
 static int retrycnt = -1;
 static int opflags = 0;
 static int nfsproto = IPPROTO_TCP;
@@ -239,6 +240,9 @@ main(int argc, char *argv[])
 				if (strcmp(opt, "bg") == 0) {
 					opflags |= BGRND;
 					pass_flag_to_nmount=0;
+				} else if (strcmp(opt, "bgnow") == 0) {
+					opflags |= BGRNDNOW;
+					pass_flag_to_nmount=0;
 				} else if (strcmp(opt, "fg") == 0) {
 					/* same as not specifying -o bg */
 					pass_flag_to_nmount=0;
@@ -418,6 +422,9 @@ main(int argc, char *argv[])
 	argc -= optind;
 	argv += optind;
 
+	if ((opflags & (BGRND | BGRNDNOW)) == (BGRND | BGRNDNOW))
+		errx(1, "Options bg and bgnow are mutually exclusive");
+
 	if (argc != 2) {
 		usage();
 		/* NOTREACHED */
@@ -588,6 +595,14 @@ getnfsargs(char *spec, struct iovec **iov, int *iovlen)
 		}
 	}
 
+	if ((opflags & (BGRNDNOW | ISBGRND)) == BGRNDNOW) {
+		warnx("Mount %s:%s, backgrounding",
+		    hostp, spec);
+		opflags |= ISBGRND;
+		if (daemon(0, 0) != 0)
+			err(1, "daemon");
+	}
+
 	ret = TRYRET_LOCALERR;
 	for (;;) {
 		/*