Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/yamt-lazymbuf]: src/sys/nfs - sprinkle some locks.
details: https://anonhg.NetBSD.org/src/rev/9a58537f34a6
branches: yamt-lazymbuf
changeset: 582778:9a58537f34a6
user: yamt <yamt%NetBSD.org@localhost>
date: Fri Feb 15 10:40:08 2008 +0000
description:
- sprinkle some locks.
- disable MNT_UPDATE because it involves too much locking headache.
- don't overwrite other bits in v_vflags when setting VV_ROOT.
diffstat:
sys/nfs/nfs.h | 3 ++-
sys/nfs/nfs_socket.c | 50 ++++++++++++++++++++++++++++++++++++--------------
sys/nfs/nfs_subs.c | 5 +++--
sys/nfs/nfs_syscalls.c | 6 ++----
sys/nfs/nfs_vfsops.c | 13 ++++++-------
sys/nfs/nfs_vnops.c | 12 ++++++++++--
6 files changed, 59 insertions(+), 30 deletions(-)
diffs (truncated from 444 to 300 lines):
diff -r 9f9a23e00954 -r 9a58537f34a6 sys/nfs/nfs.h
--- a/sys/nfs/nfs.h Thu Feb 14 10:19:59 2008 +0000
+++ b/sys/nfs/nfs.h Fri Feb 15 10:40:08 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nfs.h,v 1.48.12.5 2007/12/07 17:34:42 yamt Exp $ */
+/* $NetBSD: nfs.h,v 1.48.12.6 2008/02/15 10:40:08 yamt Exp $ */
/*
* Copyright (c) 1989, 1993, 1995
* The Regents of the University of California. All rights reserved.
@@ -338,6 +338,7 @@
/*
* Queue head for nfsreq's
*/
+extern kmutex_t nfs_reqq_lock;
extern TAILQ_HEAD(nfsreqhead, nfsreq) nfs_reqq;
/* Flag values for r_flags */
diff -r 9f9a23e00954 -r 9a58537f34a6 sys/nfs/nfs_socket.c
--- a/sys/nfs/nfs_socket.c Thu Feb 14 10:19:59 2008 +0000
+++ b/sys/nfs/nfs_socket.c Fri Feb 15 10:40:08 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nfs_socket.c,v 1.114.2.7 2008/01/21 09:47:34 yamt Exp $ */
+/* $NetBSD: nfs_socket.c,v 1.114.2.8 2008/02/15 10:40:08 yamt Exp $ */
/*
* Copyright (c) 1989, 1991, 1993, 1995
@@ -39,7 +39,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nfs_socket.c,v 1.114.2.7 2008/01/21 09:47:34 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nfs_socket.c,v 1.114.2.8 2008/02/15 10:40:08 yamt Exp $");
#include "fs_nfs.h"
#include "opt_nfs.h"
@@ -166,6 +166,7 @@
static const int nfs_backoff[8] = { 2, 4, 8, 16, 32, 64, 128, 256, };
int nfsrtton = 0;
struct nfsrtt nfsrtt;
+kmutex_t nfs_reqq_lock;
struct nfsreqhead nfs_reqq;
static callout_t nfs_timer_ch;
static struct evcnt nfs_timer_ev;
@@ -200,6 +201,8 @@
#endif
struct mbuf *m;
+ KERNEL_LOCK(1, NULL);
+
nmp->nm_so = (struct socket *)0;
saddr = mtod(nmp->nm_nam, struct sockaddr *);
error = socreate(saddr->sa_family, &nmp->nm_so,
@@ -352,10 +355,12 @@
nmp->nm_cwnd = NFS_MAXCWND / 2; /* Initial send window */
nmp->nm_sent = 0;
nmp->nm_timeouts = 0;
+ KERNEL_UNLOCK_ONE(NULL);
return (0);
bad:
nfs_disconnect(nmp);
+ KERNEL_UNLOCK_ONE(NULL);
return (error);
}
@@ -386,6 +391,7 @@
* Loop through outstanding request list and fix up all requests
* on old socket.
*/
+ mutex_enter(&nfs_reqq_lock);
TAILQ_FOREACH(rp, &nfs_reqq, r_chain) {
if (rp->r_nmp == nmp) {
if ((rp->r_flags & R_MUSTRESEND) == 0)
@@ -393,6 +399,7 @@
rp->r_rexmit = 0;
}
}
+ mutex_exit(&nfs_reqq_lock);
return (0);
}
@@ -406,6 +413,7 @@
struct socket *so;
int drain = 0;
+ KERNEL_LOCK(1, NULL);
if (nmp->nm_so) {
so = nmp->nm_so;
nmp->nm_so = (struct socket *)0;
@@ -429,6 +437,8 @@
}
soclose(so);
}
+ KERNEL_UNLOCK_ONE(NULL);
+
#ifdef DIAGNOSTIC
if (drain && (nmp->nm_waiters > 0))
panic("nfs_disconnect: waiters left after drain?");
@@ -645,8 +655,10 @@
UIO_SETUP_SYSSPACE(&auio);
do {
rcvflg = MSG_WAITALL;
+ KERNEL_LOCK(1, NULL);
error = (*so->so_receive)(so, (struct mbuf **)0, &auio,
(struct mbuf **)0, (struct mbuf **)0, &rcvflg);
+ KERNEL_UNLOCK_ONE(NULL);
if (error == EWOULDBLOCK && rep) {
if (rep->r_flags & R_SOFTTERM)
return (EINTR);
@@ -694,8 +706,10 @@
auio.uio_resid = len;
do {
rcvflg = MSG_WAITALL;
+ KERNEL_LOCK(1, NULL);
error = (*so->so_receive)(so, (struct mbuf **)0,
&auio, mp, (struct mbuf **)0, &rcvflg);
+ KERNEL_UNLOCK_ONE(NULL);
} while (error == EWOULDBLOCK || error == EINTR ||
error == ERESTART);
if (!error && auio.uio_resid > 0) {
@@ -719,8 +733,10 @@
/* not need to setup uio_vmspace */
do {
rcvflg = 0;
+ KERNEL_LOCK(1, NULL);
error = (*so->so_receive)(so, (struct mbuf **)0,
&auio, mp, &control, &rcvflg);
+ KERNEL_UNLOCK_ONE(NULL);
if (control)
m_freem(control);
if (error == EWOULDBLOCK && rep) {
@@ -763,8 +779,10 @@
/* not need to setup uio_vmspace */
do {
rcvflg = 0;
+ KERNEL_LOCK(1, NULL);
error = (*so->so_receive)(so, getnam, &auio, mp,
(struct mbuf **)0, &rcvflg);
+ KERNEL_UNLOCK_ONE(NULL);
if (error == EWOULDBLOCK &&
(rep->r_flags & R_SOFTTERM))
return (EINTR);
@@ -872,6 +890,7 @@
* Loop through the request list to match up the reply
* Iff no match, just drop the datagram
*/
+ mutex_enter(&nfs_reqq_lock);
TAILQ_FOREACH(rep, &nfs_reqq, r_chain) {
if (rep->r_mrep == NULL && rxid == rep->r_xid) {
/* Found it.. */
@@ -935,6 +954,7 @@
break;
}
}
+ mutex_exit(&nfs_reqq_lock);
nfs_rcvunlock(nmp);
/*
* If not matched to a request, drop it.
@@ -982,7 +1002,7 @@
char nickv[RPCX_NICKVERF];
time_t waituntil;
char *dpos, *cp2;
- int t1, s, error = 0, mrest_len, auth_len, auth_type;
+ int t1, error = 0, mrest_len, auth_len, auth_type;
int trylater_delay = NFS_TRYLATERDEL, failed_auth = 0;
int verf_len, verf_type;
u_int32_t xid;
@@ -1127,8 +1147,9 @@
* Chain request into list of outstanding requests. Be sure
* to put it LAST so timer finds oldest requests first.
*/
- s = splsoftnet();
+ mutex_enter(&nfs_reqq_lock);
TAILQ_INSERT_TAIL(&nfs_reqq, rep, r_chain);
+
nfs_timer_start();
/*
@@ -1137,9 +1158,7 @@
* do it now.
*/
if (nmp->nm_so && (nmp->nm_sotype != SOCK_DGRAM ||
- (nmp->nm_flag & NFSMNT_DUMBTIMR) ||
- nmp->nm_sent < nmp->nm_cwnd)) {
- splx(s);
+ (nmp->nm_flag & NFSMNT_DUMBTIMR) || nmp->nm_sent < nmp->nm_cwnd)) {
if (nmp->nm_soflags & PR_CONNREQUIRED)
error = nfs_sndlock(nmp, rep);
if (!error) {
@@ -1153,22 +1172,22 @@
rep->r_flags |= R_SENT;
}
} else {
- splx(s);
rep->r_rtt = -1;
}
/*
* Wait for the reply from our send or the timer's.
*/
- if (!error || error == EPIPE)
+ if (!error || error == EPIPE) {
+ mutex_exit(&nfs_reqq_lock);
error = nfs_reply(rep, lwp);
+ mutex_enter(&nfs_reqq_lock);
+ }
/*
* RPC done, unlink the request.
*/
- s = splsoftnet();
TAILQ_REMOVE(&nfs_reqq, rep, r_chain);
- splx(s);
/*
* Decrement the outstanding request count.
@@ -1177,6 +1196,7 @@
rep->r_flags &= ~R_SENT; /* paranoia */
nmp->nm_sent -= NFS_CWNDSCALE;
}
+ mutex_exit(&nfs_reqq_lock);
if (rexmitp != NULL) {
int rexmit;
@@ -1618,7 +1638,7 @@
struct socket *so;
struct nfsmount *nmp;
int timeo;
- int s, error;
+ int error;
bool more = false;
#ifdef NFSSERVER
struct timeval tv;
@@ -1628,7 +1648,7 @@
nfs_timer_ev.ev_count++;
- s = splsoftnet();
+ mutex_enter(&nfs_reqq_lock);
TAILQ_FOREACH(rep, &nfs_reqq, r_chain) {
more = true;
nmp = rep->r_nmp;
@@ -1722,7 +1742,7 @@
}
}
}
- splx(s);
+ mutex_exit(&nfs_reqq_lock);
#ifdef NFSSERVER
/*
@@ -1795,6 +1815,8 @@
bool catch = false;
int error = 0;
+ KASSERT(nmp == rep->r_nmp);
+
if (rep) {
l = rep->r_lwp;
if (rep->r_nmp->nm_flag & NFSMNT_INT)
diff -r 9f9a23e00954 -r 9a58537f34a6 sys/nfs/nfs_subs.c
--- a/sys/nfs/nfs_subs.c Thu Feb 14 10:19:59 2008 +0000
+++ b/sys/nfs/nfs_subs.c Fri Feb 15 10:40:08 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nfs_subs.c,v 1.149.2.9 2008/02/04 09:24:44 yamt Exp $ */
+/* $NetBSD: nfs_subs.c,v 1.149.2.10 2008/02/15 10:40:08 yamt Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -70,7 +70,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nfs_subs.c,v 1.149.2.9 2008/02/04 09:24:44 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nfs_subs.c,v 1.149.2.10 2008/02/15 10:40:08 yamt Exp $");
#include "fs_nfs.h"
#include "opt_nfs.h"
@@ -1555,6 +1555,7 @@
/*
* Initialize reply list and start timer
*/
+ mutex_init(&nfs_reqq_lock, MUTEX_DEFAULT, IPL_SOFTCLOCK);
TAILQ_INIT(&nfs_reqq);
nfs_timer_init();
MOWNER_ATTACH(&nfs_mowner);
diff -r 9f9a23e00954 -r 9a58537f34a6 sys/nfs/nfs_syscalls.c
--- a/sys/nfs/nfs_syscalls.c Thu Feb 14 10:19:59 2008 +0000
+++ b/sys/nfs/nfs_syscalls.c Fri Feb 15 10:40:08 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nfs_syscalls.c,v 1.78.4.7 2008/01/21 09:47:35 yamt Exp $ */
+/* $NetBSD: nfs_syscalls.c,v 1.78.4.8 2008/02/15 10:40:08 yamt Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nfs_syscalls.c,v 1.78.4.7 2008/01/21 09:47:35 yamt Exp $");
Home |
Main Index |
Thread Index |
Old Index