git: f84ac01e1829 - stable/13 - nfsd: Make modifying vfs.nfsd.enable_locallocks safe
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 23 Jul 2024 00:55:25 UTC
The branch stable/13 has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=f84ac01e1829a6f3e48af076041120692c00ccb0 commit f84ac01e1829a6f3e48af076041120692c00ccb0 Author: Rick Macklem <rmacklem@FreeBSD.org> AuthorDate: 2024-06-23 22:47:22 +0000 Commit: Rick Macklem <rmacklem@FreeBSD.org> CommitDate: 2024-07-23 00:35:02 +0000 nfsd: Make modifying vfs.nfsd.enable_locallocks safe Commit dfaeeacc2cc2 modified clientID handling so that it could be done with only a mutex lock held when vfs.nfsd.enable_locallocks is 0. This makes it unsafe to change the setting of vfs.nfsd.enable_locallocks when nfsd threads are active. This patch forces all nfsd threads to be blocked when the value of vfs.nfsd.enable_locallocks is changed, so that it is done safely. (cherry picked from commit 67284d32e5e0d5f015d73eeac4342974277263f5) --- sys/fs/nfsserver/nfs_nfsdport.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/sys/fs/nfsserver/nfs_nfsdport.c b/sys/fs/nfsserver/nfs_nfsdport.c index 46be3e051056..f412451e4e35 100644 --- a/sys/fs/nfsserver/nfs_nfsdport.c +++ b/sys/fs/nfsserver/nfs_nfsdport.c @@ -70,6 +70,7 @@ extern int nfsrv_maxpnfsmirror; extern uint32_t nfs_srvmaxio; extern int nfs_bufpackets; extern u_long sb_max_adj; +extern struct nfsv4lock nfsv4rootfs_lock; NFSD_VNET_DECLARE(int, nfsrv_numnfsd); NFSD_VNET_DECLARE(struct nfsrv_stablefirst, nfsrv_stablefirst); @@ -177,8 +178,6 @@ SYSCTL_INT(_vfs_nfsd, OID_AUTO, commit_miss, CTLFLAG_RW, &nfs_commit_miss, 0, ""); SYSCTL_INT(_vfs_nfsd, OID_AUTO, issue_delegations, CTLFLAG_RW, &nfsrv_issuedelegs, 0, "Enable nfsd to issue delegations"); -SYSCTL_INT(_vfs_nfsd, OID_AUTO, enable_locallocks, CTLFLAG_RW, - &nfsrv_dolocallocks, 0, "Enable nfsd to acquire local locks on files"); SYSCTL_INT(_vfs_nfsd, OID_AUTO, debuglevel, CTLFLAG_RW, &nfsd_debuglevel, 0, "Debug level for NFS server"); NFSD_VNET_DECLARE(int, nfsd_enable_stringtouid); @@ -293,6 +292,38 @@ SYSCTL_PROC(_vfs_nfsd, OID_AUTO, srvmaxio, CTLTYPE_UINT | CTLFLAG_MPSAFE | CTLFLAG_RW, NULL, 0, sysctl_srvmaxio, "IU", "Maximum I/O size in bytes"); +static int +sysctl_dolocallocks(SYSCTL_HANDLER_ARGS) +{ + int error, igotlock, newdolocallocks; + + newdolocallocks = nfsrv_dolocallocks; + error = sysctl_handle_int(oidp, &newdolocallocks, 0, req); + if (error != 0 || req->newptr == NULL) + return (error); + if (newdolocallocks == nfsrv_dolocallocks) + return (0); + if (jailed(curthread->td_ucred)) + return (EINVAL); + + NFSLOCKV4ROOTMUTEX(); + do { + igotlock = nfsv4_lock(&nfsv4rootfs_lock, 1, NULL, + NFSV4ROOTLOCKMUTEXPTR, NULL); + } while (!igotlock); + NFSUNLOCKV4ROOTMUTEX(); + + nfsrv_dolocallocks = newdolocallocks; + + NFSLOCKV4ROOTMUTEX(); + nfsv4_unlock(&nfsv4rootfs_lock, 0); + NFSUNLOCKV4ROOTMUTEX(); + return (0); +} +SYSCTL_PROC(_vfs_nfsd, OID_AUTO, enable_locallocks, + CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RW, NULL, 0, + sysctl_dolocallocks, "IU", "Enable nfsd to acquire local locks on files"); + #define MAX_REORDERED_RPC 16 #define NUM_HEURISTIC 1031 #define NHUSE_INIT 64