git: 9f5457996e00 - stable/14 - nfscl: Move delegation high water variables into clientID

From: Rick Macklem <rmacklem_at_FreeBSD.org>
Date: Mon, 03 Mar 2025 01:55:21 UTC
The branch stable/14 has been updated by rmacklem:

URL: https://cgit.FreeBSD.org/src/commit/?id=9f5457996e005e12db7737bddaada55c83f55e6a

commit 9f5457996e005e12db7737bddaada55c83f55e6a
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2025-02-17 00:01:54 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2025-03-03 01:54:10 +0000

    nfscl: Move delegation high water variables into clientID
    
    Without this patch, the variables used to maintain a high
    water limit for delegations are global and apply to all
    mounts.  This patch moves them into the clientID structure,
    which makes them per mount.  This is needed to add support
    for the CB_RECALL_ANY callback in a future commit.
    
    The only effect of this patch is an increase in the
    total number of delegations held if there are multiple NFSv4
    mounts to NFSv4 servers with delegations enabled.
    Since the default of NFSCLDELEGHIGHWATER is fairly small,
    this should not have a significant impact.
    
    (cherry picked from commit f5aff1871d3273b3cd3621ea5d3e37cdd807e66f)
---
 sys/fs/nfs/nfsclstate.h        |  2 ++
 sys/fs/nfsclient/nfs_clstate.c | 15 ++++++++-------
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/sys/fs/nfs/nfsclstate.h b/sys/fs/nfs/nfsclstate.h
index d9f5ed13b54f..84088a2a4fd2 100644
--- a/sys/fs/nfs/nfsclstate.h
+++ b/sys/fs/nfs/nfsclstate.h
@@ -116,6 +116,8 @@ struct nfsclclient {
 	struct proc		*nfsc_renewthread;
 	struct nfsmount		*nfsc_nmp;
 	time_t			nfsc_expire;
+	int			nfsc_delegcnt;
+	int			nfsc_deleghighwater;
 	u_int32_t		nfsc_clientidrev;
 	u_int32_t		nfsc_rev;
 	u_int32_t		nfsc_renew;
diff --git a/sys/fs/nfsclient/nfs_clstate.c b/sys/fs/nfsclient/nfs_clstate.c
index e803c2cfb973..ad30a306c31d 100644
--- a/sys/fs/nfsclient/nfs_clstate.c
+++ b/sys/fs/nfsclient/nfs_clstate.c
@@ -94,8 +94,6 @@ NFSCLSTATEMUTEX;
 int nfscl_inited = 0;
 struct nfsclhead nfsclhead;	/* Head of clientid list */
 
-static int nfscl_deleghighwater = NFSCLDELEGHIGHWATER;
-static int nfscl_delegcnt = 0;
 static int nfscl_layoutcnt = 0;
 static int nfscl_getopen(struct nfsclownerhead *, struct nfsclopenhash *,
     u_int8_t *, int, u_int8_t *, u_int8_t *, u_int32_t,
@@ -463,7 +461,7 @@ nfscl_deleg(mount_t mp, struct nfsclclient *clp, u_int8_t *nfhp,
 		    nfsdl_hash);
 		dp->nfsdl_timestamp = NFSD_MONOSEC + 120;
 		nfsstatsv1.cldelegates++;
-		nfscl_delegcnt++;
+		clp->nfsc_delegcnt++;
 	} else {
 		/*
 		 * A delegation already exists.  If the new one is a Write
@@ -923,6 +921,8 @@ nfscl_getcl(struct mount *mp, struct ucred *cred, NFSPROC_T *p,
 		for (i = 0; i < NFSCLLAYOUTHASHSIZE; i++)
 			LIST_INIT(&clp->nfsc_layouthash[i]);
 		clp->nfsc_flags = NFSCLFLAGS_INITED;
+		clp->nfsc_delegcnt = 0;
+		clp->nfsc_deleghighwater = NFSCLDELEGHIGHWATER;
 		clp->nfsc_clientidrev = 1;
 		clp->nfsc_cbident = nfscl_nextcbident();
 		nfscl_fillclid(nmp->nm_clval, uuid, clp->nfsc_id,
@@ -1755,10 +1755,10 @@ nfscl_freedeleg(struct nfscldeleghead *hdp, struct nfscldeleg *dp, bool freeit)
 
 	TAILQ_REMOVE(hdp, dp, nfsdl_list);
 	LIST_REMOVE(dp, nfsdl_hash);
+	dp->nfsdl_clp->nfsc_delegcnt--;
 	if (freeit)
 		free(dp, M_NFSCLDELEG);
 	nfsstatsv1.cldelegates--;
-	nfscl_delegcnt--;
 }
 
 /*
@@ -2868,7 +2868,7 @@ tryagain:
 					nfsdl_list);
 				    LIST_REMOVE(dp, nfsdl_hash);
 				    TAILQ_INSERT_HEAD(&dh, dp, nfsdl_list);
-				    nfscl_delegcnt--;
+				    clp->nfsc_delegcnt--;
 				    nfsstatsv1.cldelegates--;
 				}
 				NFSLOCKCLSTATE();
@@ -2898,7 +2898,8 @@ tryagain:
 		 * The tailq list is in LRU order.
 		 */
 		dp = TAILQ_LAST(&clp->nfsc_deleg, nfscldeleghead);
-		while (nfscl_delegcnt > nfscl_deleghighwater && dp != NULL) {
+		while (clp->nfsc_delegcnt > clp->nfsc_deleghighwater &&
+		    dp != NULL) {
 		    ndp = TAILQ_PREV(dp, nfscldeleghead, nfsdl_list);
 		    if (dp->nfsdl_rwlock.nfslock_usecnt == 0 &&
 			dp->nfsdl_rwlock.nfslock_lock == 0 &&
@@ -2925,7 +2926,7 @@ tryagain:
 			    TAILQ_REMOVE(&clp->nfsc_deleg, dp, nfsdl_list);
 			    LIST_REMOVE(dp, nfsdl_hash);
 			    TAILQ_INSERT_HEAD(&dh, dp, nfsdl_list);
-			    nfscl_delegcnt--;
+			    clp->nfsc_delegcnt--;
 			    nfsstatsv1.cldelegates--;
 			}
 		    }