git: 6ff42c4fafb7 - stable/14 - nfscl: Add support for CB_RECALL_ANY to the NFSv4.1/4.2 client

From: Rick Macklem <rmacklem_at_FreeBSD.org>
Date: Tue, 04 Mar 2025 02:21:36 UTC
The branch stable/14 has been updated by rmacklem:

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

commit 6ff42c4fafb7684805f1a756c345fcbf1a29c993
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2025-02-18 22:34:12 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2025-03-04 02:20:46 +0000

    nfscl: Add support for CB_RECALL_ANY to the NFSv4.1/4.2 client
    
    Commit f5aff1871d32 and 7e26f1c21049 moved the delegation
    and layout high water variables into the clientID structure.
    This patch uses those variables to implement the
    CB_RECALL_ANY NFSv4.1/4.2 callback.
    
    This patch only affects NFSv4.1/4.2 mounts to non-FreeBSD
    NFS servers that use CB_RECALL_ANY.  The Linux knfsd is
    one example of such a server.
    
    (cherry picked from commit 8dc0889f56dd6ac5c33ce79337a971af4b9ff127)
---
 sys/fs/nfs/nfsproto.h          | 11 +++++++++++
 sys/fs/nfsclient/nfs_clstate.c | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/sys/fs/nfs/nfsproto.h b/sys/fs/nfs/nfsproto.h
index 323746ebbb6c..995754f42b15 100644
--- a/sys/fs/nfs/nfsproto.h
+++ b/sys/fs/nfs/nfsproto.h
@@ -744,6 +744,17 @@
 #define	NFSSECINFONONAME_CURFH	0
 #define	NFSSECINFONONAME_PARENT	1
 
+/* Bits for CB_RECALL_ANY. */
+#define	NFSRCA4_RDATA_DLG	0x00000001
+#define	NFSRCA4_WDATA_DLG	0x00000002
+#define	NFSRCA4_DIR_DLG		0x00000004
+#define	NFSRCA4_FILE_LAYOUT	0x00000008
+#define	NFSRCA4_BLK_LAYOUT	0x00000010
+#define	NFSRCA4_OBJ_LAYOUT_MIN	0x00000100
+#define	NFSRCA4_OBJ_LAYOUT_MAX	0x00000200
+#define	NFSRCA4_FF_LAYOUT_READ	0x00010000
+#define	NFSRCA4_FF_LAYOUT_RW	0x00020000
+
 #if defined(_KERNEL) || defined(KERNEL)
 /* Conversion macros */
 #define	vtonfsv2_mode(t,m) 						\
diff --git a/sys/fs/nfsclient/nfs_clstate.c b/sys/fs/nfsclient/nfs_clstate.c
index 12894e3dcb84..b00de78ef591 100644
--- a/sys/fs/nfsclient/nfs_clstate.c
+++ b/sys/fs/nfsclient/nfs_clstate.c
@@ -3959,6 +3959,40 @@ nfscl_docb(struct nfsrv_descript *nd, NFSPROC_T *p)
 			}
 			NFSUNLOCKCLSTATE();
 			break;
+		case NFSV4OP_CBRECALLANY:
+			NFSM_DISSECT(tl, uint32_t *, 2 * NFSX_UNSIGNED);
+			i = fxdr_unsigned(int, *tl++);
+			j = fxdr_unsigned(int, *tl);
+			if (i < 0 || j != 1)
+				error = NFSERR_BADXDR;
+			if (error == 0) {
+				NFSM_DISSECT(tl, uint32_t *, NFSX_UNSIGNED);
+				j = fxdr_unsigned(int, *tl);
+				if (i < 100)
+					i = 100;
+				else if (i > 100000)
+					i = 100000;
+				NFSLOCKCLSTATE();
+				clp = nfscl_getclntsess(sessionid);
+				if (clp == NULL)
+					error = NFSERR_SERVERFAULT;
+				if (((j & NFSRCA4_RDATA_DLG) != 0 ||
+				    (j & NFSRCA4_WDATA_DLG) != 0) &&
+				    error == 0 && i <
+				    clp->nfsc_deleghighwater)
+					clp->nfsc_deleghighwater = i;
+				if (error == 0 &&
+				    ((!NFSHASFLEXFILE(clp->nfsc_nmp) &&
+				     (j & NFSRCA4_FILE_LAYOUT) != 0 &&
+				     i < clp->nfsc_layouthighwater) ||
+				     (NFSHASFLEXFILE(clp->nfsc_nmp) &&
+				     (j & (NFSRCA4_FF_LAYOUT_READ |
+				     NFSRCA4_FF_LAYOUT_RW)) != 0 &&
+				     i < clp->nfsc_layouthighwater)))
+					clp->nfsc_layouthighwater = i;
+				NFSUNLOCKCLSTATE();
+			}
+			break;
 		default:
 			if (i == 0 && minorvers != NFSV4_MINORVERSION)
 				error = NFSERR_OPNOTINSESS;