From 950a571078f24c9d58281a7ebaac55c569cdb408 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Fri, 11 Apr 2014 19:02:21 +0000 Subject: [PATCH 08/14] Omit needless lock dances in msdosfs_lookup. --- sys/fs/msdosfs/msdosfs_lookup.c | 64 +++-------------------------------------- 1 file changed, 4 insertions(+), 60 deletions(-) diff --git a/sys/fs/msdosfs/msdosfs_lookup.c b/sys/fs/msdosfs/msdosfs_lookup.c index 01e8dd0..f23b52c 100644 --- a/sys/fs/msdosfs/msdosfs_lookup.c +++ b/sys/fs/msdosfs/msdosfs_lookup.c @@ -113,7 +113,6 @@ msdosfs_lookup(void *v) int blsize; int isadir; /* ~0 if found direntry is a directory */ u_long scn; /* starting cluster number */ - struct vnode *pdp; struct denode *dp; struct denode *tdp; struct msdosfsmount *pmp; @@ -493,13 +492,7 @@ foundroot: } if ((error = deget(pmp, cluster, blkoff, 0, &tdp)) != 0) return (error); - /* XXX Omit needless lock/unlock. */ - if ((error = vn_lock(DETOV(tdp), LK_EXCLUSIVE)) != 0) { - vrele(DETOV(tdp)); - return (error); - } *vpp = DETOV(tdp); - VOP_UNLOCK(*vpp); return (0); } @@ -530,63 +523,17 @@ foundroot: if ((error = deget(pmp, cluster, blkoff, 0, &tdp)) != 0) return (error); - /* XXX Omit needless lock/unlock. */ - if ((error = vn_lock(DETOV(tdp), LK_EXCLUSIVE)) != 0) { - vrele(DETOV(tdp)); - return (error); - } *vpp = DETOV(tdp); - VOP_UNLOCK(*vpp); return (0); } - /* - * Step through the translation in the name. We do not `vput' the - * directory because we may need it again if a symbolic link - * is relative to the current directory. Instead we save it - * unlocked as "pdp". We must get the target inode before unlocking - * the directory to insure that the inode will not be removed - * before we get it. We prevent deadlock by always fetching - * inodes from the root, moving down the directory tree. Thus - * when following backward pointers ".." we must unlock the - * parent directory before getting the requested directory. - * There is a potential race condition here if both the current - * and parent directories are removed before the VFS_VGET for the - * inode associated with ".." returns. We hope that this occurs - * infrequently since we cannot avoid this race condition without - * implementing a sophisticated deadlock detection algorithm. - * Note also that this simple deadlock detection scheme will not - * work if the file system has any hard links other than ".." - * that point backwards in the directory structure. - */ - pdp = vdp; - if (flags & ISDOTDOT) { - VOP_UNLOCK(pdp); /* race to get the inode */ - error = deget(pmp, cluster, blkoff, 0, &tdp); - if (error) { - vn_lock(pdp, LK_EXCLUSIVE | LK_RETRY); - return error; - } - /* XXX Omit needless lock/unlock. */ - error = vn_lock(DETOV(tdp), LK_EXCLUSIVE); - if (error) { - vrele(DETOV(tdp)); - vn_lock(pdp, LK_EXCLUSIVE | LK_RETRY); - return error; - } - vn_lock(pdp, LK_EXCLUSIVE | LK_RETRY); - *vpp = DETOV(tdp); - } else if (dp->de_StartCluster == scn && isadir) { + if (dp->de_StartCluster == scn && isadir) { vref(vdp); /* we want ourself, ie "." */ *vpp = vdp; } else { - if ((error = deget(pmp, cluster, blkoff, 0, &tdp)) != 0) - return (error); - /* XXX Omit needless lock/unlock. */ - if ((error = vn_lock(DETOV(tdp), LK_EXCLUSIVE)) != 0) { - vrele(DETOV(tdp)); - return (error); - } + error = deget(pmp, cluster, blkoff, 0, &tdp); + if (error) + return error; *vpp = DETOV(tdp); } @@ -595,9 +542,6 @@ foundroot: */ cache_enter(vdp, *vpp, cnp->cn_nameptr, cnp->cn_namelen, cnp->cn_flags); - if (*vpp != vdp) - VOP_UNLOCK(*vpp); - return 0; } #endif /* _KERNEL */ -- 1.8.3.1