git: 99ff1bd55733 - stable/13 - nfscl: Do not call nfscl_hasexpired() for NFSv4.1/4.2

From: Rick Macklem <rmacklem_at_FreeBSD.org>
Date: Thu, 28 Jul 2022 20:20:29 UTC
The branch stable/13 has been updated by rmacklem:

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

commit 99ff1bd55733d8fd20f6b70922639fa25b434ce9
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2022-07-10 20:56:38 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2022-07-28 20:16:11 +0000

    nfscl: Do not call nfscl_hasexpired() for NFSv4.1/4.2
    
    Commit 981ef32230b2 enabled marking of potentially bad
    session slots when an RPC is interrupted if the "intr"
    mount option is used.  As such, it no longer makes
    sense to call nfscl_hasexpired() for I/O operations that
    reply NFSERR_BADSTATEID for NFSv4.1/4.2, which does a full
    recovery of NFSv4 open state, destroying all byte range locks.
    Recovery of open state should not be usually needed, since
    the session slot has been marked potentially bad and,
    although opens for the process that has been terminated via
    a signal may be broken, locks for other processes will still
    be valid.
    
    This patch disables calls to nfscl_hasexpired for NFSv4.1/4.2
    mounts, when I/O RPCs receive NFSERR_BADSTATEID replies.
    It does not affect the behaviour of NFSv4.0 mounts nor
    hard (non "intr") mounts.
    
    PR: 260011
    (cherry picked from commit 8f4a5fc6bc6c4e9e0739326199d73ee4401ebd58)
---
 sys/fs/nfsclient/nfs_clrpcops.c | 36 +++++++++++++++++++++++++++---------
 1 file changed, 27 insertions(+), 9 deletions(-)

