From 4a22b7e60e63dfa34777b0629b4152c8a69c9c86 Mon Sep 17 00:00:00 2001 From: Boris Popov Date: Sun, 21 Nov 1999 16:35:29 +0000 Subject: [PATCH] Remove race condition under SMP. Noted by: Denis Kalinin --- sys/fs/nwfs/nwfs_vnops.c | 10 ++++++++-- sys/nwfs/nwfs_vnops.c | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/sys/fs/nwfs/nwfs_vnops.c b/sys/fs/nwfs/nwfs_vnops.c index d0845037947f..38e9f191e085 100644 --- a/sys/fs/nwfs/nwfs_vnops.c +++ b/sys/fs/nwfs/nwfs_vnops.c @@ -262,10 +262,16 @@ nwfs_close(ap) simple_unlock(&vp->v_interlock); return 0; } + simple_unlock(&vp->v_interlock); error = nwfs_vinvalbuf(vp, V_SAVE, ap->a_cred, ap->a_p, 1); - if (--np->opened == 0) { - error = ncp_close_file(NWFSTOCONN(VTONWFS(vp)), &np->n_fh, ap->a_p,ap->a_cred); + simple_lock(&vp->v_interlock); + if (np->opened == 0) { + simple_unlock(&vp->v_interlock); + return 0; } + if (--np->opened == 0) + error = ncp_close_file(NWFSTOCONN(VTONWFS(vp)), &np->n_fh, + ap->a_p, ap->a_cred); simple_unlock(&vp->v_interlock); np->n_atime = 0; return (error); diff --git a/sys/nwfs/nwfs_vnops.c b/sys/nwfs/nwfs_vnops.c index d0845037947f..38e9f191e085 100644 --- a/sys/nwfs/nwfs_vnops.c +++ b/sys/nwfs/nwfs_vnops.c @@ -262,10 +262,16 @@ nwfs_close(ap) simple_unlock(&vp->v_interlock); return 0; } + simple_unlock(&vp->v_interlock); error = nwfs_vinvalbuf(vp, V_SAVE, ap->a_cred, ap->a_p, 1); - if (--np->opened == 0) { - error = ncp_close_file(NWFSTOCONN(VTONWFS(vp)), &np->n_fh, ap->a_p,ap->a_cred); + simple_lock(&vp->v_interlock); + if (np->opened == 0) { + simple_unlock(&vp->v_interlock); + return 0; } + if (--np->opened == 0) + error = ncp_close_file(NWFSTOCONN(VTONWFS(vp)), &np->n_fh, + ap->a_p, ap->a_cred); simple_unlock(&vp->v_interlock); np->n_atime = 0; return (error);