diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_znode.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_znode.c index a20183730102..46e501c1b6b8 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_znode.c +++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_znode.c @@ -119,8 +119,8 @@ zfs_znode_cache_constructor(void *buf, void *cdrarg, int kmflags) ASSERT(error == 0); zp->z_vnode = vp; vp->v_data = (caddr_t)zp; - vp->v_vnlock->lk_flags |= LK_CANRECURSE; - vp->v_vnlock->lk_flags &= ~LK_NOSHARE; + VN_LOCK_AREC(vp); + VN_LOCK_ASHARE(vp); } else { zp->z_vnode = NULL; } @@ -604,8 +604,8 @@ zfs_zget(zfsvfs_t *zfsvfs, uint64_t obj_num, znode_t **zpp) ASSERT(err == 0); vp = ZTOV(zp); vp->v_data = (caddr_t)zp; - vp->v_vnlock->lk_flags |= LK_CANRECURSE; - vp->v_vnlock->lk_flags &= ~LK_NOSHARE; + VN_LOCK_AREC(vp); + VN_LOCK_ASHARE(vp); vp->v_type = IFTOVT((mode_t)zp->z_phys->zp_mode); if (vp->v_type == VDIR) zp->z_zn_prefetch = B_TRUE; /* z_prefetch default is enabled */ diff --git a/sys/contrib/opensolaris/uts/common/fs/zfs/zfs_znode.c b/sys/contrib/opensolaris/uts/common/fs/zfs/zfs_znode.c index a20183730102..46e501c1b6b8 100644 --- a/sys/contrib/opensolaris/uts/common/fs/zfs/zfs_znode.c +++ b/sys/contrib/opensolaris/uts/common/fs/zfs/zfs_znode.c @@ -119,8 +119,8 @@ zfs_znode_cache_constructor(void *buf, void *cdrarg, int kmflags) ASSERT(error == 0); zp->z_vnode = vp; vp->v_data = (caddr_t)zp; - vp->v_vnlock->lk_flags |= LK_CANRECURSE; - vp->v_vnlock->lk_flags &= ~LK_NOSHARE; + VN_LOCK_AREC(vp); + VN_LOCK_ASHARE(vp); } else { zp->z_vnode = NULL; } @@ -604,8 +604,8 @@ zfs_zget(zfsvfs_t *zfsvfs, uint64_t obj_num, znode_t **zpp) ASSERT(err == 0); vp = ZTOV(zp); vp->v_data = (caddr_t)zp; - vp->v_vnlock->lk_flags |= LK_CANRECURSE; - vp->v_vnlock->lk_flags &= ~LK_NOSHARE; + VN_LOCK_AREC(vp); + VN_LOCK_ASHARE(vp); vp->v_type = IFTOVT((mode_t)zp->z_phys->zp_mode); if (vp->v_type == VDIR) zp->z_zn_prefetch = B_TRUE; /* z_prefetch default is enabled */ diff --git a/sys/fs/nwfs/nwfs_node.c b/sys/fs/nwfs/nwfs_node.c index 7a4964197cb7..b36840ebced5 100644 --- a/sys/fs/nwfs/nwfs_node.c +++ b/sys/fs/nwfs/nwfs_node.c @@ -188,7 +188,7 @@ nwfs_allocvp(struct mount *mp, ncpfid fid, struct nw_entry_info *fap, if (dvp) { np->n_parent = VTONW(dvp)->n_fid; } - vp->v_vnlock->lk_flags |= LK_CANRECURSE; + VN_LOCK_AREC(vp); lockmgr(&nwhashlock, LK_EXCLUSIVE, NULL); /* * Another process can create vnode while we blocked in malloc() or diff --git a/sys/fs/pseudofs/pseudofs_vncache.c b/sys/fs/pseudofs/pseudofs_vncache.c index ba57602b84d0..2e8040fa6df9 100644 --- a/sys/fs/pseudofs/pseudofs_vncache.c +++ b/sys/fs/pseudofs/pseudofs_vncache.c @@ -196,7 +196,7 @@ pfs_vncache_alloc(struct mount *mp, struct vnode **vpp, if ((pn->pn_flags & PFS_PROCDEP) != 0) (*vpp)->v_vflag |= VV_PROCDEP; pvd->pvd_vnode = *vpp; - (*vpp)->v_vnlock->lk_flags |= LK_CANRECURSE; + VN_LOCK_AREC(*vpp); vn_lock(*vpp, LK_EXCLUSIVE | LK_RETRY); error = insmntque(*vpp, mp); if (error != 0) { diff --git a/sys/fs/smbfs/smbfs_node.c b/sys/fs/smbfs/smbfs_node.c index d2993c621b1f..9761a8f5ef32 100644 --- a/sys/fs/smbfs/smbfs_node.c +++ b/sys/fs/smbfs/smbfs_node.c @@ -261,7 +261,7 @@ smbfs_node_alloc(struct mount *mp, struct vnode *dvp, } else if (vp->v_type == VREG) SMBERROR("new vnode '%s' born without parent ?\n", np->n_name); - vp->v_vnlock->lk_flags |= LK_CANRECURSE; + VN_LOCK_AREC(vp); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); smbfs_hash_lock(smp, td); diff --git a/sys/gnu/fs/xfs/FreeBSD/xfs_freebsd_iget.c b/sys/gnu/fs/xfs/FreeBSD/xfs_freebsd_iget.c index ff5b0c2efcfb..49cfb5d51c1b 100644 --- a/sys/gnu/fs/xfs/FreeBSD/xfs_freebsd_iget.c +++ b/sys/gnu/fs/xfs/FreeBSD/xfs_freebsd_iget.c @@ -389,7 +389,7 @@ xfs_vn_allocate(xfs_mount_t *mp, xfs_inode_t *ip, struct xfs_vnode **vpp) return (error); } - vp->v_vnlock->lk_flags |= LK_CANRECURSE; + VN_LOCK_AREC(vp); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); error = insmntque(vp, XVFSTOMNT(XFS_MTOVFS(mp))); if (error != 0) { diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c index 1e0a8be5cd06..8c4c612b7d49 100644 --- a/sys/kern/vfs_lookup.c +++ b/sys/kern/vfs_lookup.c @@ -84,7 +84,7 @@ nameiinit(void *dummy __unused) error = getnewvnode("crossmp", NULL, &dead_vnodeops, &vp_crossmp); if (error != 0) panic("nameiinit: getnewvnode"); - vp_crossmp->v_vnlock->lk_flags &= ~LK_NOSHARE; + VN_LOCK_ASHARE(vp_crossmp); } SYSINIT(vfs, SI_SUB_VFS, SI_ORDER_SECOND, nameiinit, NULL) diff --git a/sys/netncp/ncp_conn.c b/sys/netncp/ncp_conn.c index d870198f0afa..bff949844569 100644 --- a/sys/netncp/ncp_conn.c +++ b/sys/netncp/ncp_conn.c @@ -193,7 +193,7 @@ ncp_conn_unlock(struct ncp_conn *conn, struct thread *td) int ncp_conn_assert_locked(struct ncp_conn *conn, const char *checker, struct thread *td) { - if (conn->nc_lock.lk_flags & LK_HAVE_EXCL) return 0; + if (lockstatus(&conn->nc_lock, curthread) == LK_EXCLUSIVE) return 0; printf("%s: connection isn't locked!\n", checker); return EIO; } diff --git a/sys/nfsclient/nfs_node.c b/sys/nfsclient/nfs_node.c index 4f13a77c3b66..7876d3278d60 100644 --- a/sys/nfsclient/nfs_node.c +++ b/sys/nfsclient/nfs_node.c @@ -158,8 +158,8 @@ nfs_nget(struct mount *mntp, nfsfh_t *fhp, int fhsize, struct nfsnode **npp, int /* * NFS supports recursive and shared locking. */ - vp->v_vnlock->lk_flags |= LK_CANRECURSE; - vp->v_vnlock->lk_flags &= ~LK_NOSHARE; + VN_LOCK_AREC(vp); + VN_LOCK_ASHARE(vp); if (fhsize > NFS_SMALLFH) { MALLOC(np->n_fhp, nfsfh_t *, fhsize, M_NFSBIGFH, M_WAITOK); } else diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h index abbc9e1c1cd7..5c96a1c44112 100644 --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -400,6 +400,9 @@ extern void (*lease_updatetime)(int deltat); #define VI_UNLOCK(vp) mtx_unlock(&(vp)->v_interlock) #define VI_MTX(vp) (&(vp)->v_interlock) +#define VN_LOCK_AREC(vp) ((vp)->v_vnlock->lk_flags |= LK_CANRECURSE) +#define VN_LOCK_ASHARE(vp) ((vp)->v_vnlock->lk_flags &= ~LK_NOSHARE) + #endif /* _KERNEL */ /* diff --git a/sys/ufs/ffs/ffs_softdep.c b/sys/ufs/ffs/ffs_softdep.c index e4838e34f4f2..bda95d017f5e 100644 --- a/sys/ufs/ffs/ffs_softdep.c +++ b/sys/ufs/ffs/ffs_softdep.c @@ -564,6 +564,9 @@ MTX_SYSINIT(softdep_lock, &lk, "Softdep Lock", MTX_DEF); #define ACQUIRE_LOCK(lk) mtx_lock(lk) #define FREE_LOCK(lk) mtx_unlock(lk) +#define BUF_AREC(bp) ((bp)->b_lock.lk_flags |= LK_CANRECURSE) +#define BUF_NOREC(bp) ((bp)->b_lock.lk_flags &= ~LK_CANRECURSE) + /* * Worklist queue management. * These routines require that the lock be held. @@ -5251,7 +5254,7 @@ softdep_sync_metadata(struct vnode *vp) return (0); loop: /* While syncing snapshots, we must allow recursive lookups */ - bp->b_lock.lk_flags |= LK_CANRECURSE; + BUF_AREC(bp); ACQUIRE_LOCK(&lk); /* * As we hold the buffer locked, none of its dependencies @@ -5393,7 +5396,7 @@ softdep_sync_metadata(struct vnode *vp) /* We reach here only in error and unlocked */ if (error == 0) panic("softdep_sync_metadata: zero error"); - bp->b_lock.lk_flags &= ~LK_CANRECURSE; + BUF_NOREC(bp); bawrite(bp); return (error); } @@ -5405,7 +5408,7 @@ softdep_sync_metadata(struct vnode *vp) break; } VI_UNLOCK(vp); - bp->b_lock.lk_flags &= ~LK_CANRECURSE; + BUF_NOREC(bp); bawrite(bp); if (nbp != NULL) { bp = nbp; diff --git a/sys/ufs/ffs/ffs_vfsops.c b/sys/ufs/ffs/ffs_vfsops.c index 971694fdc205..f226750e5164 100644 --- a/sys/ufs/ffs/ffs_vfsops.c +++ b/sys/ufs/ffs/ffs_vfsops.c @@ -1363,8 +1363,8 @@ ffs_vget(mp, ino, flags, vpp) /* * FFS supports recursive and shared locking. */ - vp->v_vnlock->lk_flags |= LK_CANRECURSE; - vp->v_vnlock->lk_flags &= ~LK_NOSHARE; + VN_LOCK_AREC(vp); + VN_LOCK_ASHARE(vp); vp->v_data = ip; vp->v_bufobj.bo_bsize = fs->fs_bsize; ip->i_vnode = vp;