diff --git a/sys/fs/nfsclient/nfs_clrpcops.c b/sys/fs/nfsclient/nfs_clrpcops.c
index 05e3ebe5114d..529655cfe5ca 100644
--- a/sys/fs/nfsclient/nfs_clrpcops.c
+++ b/sys/fs/nfsclient/nfs_clrpcops.c
@@ -1339,8 +1339,12 @@ nfsrpc_setattr(vnode_t vp, struct vattr *vap, NFSACL_T *aclp,
 		    error == NFSERR_OLDSTATEID || error == NFSERR_BADSESSION) {
 			(void) nfs_catnap(PZERO, error, "nfs_setattr");
 		} else if ((error == NFSERR_EXPIRED ||
-		    error == NFSERR_BADSTATEID) && clidrev != 0) {
+		    ((!NFSHASINT(nmp) || !NFSHASNFSV4N(nmp)) &&
+		    error == NFSERR_BADSTATEID)) && clidrev != 0) {
 			expireret = nfscl_hasexpired(nmp->nm_clp, clidrev, p);
+		} else if (error == NFSERR_BADSTATEID && NFSHASINT(nmp) &&
+		    NFSHASNFSV4N(nmp)) {
+			error = EIO;
 		}
 		retrycnt++;
 	} while (error == NFSERR_GRACE || error == NFSERR_STALESTATEID ||
@@ -1601,8 +1605,12 @@ nfsrpc_read(vnode_t vp, struct uio *uiop, struct ucred *cred,
 		    error == NFSERR_OLDSTATEID || error == NFSERR_BADSESSION) {
 			(void) nfs_catnap(PZERO, error, "nfs_read");
 		} else if ((error == NFSERR_EXPIRED ||
-		    error == NFSERR_BADSTATEID) && clidrev != 0) {
+		    ((!NFSHASINT(nmp) || !NFSHASNFSV4N(nmp)) &&
+		    error == NFSERR_BADSTATEID)) && clidrev != 0) {
 			expireret = nfscl_hasexpired(nmp->nm_clp, clidrev, p);
+		} else if (error == NFSERR_BADSTATEID && NFSHASINT(nmp) &&
+		    NFSHASNFSV4N(nmp)) {
+			error = EIO;
 		}
 		retrycnt++;
 	} while (error == NFSERR_GRACE || error == NFSERR_STALESTATEID ||
@@ -1773,8 +1781,12 @@ nfsrpc_write(vnode_t vp, struct uio *uiop, int *iomode, int *must_commit,
 		    error == NFSERR_OLDSTATEID || error == NFSERR_BADSESSION) {
 			(void) nfs_catnap(PZERO, error, "nfs_write");
 		} else if ((error == NFSERR_EXPIRED ||
-		    error == NFSERR_BADSTATEID) && clidrev != 0) {
+		    ((!NFSHASINT(nmp) || !NFSHASNFSV4N(nmp)) &&
+		    error == NFSERR_BADSTATEID)) && clidrev != 0) {
 			expireret = nfscl_hasexpired(nmp->nm_clp, clidrev, p);
+		} else if (error == NFSERR_BADSTATEID && NFSHASINT(nmp) &&
+		    NFSHASNFSV4N(nmp)) {
+			error = EIO;
 		}
 		retrycnt++;
 	} while (error == NFSERR_GRACE || error == NFSERR_DELAY ||
@@ -7186,9 +7198,11 @@ nfsrpc_allocate(vnode_t vp, off_t off, off_t len, struct nfsvattr *nap,
 		    error == NFSERR_STALEDONTRECOVER || error == NFSERR_DELAY ||
 		    error == NFSERR_OLDSTATEID || error == NFSERR_BADSESSION) {
 			(void) nfs_catnap(PZERO, error, "nfs_allocate");
-		} else if ((error == NFSERR_EXPIRED ||
-		    error == NFSERR_BADSTATEID) && clidrev != 0) {
+		} else if ((error == NFSERR_EXPIRED || (!NFSHASINT(nmp) &&
+		    error == NFSERR_BADSTATEID)) && clidrev != 0) {
 			expireret = nfscl_hasexpired(nmp->nm_clp, clidrev, p);
+		} else if (error == NFSERR_BADSTATEID && NFSHASINT(nmp)) {
+			error = EIO;
 		}
 		retrycnt++;
 	} while (error == NFSERR_GRACE || error == NFSERR_DELAY ||
@@ -8287,10 +8301,12 @@ nfsrpc_copy_file_range(vnode_t invp, off_t *inoffp, vnode_t outvp,
 		    error == NFSERR_STALEDONTRECOVER || error == NFSERR_DELAY ||
 		    error == NFSERR_OLDSTATEID || error == NFSERR_BADSESSION) {
 			(void) nfs_catnap(PZERO, error, "nfs_cfr");
-		} else if ((error == NFSERR_EXPIRED ||
-		    error == NFSERR_BADSTATEID) && clidrev != 0) {
+		} else if ((error == NFSERR_EXPIRED || (!NFSHASINT(nmp) &&
+		    error == NFSERR_BADSTATEID)) && clidrev != 0) {
 			expireret = nfscl_hasexpired(nmp->nm_clp, clidrev,
 			    curthread);
+		} else if (error == NFSERR_BADSTATEID && NFSHASINT(nmp)) {
+			error = EIO;
 		}
 		retrycnt++;
 	} while (error == NFSERR_GRACE || error == NFSERR_DELAY ||
@@ -8464,10 +8480,12 @@ nfsrpc_seek(vnode_t vp, off_t *offp, bool *eofp, int content,
 		    error == NFSERR_STALEDONTRECOVER || error == NFSERR_DELAY ||
 		    error == NFSERR_OLDSTATEID || error == NFSERR_BADSESSION) {
 			(void) nfs_catnap(PZERO, error, "nfs_seek");
-		} else if ((error == NFSERR_EXPIRED ||
-		    error == NFSERR_BADSTATEID) && clidrev != 0) {
+		} else if ((error == NFSERR_EXPIRED || (!NFSHASINT(nmp) &&
+		    error == NFSERR_BADSTATEID)) && clidrev != 0) {
 			expireret = nfscl_hasexpired(nmp->nm_clp, clidrev,
 			    curthread);
+		} else if (error == NFSERR_BADSTATEID && NFSHASINT(nmp)) {
+			error = EIO;
 		}
 		retrycnt++;
 	} while (error == NFSERR_GRACE || error == NFSERR_STALESTATEID ||