git: f115e0e9e319 - stable/13 - nfscl: Fix setting of nfsess_defunct for nfscl_hasexpired()

From: Rick Macklem <rmacklem_at_FreeBSD.org>
Date: Sat, 23 Jul 2022 20:41:33 UTC
The branch stable/13 has been updated by rmacklem:

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

commit f115e0e9e3198da0f21a0cb32bee966a27181c8d
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2022-07-08 14:37:36 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2022-07-23 20:38:21 +0000

    nfscl: Fix setting of nfsess_defunct for nfscl_hasexpired()
    
    Commit a7bb120f8b87 added a printf for the case where recovery
    has not marked the session defunct by setting nfsess_defunct
    to 1.  It turns out that nfscl_hasexpired() calls
    nfsrpc_setclient() directly, without setting nfsess_defunct.
    This patch replaces the printf with code that sets
    nfsess_defunct to 1 to handle this case.
    
    If SIGTERM is issued to a process when it is doing I/O on
    an "intr" mount, the NFSv4 server may reply NFSERR_BADSTATEID,
    due to the Open being prematurely closed.
    This can result in a call to nfscl_hasexpired() to do a
    recovery.
    
    This would explain at least one hang described in the PR.
    
    PR: 260011
    MFC after:      2 weeks
    
    (cherry picked from commit be7b87de16ffbabb81989e13a4b19a178e3ab8ee)
---
 sys/fs/nfsclient/nfs_clrpcops.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/sys/fs/nfsclient/nfs_clrpcops.c b/sys/fs/nfsclient/nfs_clrpcops.c
index eac6c777324a..fbca55027807 100644
--- a/sys/fs/nfsclient/nfs_clrpcops.c
+++ b/sys/fs/nfsclient/nfs_clrpcops.c
@@ -1061,10 +1061,12 @@ nfsrpc_setclient(struct nfsmount *nmp, struct nfsclclient *clp, int reclaim,
 			 */
 			tsep = NULL;
 			if (TAILQ_FIRST(&nmp->nm_sess) != NULL) {
+				/*
+				 * Mark the old session defunct.  Needed
+				 * when called from nfscl_hasexpired().
+				 */
 				tsep = NFSMNT_MDSSESSION(nmp);
-				if (tsep->nfsess_defunct == 0)
-					printf("nfsrpc_setclient: "
-					    "nfsess_defunct not set\n");
+				tsep->nfsess_defunct = 1;
 			}
 			TAILQ_INSERT_HEAD(&nmp->nm_sess, dsp,
 			    nfsclds_list);