When we do open, we should lock the vnode exclusively. This fixes few races:

- fifo race, where two threads assign v_fifoinfo,
- v_writecount modifications,
- v_object modifications,
- and probably more...

Discussed with:	kib, ups
Approved by:	re (rwatson)
This commit is contained in:
Pawel Jakub Dawidek 2007-07-26 16:58:09 +00:00
parent 68c1a246ae
commit 57fd3d5572
5 changed files with 8 additions and 7 deletions

View File

@ -232,6 +232,7 @@ devfs_allocv(struct devfs_dirent *de, struct mount *mp, struct vnode **vpp, stru
VI_LOCK(vp);
dev_lock();
dev_refl(dev);
/* XXX: v_rdev should be protect by vnode lock */
vp->v_rdev = dev;
KASSERT(vp->v_usecount == 1,
("%s %d (%d)\n", __func__, __LINE__, vp->v_usecount));

View File

@ -179,7 +179,7 @@ fifo_open(ap)
struct socket *rso, *wso;
int error;
ASSERT_VOP_LOCKED(vp, "fifo_open");
ASSERT_VOP_ELOCKED(vp, "fifo_open");
if (fp == NULL)
return (EINVAL);
if ((fip = vp->v_fifoinfo) == NULL) {

View File

@ -463,7 +463,7 @@ uipc_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
goto error;
}
vp = nd.ni_vp;
ASSERT_VOP_LOCKED(vp, "uipc_bind");
ASSERT_VOP_ELOCKED(vp, "uipc_bind");
soun = (struct sockaddr_un *)sodupsockaddr(nam, M_WAITOK);
UNP_GLOBAL_WLOCK();

View File

@ -184,7 +184,7 @@ vn_open_cred(ndp, flagp, cmode, cred, fp)
ndp->ni_cnd.cn_nameiop = LOOKUP;
ndp->ni_cnd.cn_flags = ISOPEN |
((fmode & O_NOFOLLOW) ? NOFOLLOW : FOLLOW) |
LOCKSHARED | LOCKLEAF | MPSAFE | AUDITVNODE1;
LOCKLEAF | MPSAFE | AUDITVNODE1;
if ((error = namei(ndp)) != 0)
return (error);
if (!mpsafe)
@ -235,7 +235,7 @@ vn_open_cred(ndp, flagp, cmode, cred, fp)
if (fmode & FWRITE)
vp->v_writecount++;
*flagp = fmode;
ASSERT_VOP_LOCKED(vp, "vn_open_cred");
ASSERT_VOP_ELOCKED(vp, "vn_open_cred");
if (!mpsafe)
VFS_UNLOCK_GIANT(vfslocked);
return (0);

View File

@ -151,7 +151,7 @@ vnode_destroy_vobject(struct vnode *vp)
obj = vp->v_object;
if (obj == NULL)
return;
ASSERT_VOP_LOCKED(vp, "vnode_destroy_vobject");
ASSERT_VOP_ELOCKED(vp, "vnode_destroy_vobject");
VM_OBJECT_LOCK(obj);
if (obj->ref_count == 0) {
/*
@ -198,7 +198,7 @@ vnode_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot,
vp = (struct vnode *) handle;
ASSERT_VOP_LOCKED(vp, "vnode_pager_alloc");
ASSERT_VOP_ELOCKED(vp, "vnode_pager_alloc");
/*
* If the object is being terminated, wait for it to
@ -256,7 +256,7 @@ vnode_pager_dealloc(object)
vm_object_clear_flag(object, OBJ_DISCONNECTWNT);
wakeup(object);
}
ASSERT_VOP_LOCKED(vp, "vnode_pager_dealloc");
ASSERT_VOP_ELOCKED(vp, "vnode_pager_dealloc");
vp->v_object = NULL;
vp->v_vflag &= ~VV_TEXT;
}