aboutsummaryrefslogtreecommitdiff
path: root/sys/nfsserver/nfs_srvcache.c
diff options
context:
space:
mode:
authorRobert Watson <rwatson@FreeBSD.org>2004-05-24 04:06:14 +0000
committerRobert Watson <rwatson@FreeBSD.org>2004-05-24 04:06:14 +0000
commit1ee624b31df9479d99900c9751e395b15a9795cd (patch)
tree64794e5ad3d2c2f7555caf8bcbc04652f192d1fa /sys/nfsserver/nfs_srvcache.c
parent966efcc76783ac795127625be29bf6e8c91628ae (diff)
downloadsrc-1ee624b31df9479d99900c9751e395b15a9795cd.tar.gz
src-1ee624b31df9479d99900c9751e395b15a9795cd.zip
The socket code upcalls into the NFS server using the so_upcall
mechanism so that early processing on mbufs can be performed before a context switch to the NFS server threads. Because of this, if the socket code is running without Giant, the NFS server also needs to be able to run the upcall code without relying on the presence on Giant. This change modifies the NFS server to run using a "giant code lock" covering operation of the whole subsystem. Work is in progress to move to data-based locking as part of the NFSv4 server changes. Introduce an NFS server subsystem lock, 'nfsd_mtx', and a set of macros to operate on the lock: NFSD_LOCK_ASSERT() Assert nfsd_mtx owned by current thread NFSD_UNLOCK_ASSERT() Assert nfsd_mtx not owned by current thread NFSD_LOCK_DONTCARE() Advisory: this function doesn't care NFSD_LOCK() Lock nfsd_mtx NFSD_UNLOCK() Unlock nfsd_mtx Constify a number of global variables/structures in the NFS server code, as they are not modified and contain constants only: nfsrvv2_procid nfsrv_nfsv3_procid nonidempotent nfsv2_repstat nfsv2_type nfsrv_nfsv3_procid nfsrvv2_procid nfsrv_v2errmap nfsv3err_null nfsv3err_getattr nfsv3err_setattr nfsv3err_lookup nfsv3err_access nfsv3err_readlink nfsv3err_read nfsv3err_write nfsv3err_create nfsv3err_mkdir nfsv3err_symlink nfsv3err_mknod nfsv3err_remove nfsv3err_rmdir nfsv3err_rename nfsv3err_link nfsv3err_readdir nfsv3err_readdirplus nfsv3err_fsstat nfsv3err_fsinfo nfsv3err_pathconf nfsv3err_commit nfsrv_v3errmap There are additional structures that should be constified but due to their being passed into general purpose functions without const arguments, I have not yet converted. In general, acquire nfsd_mtx when accessing any of the global NFS structures, including struct nfssvc_sock, struct nfsd, struct nfsrv_descript. Release nfsd_mtx whenever calling into VFS, and acquire Giant for calls into VFS. Giant is not required for any part of the operation of the NFS server with the exception of calls into VFS. Giant will never by acquired in the upcall code path. However, it may operate entirely covered by Giant, or not. If debug.mpsafenet is set to 0, the system calls will acquire Giant across all operations, and the upcall will assert Giant. As such, by default, this enables locking and allows us to test assertions, but should not cause any substantial new amount of code to be run without Giant. Bugs should manifest in the form of lock assertion failures for now. This approach is similar (but not identical) to modifications to the BSD/OS NFS server code snapshot provided by BSDi as part of their SMPng snapshot. The strategy is almost the same (single lock over the NFS server), but differs in the following ways: - Our NFS client and server code bases don't overlap, which means both fewer bugs and easier locking (thanks Peter!). Also means NFSD_*() as opposed to NFS_*(). - We make broad use of assertions, whereas the BSD/OS code does not. - Made slightly different choices about how to handle macros building packets but operating with side effects. - We acquire Giant only when entering VFS from the NFS server daemon threads. - Serious bugs in BSD/OS implementation corrected -- the snapshot we received was clearly a work in progress. Based on ideas from: BSDi SMPng Snapshot Reviewed by: rick@snowhite.cis.uoguelph.ca Extensive testing by: kris
Notes
Notes: svn path=/head/; revision=129639
Diffstat (limited to 'sys/nfsserver/nfs_srvcache.c')
-rw-r--r--sys/nfsserver/nfs_srvcache.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/sys/nfsserver/nfs_srvcache.c b/sys/nfsserver/nfs_srvcache.c
index f0e940dd9a89..e82625ed6928 100644
--- a/sys/nfsserver/nfs_srvcache.c
+++ b/sys/nfsserver/nfs_srvcache.c
@@ -44,7 +44,9 @@ __FBSDID("$FreeBSD$");
#include <sys/malloc.h>
#include <sys/mount.h>
#include <sys/systm.h>
+#include <sys/lock.h>
#include <sys/mbuf.h>
+#include <sys/mutex.h>
#include <sys/socket.h>
#include <sys/socketvar.h> /* for sodupsockaddr */
@@ -72,7 +74,7 @@ static u_long nfsrvhash;
/*
* Static array that defines which nfs rpc's are nonidempotent
*/
-static int nonidempotent[NFS_NPROCS] = {
+static const int nonidempotent[NFS_NPROCS] = {
FALSE,
FALSE,
TRUE,
@@ -99,7 +101,7 @@ static int nonidempotent[NFS_NPROCS] = {
};
/* True iff the rpc reply is an nfs status ONLY! */
-static int nfsv2_repstat[NFS_NPROCS] = {
+static const int nfsv2_repstat[NFS_NPROCS] = {
FALSE,
FALSE,
FALSE,
@@ -154,6 +156,8 @@ nfsrv_getcache(struct nfsrv_descript *nd, struct mbuf **repp)
caddr_t bpos;
int ret;
+ NFSD_LOCK_ASSERT();
+
/*
* Don't cache recent requests for reliable transport protocols.
* (Maybe we should for the case of a reconnect, but..)
@@ -167,7 +171,8 @@ loop:
NFS_DPF(RC, ("H%03x", rp->rc_xid & 0xfff));
if ((rp->rc_flag & RC_LOCKED) != 0) {
rp->rc_flag |= RC_WANTED;
- (void) tsleep(rp, PZERO-1, "nfsrc", 0);
+ (void) msleep(rp, &nfsd_mtx, PZERO-1,
+ "nfsrc", 0);
goto loop;
}
rp->rc_flag |= RC_LOCKED;
@@ -188,8 +193,10 @@ loop:
ret = RC_REPLY;
} else if (rp->rc_flag & RC_REPMBUF) {
nfsrvstats.srvcache_nonidemdonehits++;
+ NFSD_UNLOCK();
*repp = m_copym(rp->rc_reply, 0, M_COPYALL,
M_TRYWAIT);
+ NFSD_LOCK();
ret = RC_REPLY;
} else {
nfsrvstats.srvcache_idemdonehits++;
@@ -207,15 +214,17 @@ loop:
nfsrvstats.srvcache_misses++;
NFS_DPF(RC, ("M%03x", nd->nd_retxid & 0xfff));
if (numnfsrvcache < desirednfsrvcache) {
+ NFSD_UNLOCK();
rp = (struct nfsrvcache *)malloc((u_long)sizeof *rp,
M_NFSD, M_WAITOK | M_ZERO);
+ NFSD_LOCK();
numnfsrvcache++;
rp->rc_flag = RC_LOCKED;
} else {
rp = TAILQ_FIRST(&nfsrvlruhead);
while ((rp->rc_flag & RC_LOCKED) != 0) {
rp->rc_flag |= RC_WANTED;
- (void) tsleep(rp, PZERO-1, "nfsrc", 0);
+ (void) msleep(rp, &nfsd_mtx, PZERO-1, "nfsrc", 0);
rp = TAILQ_FIRST(&nfsrvlruhead);
}
rp->rc_flag |= RC_LOCKED;
@@ -261,6 +270,8 @@ nfsrv_updatecache(struct nfsrv_descript *nd, int repvalid, struct mbuf *repmbuf)
{
struct nfsrvcache *rp;
+ NFSD_LOCK_ASSERT();
+
if (!nd->nd_nam2)
return;
loop:
@@ -270,7 +281,8 @@ loop:
NFS_DPF(RC, ("U%03x", rp->rc_xid & 0xfff));
if ((rp->rc_flag & RC_LOCKED) != 0) {
rp->rc_flag |= RC_WANTED;
- (void) tsleep(rp, PZERO-1, "nfsrc", 0);
+ (void) msleep(rp, &nfsd_mtx, PZERO-1,
+ "nfsrc", 0);
goto loop;
}
rp->rc_flag |= RC_LOCKED;
@@ -298,8 +310,10 @@ loop:
rp->rc_status = nd->nd_repstat;
rp->rc_flag |= RC_REPSTATUS;
} else {
+ NFSD_UNLOCK();
rp->rc_reply = m_copym(repmbuf,
0, M_COPYALL, M_TRYWAIT);
+ NFSD_LOCK();
rp->rc_flag |= RC_REPMBUF;
}
}
@@ -322,6 +336,8 @@ nfsrv_cleancache(void)
{
struct nfsrvcache *rp, *nextrp;
+ NFSD_LOCK_ASSERT();
+
for (rp = TAILQ_FIRST(&nfsrvlruhead); rp != 0; rp = nextrp) {
nextrp = TAILQ_NEXT(rp, rc_lru);
LIST_REMOVE(rp, rc_hash);