From d9c1039158d022977b141a2880fe9724a697de84 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Thu, 10 Apr 2014 14:15:44 +0000 Subject: [PATCH 03/14] Omit needless locking in ffs_vget and ext2fs_vget. --- sys/ufs/ext2fs/ext2fs_vfsops.c | 13 +++++-------- sys/ufs/ffs/ffs_vfsops.c | 11 ++++------- sys/ufs/ufs/ufs_extern.h | 2 +- sys/ufs/ufs/ufs_ihash.c | 11 +++-------- 4 files changed, 13 insertions(+), 24 deletions(-) diff --git a/sys/ufs/ext2fs/ext2fs_vfsops.c b/sys/ufs/ext2fs/ext2fs_vfsops.c index a48f931..a04e51b 100644 --- a/sys/ufs/ext2fs/ext2fs_vfsops.c +++ b/sys/ufs/ext2fs/ext2fs_vfsops.c @@ -961,10 +961,8 @@ ext2fs_vget(struct mount *mp, ino_t ino, int flags, struct vnode **vpp) ump = VFSTOUFS(mp); dev = ump->um_dev; retry: - if ((*vpp = ufs_ihashget(dev, ino, LK_EXCLUSIVE)) != NULL) { - VOP_UNLOCK(*vpp); + if ((*vpp = ufs_ihashget(dev, ino, 0, true)) != NULL) return (0); - } /* Allocate a new vnode/inode. */ error = getnewvnode(VT_EXT2FS, mp, ext2fs_vnodeop_p, NULL, 0, &vp); @@ -975,7 +973,7 @@ retry: ip = pool_get(&ext2fs_inode_pool, PR_WAITOK); mutex_enter(&ufs_hashlock); - if ((*vpp = ufs_ihashget(dev, ino, 0)) != NULL) { + if ((*vpp = ufs_ihashget(dev, ino, 0, false)) != NULL) { mutex_exit(&ufs_hashlock); ungetnewvnode(vp); pool_put(&ext2fs_inode_pool, ip); @@ -1014,11 +1012,11 @@ retry: * The inode does not contain anything useful, so it would * be misleading to leave it on its hash chain. With mode * still zero, it will be unlinked and returned to the free - * list by vput(). + * list by vrele(). */ vready_fail(vp); - vput(vp); + vrele(vp); *vpp = NULL; return (error); } @@ -1043,7 +1041,7 @@ retry: error = ext2fs_vinit(mp, ext2fs_specop_p, ext2fs_fifoop_p, &vp); if (error) { vready_fail(vp); - vput(vp); + vrele(vp); *vpp = NULL; return (error); } @@ -1068,7 +1066,6 @@ retry: } uvm_vnp_setsize(vp, ext2fs_size(ip)); vready(vp); - VOP_UNLOCK(vp); *vpp = vp; return (0); } diff --git a/sys/ufs/ffs/ffs_vfsops.c b/sys/ufs/ffs/ffs_vfsops.c index 9db6ab7..c0d5d21 100644 --- a/sys/ufs/ffs/ffs_vfsops.c +++ b/sys/ufs/ffs/ffs_vfsops.c @@ -1743,10 +1743,8 @@ ffs_vget(struct mount *mp, ino_t ino, int flags, struct vnode **vpp) dev = ump->um_dev; retry: - if ((*vpp = ufs_ihashget(dev, ino, LK_EXCLUSIVE)) != NULL) { - VOP_UNLOCK(*vpp); + if ((*vpp = ufs_ihashget(dev, ino, 0, true)) != NULL) return (0); - } /* Allocate a new vnode/inode. */ error = getnewvnode(VT_UFS, mp, ffs_vnodeop_p, NULL, 0, &vp); @@ -1761,7 +1759,7 @@ ffs_vget(struct mount *mp, ino_t ino, int flags, struct vnode **vpp) * vnode/inode pair and retry. */ mutex_enter(&ufs_hashlock); - if (ufs_ihashget(dev, ino, 0) != NULL) { + if (ufs_ihashget(dev, ino, 0, false) != NULL) { mutex_exit(&ufs_hashlock); ungetnewvnode(vp); pool_cache_put(ffs_inode_cache, ip); @@ -1811,11 +1809,11 @@ ffs_vget(struct mount *mp, ino_t ino, int flags, struct vnode **vpp) * The inode does not contain anything useful, so it would * be misleading to leave it on its hash chain. With mode * still zero, it will be unlinked and returned to the free - * list by vput(). + * list by vrele(). */ vready_fail(vp); - vput(vp); + vrele(vp); *vpp = NULL; return (error); } @@ -1853,7 +1851,6 @@ ffs_vget(struct mount *mp, ino_t ino, int flags, struct vnode **vpp) } /* XXX */ uvm_vnp_setsize(vp, ip->i_size); vready(vp); - VOP_UNLOCK(vp); *vpp = vp; return (0); } diff --git a/sys/ufs/ufs/ufs_extern.h b/sys/ufs/ufs/ufs_extern.h index db91181..4413c3b 100644 --- a/sys/ufs/ufs/ufs_extern.h +++ b/sys/ufs/ufs/ufs_extern.h @@ -113,7 +113,7 @@ void ufs_ihashinit(void); void ufs_ihashreinit(void); void ufs_ihashdone(void); struct vnode *ufs_ihashlookup(dev_t, ino_t); -struct vnode *ufs_ihashget(dev_t, ino_t, int); +struct vnode *ufs_ihashget(dev_t, ino_t, int, bool); void ufs_ihashins(struct inode *); void ufs_ihashrem(struct inode *); diff --git a/sys/ufs/ufs/ufs_ihash.c b/sys/ufs/ufs/ufs_ihash.c index c604555..d363f9e0 100644 --- a/sys/ufs/ufs/ufs_ihash.c +++ b/sys/ufs/ufs/ufs_ihash.c @@ -133,7 +133,7 @@ ufs_ihashlookup(dev_t dev, ino_t inum) * to it. If it is in core, but locked, wait for it. */ struct vnode * -ufs_ihashget(dev_t dev, ino_t inum, int flags) +ufs_ihashget(dev_t dev, ino_t inum, int flags, bool do_vget) { struct ihashhead *ipp; struct inode *ip; @@ -145,7 +145,7 @@ ufs_ihashget(dev_t dev, ino_t inum, int flags) LIST_FOREACH(ip, ipp, i_hash) { if (inum == ip->i_number && dev == ip->i_dev) { vp = ITOV(ip); - if (flags == 0) { + if (!do_vget) { mutex_exit(&ufs_ihash_lock); } else { mutex_enter(vp->v_interlock); @@ -161,20 +161,15 @@ ufs_ihashget(dev_t dev, ino_t inum, int flags) } /* - * Insert the inode into the hash table, and return it locked. + * Insert the inode into the hash table. */ void ufs_ihashins(struct inode *ip) { struct ihashhead *ipp; - int error __diagused; KASSERT(mutex_owned(&ufs_hashlock)); - /* lock the inode, then put it on the appropriate hash list */ - error = VOP_LOCK(ITOV(ip), LK_EXCLUSIVE); - KASSERT(error == 0); - mutex_enter(&ufs_ihash_lock); ipp = &ihashtbl[INOHASH(ip->i_dev, ip->i_number)]; LIST_INSERT_HEAD(ipp, ip, i_hash); -- 1.8.3.1