git: 84de8c51d1a0 - main - nfsd: Add vfs.nfsd.testing_disable_grace sysctl

From: Rick Macklem <rmacklem_at_FreeBSD.org>
Date: Fri, 10 Jan 2025 14:50:45 UTC
The branch main has been updated by rmacklem:

URL: https://cgit.FreeBSD.org/src/commit/?id=84de8c51d1a0fff1c65cd1ec44dd3c3a0e7904eb

commit 84de8c51d1a0fff1c65cd1ec44dd3c3a0e7904eb
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2025-01-10 14:49:45 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2025-01-10 14:49:45 +0000

    nfsd: Add vfs.nfsd.testing_disable_grace sysctl
    
    The grace time of 2 minutes plus when the nfsd is started
    is needed for normal operation.  It allows client(s) to
    recovery open/lock state.  However, for testing situations
    where there are no client(s) to recover state, it introduces
    an unacceptable delay.
    
    The new per-vnet jail sysctl can be set non-zero to disable
    the grace period.  It should only be used for testing and
    can be applied on a per-jail basis.  It must be set before
    the nfsd is started up.
    
    Requested by:   asomers
    Tested by:      asomers
---
 sys/fs/nfsserver/nfs_nfsdstate.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/sys/fs/nfsserver/nfs_nfsdstate.c b/sys/fs/nfsserver/nfs_nfsdstate.c
index 6cd8c1c861ec..d1639f48451c 100644
--- a/sys/fs/nfsserver/nfs_nfsdstate.c
+++ b/sys/fs/nfsserver/nfs_nfsdstate.c
@@ -115,6 +115,11 @@ SYSCTL_INT(_vfs_nfsd, OID_AUTO, flexlinuxhack, CTLFLAG_RW,
     &nfsrv_flexlinuxhack, 0,
     "For Linux clients, hack around Flex File Layout bug");
 
+NFSD_VNET_DEFINE_STATIC(bool, nfsd_disable_grace) = false;
+SYSCTL_BOOL(_vfs_nfsd, OID_AUTO, testing_disable_grace,
+    CTLFLAG_NFSD_VNET | CTLFLAG_RW, &NFSD_VNET_NAME(nfsd_disable_grace),
+    0, "Disable grace for testing");
+
 /*
  * Hash lists for nfs V4.
  */
@@ -4381,11 +4386,13 @@ nfsrv_checkgrace(struct nfsrv_descript *nd, struct nfsclient *clp,
 		 * ReclaimComplete.  If so, grace can end now.
 		 */
 		notreclaimed = 0;
-		LIST_FOREACH(sp, &NFSD_VNET(nfsrv_stablefirst).nsf_head,
-		    nst_list) {
-			if ((sp->nst_flag & NFSNST_RECLAIMED) == 0) {
-				notreclaimed = 1;
-				break;
+		if (!NFSD_VNET(nfsd_disable_grace)) {
+			LIST_FOREACH(sp, &NFSD_VNET(nfsrv_stablefirst).nsf_head,
+			    nst_list) {
+				if ((sp->nst_flag & NFSNST_RECLAIMED) == 0) {
+					notreclaimed = 1;
+					break;
+				}
 			}
 		}
 		if (notreclaimed == 0)