diff --git a/sbin/mount_nfs/mount_nfs.8.sav b/sbin/mount_nfs/mount_nfs.8 --- a/sbin/mount_nfs/mount_nfs.8.sav +++ b/sbin/mount_nfs/mount_nfs.8 @@ -28,7 +28,7 @@ .\" @(#)mount_nfs.8 8.3 (Berkeley) 3/29/95 .\" $FreeBSD$ .\" -.Dd July 10, 2021 +.Dd January 3, 2022 .Dt MOUNT_NFS 8 .Os .Sh NAME @@ -129,6 +129,18 @@ 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.sav b/sbin/mount_nfs/mount_nfs.c --- a/sbin/mount_nfs/mount_nfs.c.sav +++ b/sbin/mount_nfs/mount_nfs.c @@ -107,6 +107,7 @@ #define ISBGRND 2 #define OF_NOINET4 4 #define OF_NOINET6 8 +#define BGRNDNOW 0x10 static int retrycnt = -1; static int opflags = 0; static int nfsproto = IPPROTO_TCP; @@ -242,6 +243,9 @@ 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; @@ -421,6 +425,9 @@ argc -= optind; argv += optind; + if ((opflags & (BGRND | BGRNDNOW)) == (BGRND | BGRNDNOW)) + errx(1, "Options bg and bgnow mutually exclusive"); + if (argc != 2) { usage(); /* NOTREACHED */ @@ -647,6 +654,14 @@ build_iovec(iov, iovlen, "principal", pname, strlen(pname) + 1); } + } + + 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;