diff options
author | rwatson <rwatson@FreeBSD.org> | 2008-03-02 19:02:30 +0000 |
---|---|---|
committer | rwatson <rwatson@FreeBSD.org> | 2008-03-02 19:02:30 +0000 |
commit | 1e5ea4d08580f809d3d67f2fd5e4fe1749d67cad (patch) | |
tree | 15ddcce01a295f5f3d3c331df9436e16b84cd0ea | |
parent | f0f08023032c77ced011d5d7fabf44b57fb62581 (diff) | |
download | FreeBSD-src-1e5ea4d08580f809d3d67f2fd5e4fe1749d67cad.zip FreeBSD-src-1e5ea4d08580f809d3d67f2fd5e4fe1749d67cad.tar.gz |
Replace lockmgr lock protecting nwfs vnode hash table with an sx lock.
MFC after: 1 month
-rw-r--r-- | sys/fs/nwfs/nwfs_node.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/sys/fs/nwfs/nwfs_node.c b/sys/fs/nwfs/nwfs_node.c index b36840e..6082fde 100644 --- a/sys/fs/nwfs/nwfs_node.c +++ b/sys/fs/nwfs/nwfs_node.c @@ -40,6 +40,7 @@ #include <sys/mutex.h> #include <sys/proc.h> #include <sys/queue.h> +#include <sys/sx.h> #include <sys/sysctl.h> #include <sys/time.h> #include <sys/vnode.h> @@ -62,7 +63,7 @@ static LIST_HEAD(nwnode_hash_head,nwnode) *nwhashtbl; static u_long nwnodehash; -static struct lock nwhashlock; +static struct sx nwhashlock; static MALLOC_DEFINE(M_NWNODE, "nwfs_node", "NWFS vnode private part"); static MALLOC_DEFINE(M_NWFSHASH, "nwfs_hash", "NWFS has table"); @@ -77,12 +78,12 @@ SYSCTL_PROC(_vfs_nwfs, OID_AUTO, vnprint, CTLFLAG_WR|CTLTYPE_OPAQUE, void nwfs_hash_init(void) { nwhashtbl = hashinit(desiredvnodes, M_NWFSHASH, &nwnodehash); - lockinit(&nwhashlock, PVFS, "nwfshl", 0, 0); + sx_init(&nwhashlock, "nwfshl"); } void nwfs_hash_free(void) { - lockdestroy(&nwhashlock); + sx_destroy(&nwhashlock); free(nwhashtbl, M_NWFSHASH); } @@ -118,6 +119,8 @@ nwfs_hashlookup(struct nwmount *nmp, ncpfid fid, struct nwnode **npp) struct nwnode *np; struct nwnode_hash_head *nhpp; + sx_assert(&nwhashlock, SA_XLOCKED); + nhpp = NWNOHASH(fid); LIST_FOREACH(np, nhpp, n_hash) { if (nmp != np->n_mount || !NWCMPF(&fid, &np->n_fid)) @@ -144,12 +147,12 @@ nwfs_allocvp(struct mount *mp, ncpfid fid, struct nw_entry_info *fap, int error; loop: - lockmgr(&nwhashlock, LK_EXCLUSIVE, NULL); + sx_xlock(&nwhashlock); rescan: if (nwfs_hashlookup(nmp, fid, &np) == 0) { vp = NWTOV(np); mtx_lock(&vp->v_interlock); - lockmgr(&nwhashlock, LK_RELEASE, NULL); + sx_xunlock(&nwhashlock); if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK, curthread)) goto loop; if (fap) @@ -157,7 +160,7 @@ rescan: *vpp = vp; return(0); } - lockmgr(&nwhashlock, LK_RELEASE, NULL); + sx_xunlock(&nwhashlock); if (fap == NULL || ((fap->attributes & aDIR) == 0 && dvp == NULL)) panic("nwfs_allocvp: fap = %p, dvp = %p\n", fap, dvp); @@ -189,7 +192,7 @@ rescan: np->n_parent = VTONW(dvp)->n_fid; } VN_LOCK_AREC(vp); - lockmgr(&nwhashlock, LK_EXCLUSIVE, NULL); + sx_xlock(&nwhashlock); /* * Another process can create vnode while we blocked in malloc() or * getnewvnode(). Rescan list again. @@ -205,7 +208,7 @@ rescan: nhpp = NWNOHASH(fid); LIST_INSERT_HEAD(nhpp, np, n_hash); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); - lockmgr(&nwhashlock, LK_RELEASE, NULL); + sx_xunlock(&nwhashlock); ASSERT_VOP_LOCKED(dvp, "nwfs_allocvp"); if (vp->v_type == VDIR && dvp && (dvp->v_vflag & VV_ROOT) == 0) { @@ -238,9 +241,9 @@ nwfs_lookupnp(struct nwmount *nmp, ncpfid fid, struct thread *td, { int error; - lockmgr(&nwhashlock, LK_EXCLUSIVE, NULL); + sx_xlock(&nwhashlock); error = nwfs_hashlookup(nmp, fid, npp); - lockmgr(&nwhashlock, LK_RELEASE, NULL); + sx_xunlock(&nwhashlock); return error; } @@ -273,9 +276,9 @@ nwfs_reclaim(ap) NCPVNDEBUG("%s: has no parent ?\n",np->n_name); } } - lockmgr(&nwhashlock, LK_EXCLUSIVE, NULL); + sx_xlock(&nwhashlock); LIST_REMOVE(np, n_hash); - lockmgr(&nwhashlock, LK_RELEASE, NULL); + sx_xunlock(&nwhashlock); if (nmp->n_root == np) { nmp->n_root = NULL; } |