git: 3ba93b50d6fa - stable/14 - nullfs: Add the vfs.nullfs.cache_nodes sysctl to control nocache default

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Thu, 14 Mar 2024 00:45:58 UTC
The branch stable/14 has been updated by kib:

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

commit 3ba93b50d6fa7733dd80158f162faf33a216b5b0
Author:     Seigo Tanimura <seigo.tanimura@gmail.com>
AuthorDate: 2024-03-04 13:50:25 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-03-13 00:30:40 +0000

    nullfs: Add the vfs.nullfs.cache_nodes sysctl to control nocache default
    
    (cherry picked from commit c849eb8f1925f95ebfb8dbbe00672d902486a973)
---
 sys/fs/nullfs/null_vfsops.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/sys/fs/nullfs/null_vfsops.c b/sys/fs/nullfs/null_vfsops.c
index 6acff89189f5..9d4a9588fed9 100644
--- a/sys/fs/nullfs/null_vfsops.c
+++ b/sys/fs/nullfs/null_vfsops.c
@@ -50,6 +50,7 @@
 #include <sys/mount.h>
 #include <sys/namei.h>
 #include <sys/proc.h>
+#include <sys/sysctl.h>
 #include <sys/vnode.h>
 #include <sys/jail.h>
 
@@ -67,6 +68,13 @@ static vfs_unmount_t	nullfs_unmount;
 static vfs_vget_t	nullfs_vget;
 static vfs_extattrctl_t	nullfs_extattrctl;
 
+SYSCTL_NODE(_vfs, OID_AUTO, nullfs, CTLFLAG_RW, 0, "nullfs");
+
+static bool null_cache_vnodes = true;
+SYSCTL_BOOL(_vfs_nullfs, OID_AUTO, cache_vnodes, CTLFLAG_RWTUN,
+    &null_cache_vnodes, 0,
+    "cache free nullfs vnodes");
+
 /*
  * Mount null layer
  */
@@ -202,7 +210,8 @@ nullfs_mount(struct mount *mp)
 	}
 
 	xmp->nullm_flags |= NULLM_CACHE;
-	if (vfs_getopt(mp->mnt_optnew, "nocache", NULL, NULL) == 0 ||
+	if (!null_cache_vnodes ||
+	    vfs_getopt(mp->mnt_optnew, "nocache", NULL, NULL) == 0 ||
 	    (xmp->nullm_vfs->mnt_kern_flag & MNTK_NULL_NOCACHE) != 0)
 		xmp->nullm_flags &= ~NULLM_CACHE;