git: 40631b79b5fe - stable/14 - nfscl: Purge name cache when readdir_plus is done

From: Rick Macklem <rmacklem_at_FreeBSD.org>
Date: Thu, 18 Apr 2024 00:50:37 UTC
The branch stable/14 has been updated by rmacklem:

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

commit 40631b79b5fedc53045c98eccb0e38e6c3d27ba8
Author:     Zaphrod Beeblebrox <zbeeble@gmail.com>
AuthorDate: 2024-04-11 20:27:27 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2024-04-18 00:49:10 +0000

    nfscl: Purge name cache when readdir_plus is done
    
    The author reported that this patch was needed to avoid
    crashes on a fairly busy RISC-V system.  The author did not
    provide details w.r.t. the crashes.  Although I
    have not seen any such crash, the patch looks reasonable
    and I have not found any regressions when testing it.
    
    Since "rdirplus" is not a default option, the patch is
    only needed if you are doing NFS mounts with the "rdirplus"
    mount option and seeing crashes related to the name cache.
    
    (cherry picked from commit d00c64bb2347cc620d31a178c7755aa7e594f065)
---
 sys/fs/nfsclient/nfs_clvnops.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/sys/fs/nfsclient/nfs_clvnops.c b/sys/fs/nfsclient/nfs_clvnops.c
index 0b8c587a542c..85c0ebd7a10f 100644
--- a/sys/fs/nfsclient/nfs_clvnops.c
+++ b/sys/fs/nfsclient/nfs_clvnops.c
@@ -2459,6 +2459,16 @@ nfs_readdir(struct vop_readdir_args *ap)
 		return (EINVAL);
 	uio->uio_resid -= left;
 
+	/*
+	 * For readdirplus, if starting to read the directory,
+	 * purge the name cache, since it will be reloaded by
+	 * this directory read.
+	 * This removes potentially stale name cache entries.
+	 */
+	if (uio->uio_offset == 0 &&
+	    (VFSTONFS(vp->v_mount)->nm_flag & NFSMNT_RDIRPLUS) != 0)
+		cache_purge(vp);
+
 	/*
 	 * Call ncl_bioread() to do the real work.
 	 */