git: d00c64bb2347 - main - nfscl: Purge name cache when readdir_plus is done

From: Rick Macklem <rmacklem_at_FreeBSD.org>
Date: Thu, 11 Apr 2024 20:31:39 UTC
The branch main has been updated by rmacklem:

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

commit d00c64bb2347cc620d31a178c7755aa7e594f065
Author:     Zaphrod Beeblebrox <zbeeble@gmail.com>
AuthorDate: 2024-04-11 20:27:27 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2024-04-11 20:27:27 +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.
    
    MFC after:      1 week
---
 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.
 	 */