From bbe5115ad9e7f8bc892c5071ed627d7cbdeccad2 Mon Sep 17 00:00:00 2001 From: yamt Date: Sun, 29 Apr 2007 14:56:59 +0000 Subject: [PATCH] use condvar. --- sys/nfs/nfs_socket.c | 27 ++++++++++++++++----------- sys/nfs/nfs_vfsops.c | 5 +++-- sys/nfs/nfsmount.h | 3 ++- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/sys/nfs/nfs_socket.c b/sys/nfs/nfs_socket.c index fa0571ae6f2a..58b08d94c816 100644 --- a/sys/nfs/nfs_socket.c +++ b/sys/nfs/nfs_socket.c @@ -1,4 +1,4 @@ -/* $NetBSD: nfs_socket.c,v 1.150 2007/04/29 10:30:18 yamt Exp $ */ +/* $NetBSD: nfs_socket.c,v 1.151 2007/04/29 14:56:59 yamt Exp $ */ /* * Copyright (c) 1989, 1991, 1993, 1995 @@ -39,7 +39,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: nfs_socket.c,v 1.150 2007/04/29 10:30:18 yamt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nfs_socket.c,v 1.151 2007/04/29 14:56:59 yamt Exp $"); #include "fs_nfs.h" #include "opt_nfs.h" @@ -414,14 +414,13 @@ nfs_disconnect(nmp) * wait for them to go away unhappy, to prevent *nmp * from evaporating while they're sleeping. */ + mutex_enter(&nmp->nm_lock); while (nmp->nm_waiters > 0) { - mutex_enter(&nmp->nm_lock); cv_broadcast(&nmp->nm_rcvcv); cv_broadcast(&nmp->nm_sndcv); - mutex_exit(&nmp->nm_lock); - (void) tsleep(&nmp->nm_waiters, PVFS, - "nfsdis", 0); + cv_wait(&nmp->nm_disconcv, &nmp->nm_lock); } + mutex_exit(&nmp->nm_lock); } soclose(so); } @@ -812,20 +811,27 @@ nfs_reply(myrep, lwp) /* * Get the next Rpc reply off the socket */ + + mutex_enter(&nmp->nm_lock); nmp->nm_waiters++; + mutex_exit(&nmp->nm_lock); + error = nfs_receive(myrep, &nam, &mrep, lwp); nfs_rcvunlock(nmp); + + mutex_enter(&nmp->nm_lock); + nmp->nm_waiters--; + cv_signal(&nmp->nm_disconcv); + mutex_exit(&nmp->nm_lock); + if (error) { if (nmp->nm_iflag & NFSMNT_DISMNT) { /* * Oops, we're going away now.. */ - nmp->nm_waiters--; - wakeup (&nmp->nm_waiters); return error; } - nmp->nm_waiters--; /* * Ignore routing errors on connectionless protocols? ? */ @@ -840,7 +846,6 @@ nfs_reply(myrep, lwp) } return (error); } - nmp->nm_waiters--; if (nam) m_freem(nam); @@ -1825,7 +1830,7 @@ nfs_rcvlock(struct nfsmount *nmp, struct nfsreq *rep) slptimeo); } if (*flagp & NFSMNT_DISMNT) { - wakeup(&nmp->nm_waiters); + cv_signal(&nmp->nm_disconcv); error = EIO; goto quit; } diff --git a/sys/nfs/nfs_vfsops.c b/sys/nfs/nfs_vfsops.c index fae737c37493..a372f4ef1c3a 100644 --- a/sys/nfs/nfs_vfsops.c +++ b/sys/nfs/nfs_vfsops.c @@ -1,4 +1,4 @@ -/* $NetBSD: nfs_vfsops.c,v 1.175 2007/04/29 10:30:19 yamt Exp $ */ +/* $NetBSD: nfs_vfsops.c,v 1.176 2007/04/29 14:57:00 yamt Exp $ */ /* * Copyright (c) 1989, 1993, 1995 @@ -35,7 +35,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: nfs_vfsops.c,v 1.175 2007/04/29 10:30:19 yamt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nfs_vfsops.c,v 1.176 2007/04/29 14:57:00 yamt Exp $"); #if defined(_KERNEL_OPT) #include "opt_compat_netbsd.h" @@ -728,6 +728,7 @@ mountnfs(argp, mp, nam, pth, hst, vpp, l) cv_init(&nmp->nm_rcvcv, "nfsrcv"); cv_init(&nmp->nm_sndcv, "nfssnd"); cv_init(&nmp->nm_aiocv, "nfsaio"); + cv_init(&nmp->nm_disconcv, "nfsdis"); } vfs_getnewfsid(mp); nmp->nm_mountp = mp; diff --git a/sys/nfs/nfsmount.h b/sys/nfs/nfsmount.h index f51a8610feb6..20a6b5d17525 100644 --- a/sys/nfs/nfsmount.h +++ b/sys/nfs/nfsmount.h @@ -1,4 +1,4 @@ -/* $NetBSD: nfsmount.h,v 1.43 2007/04/29 10:30:19 yamt Exp $ */ +/* $NetBSD: nfsmount.h,v 1.44 2007/04/29 14:57:00 yamt Exp $ */ /* * Copyright (c) 1989, 1993 @@ -170,6 +170,7 @@ struct nfsmount { u_int64_t nm_maxfilesize; /* maximum file size */ int nm_iflag; /* internal flags */ int nm_waiters; /* number of waiting listeners.. */ + kcondvar_t nm_disconcv; long nm_wcckludgetime; /* see nfs_check_wccdata() */ struct io_stats *nm_stats; /* per nfs mount statistics */ };