From b77d60484179b49123698effa540a33e91cbbb1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Mon, 23 Apr 2007 19:17:01 +0000 Subject: [PATCH] Fix old locking bugs which were revealed when pseudofs was made MPSAFE. Submitted by: tegge --- sys/fs/pseudofs/pseudofs_vncache.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sys/fs/pseudofs/pseudofs_vncache.c b/sys/fs/pseudofs/pseudofs_vncache.c index 1310013bf37e..57aa983b10f7 100644 --- a/sys/fs/pseudofs/pseudofs_vncache.c +++ b/sys/fs/pseudofs/pseudofs_vncache.c @@ -150,10 +150,15 @@ pfs_vncache_alloc(struct mount *mp, struct vnode **vpp, /* nope, get a new one */ MALLOC(pvd, struct pfs_vdata *, sizeof *pvd, M_PFSVNCACHE, M_WAITOK); + mtx_lock(&pfs_vncache_mutex); if (++pfs_vncache_entries > pfs_vncache_maxentries) pfs_vncache_maxentries = pfs_vncache_entries; + mtx_unlock(&pfs_vncache_mutex); error = getnewvnode("pseudofs", mp, &pfs_vnodeops, vpp); if (error) { + mtx_lock(&pfs_vncache_mutex); + --pfs_vncache_entries; + mtx_unlock(&pfs_vncache_mutex); FREE(pvd, M_PFSVNCACHE); return (error); } @@ -195,6 +200,9 @@ pfs_vncache_alloc(struct mount *mp, struct vnode **vpp, vn_lock(*vpp, LK_EXCLUSIVE | LK_RETRY, curthread); error = insmntque(*vpp, mp); if (error != 0) { + mtx_lock(&pfs_vncache_mutex); + --pfs_vncache_entries; + mtx_unlock(&pfs_vncache_mutex); FREE(pvd, M_PFSVNCACHE); *vpp = NULLVP; return (error); @@ -226,9 +234,9 @@ pfs_vncache_free(struct vnode *vp) pvd->pvd_prev->pvd_next = pvd->pvd_next; else pfs_vncache = pvd->pvd_next; + --pfs_vncache_entries; mtx_unlock(&pfs_vncache_mutex); - --pfs_vncache_entries; FREE(pvd, M_PFSVNCACHE); vp->v_data = NULL; return (0);