From b136fd4eeec08b4463f68e065e6aa2a33f14b660 Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 28 Mar 2005 09:34:36 +0000 Subject: [PATCH] - We no longer have to bother with PDIRUNLOCK, lookup() handles it for us. Sponsored by: Isilon Systems, Inc. --- sys/fs/cd9660/cd9660_lookup.c | 15 -------------- sys/fs/devfs/devfs_vnops.c | 23 ++------------------- sys/fs/msdosfs/msdosfs_lookup.c | 29 -------------------------- sys/fs/ntfs/ntfs_vnops.c | 22 +++----------------- sys/fs/portalfs/portal_vnops.c | 10 ++------- sys/fs/pseudofs/pseudofs_vnops.c | 30 ++++++++------------------- sys/isofs/cd9660/cd9660_lookup.c | 15 -------------- sys/ufs/ufs/ufs_lookup.c | 35 +++++--------------------------- 8 files changed, 21 insertions(+), 158 deletions(-) diff --git a/sys/fs/cd9660/cd9660_lookup.c b/sys/fs/cd9660/cd9660_lookup.c index bbff6c1075ec..09dbe5f9a939 100644 --- a/sys/fs/cd9660/cd9660_lookup.c +++ b/sys/fs/cd9660/cd9660_lookup.c @@ -102,7 +102,6 @@ cd9660_lookup(ap) struct vnode *pdp; /* saved dp during symlink work */ struct vnode *tdp; /* returned by cd9660_vget_internal */ u_long bmask; /* block offset mask */ - int lockparent; /* 1 => lockparent flag is set */ int error; ino_t ino = 0; int reclen; @@ -123,8 +122,6 @@ cd9660_lookup(ap) vdp = ap->a_dvp; dp = VTOI(vdp); imp = dp->i_mnt; - lockparent = flags & LOCKPARENT; - cnp->cn_flags &= ~PDIRUNLOCK; /* * We now have a segment name to search for, and a directory to search. @@ -360,14 +357,6 @@ cd9660_lookup(ap) vn_lock(pdp, LK_EXCLUSIVE | LK_RETRY, td); return (error); } - if (lockparent && (flags & ISLASTCN)) { - if ((error = vn_lock(pdp, LK_EXCLUSIVE, td)) != 0) { - cnp->cn_flags |= PDIRUNLOCK; - vput(tdp); - return (error); - } - } else - cnp->cn_flags |= PDIRUNLOCK; *vpp = tdp; } else if (dp->i_number == dp->i_ino) { brelse(bp); @@ -380,10 +369,6 @@ cd9660_lookup(ap) brelse(bp); if (error) return (error); - if (!lockparent || !(flags & ISLASTCN)) { - cnp->cn_flags |= PDIRUNLOCK; - VOP_UNLOCK(pdp, 0, td); - } *vpp = tdp; } diff --git a/sys/fs/devfs/devfs_vnops.c b/sys/fs/devfs/devfs_vnops.c index 0fa8e30aa165..c28dfa084910 100644 --- a/sys/fs/devfs/devfs_vnops.c +++ b/sys/fs/devfs/devfs_vnops.c @@ -587,9 +587,7 @@ devfs_lookupx(ap) nameiop = cnp->cn_nameiop; dmp = VFSTODEVFS(dvp->v_mount); dd = dvp->v_data; - *vpp = NULLVP; - cnp->cn_flags &= ~PDIRUNLOCK; if ((flags & ISLASTCN) && nameiop == RENAME) return (EOPNOTSUPP); @@ -616,15 +614,12 @@ devfs_lookupx(ap) if ((flags & ISLASTCN) && nameiop != LOOKUP) return (EINVAL); VOP_UNLOCK(dvp, 0, td); - cnp->cn_flags |= PDIRUNLOCK; de = TAILQ_FIRST(&dd->de_dlist); /* "." */ de = TAILQ_NEXT(de, de_list); /* ".." */ de = de->de_dir; error = devfs_allocv(de, dvp->v_mount, vpp, td); - if (error || ((flags & LOCKPARENT) && (flags & ISLASTCN))) { + if (error) vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, td); - cnp->cn_flags &= ~PDIRUNLOCK; - } return (error); } @@ -675,10 +670,6 @@ devfs_lookupx(ap) if ((nameiop == CREATE || nameiop == RENAME) && (flags & (LOCKPARENT | WANTPARENT)) && (flags & ISLASTCN)) { cnp->cn_flags |= SAVENAME; - if (!(flags & LOCKPARENT)) { - VOP_UNLOCK(dvp, 0, td); - cnp->cn_flags |= PDIRUNLOCK; - } return (EJUSTRETURN); } return (ENOENT); @@ -698,20 +689,10 @@ devfs_lookupx(ap) error = devfs_allocv(de, dvp->v_mount, vpp, td); if (error) return (error); - if (!(flags & LOCKPARENT)) { - VOP_UNLOCK(dvp, 0, td); - cnp->cn_flags |= PDIRUNLOCK; - } return (0); } error = devfs_allocv(de, dvp->v_mount, vpp, td); - if (error) - return (error); - if (!(flags & LOCKPARENT) || !(flags & ISLASTCN)) { - VOP_UNLOCK(dvp, 0, td); - cnp->cn_flags |= PDIRUNLOCK; - } - return (0); + return (error); } static int diff --git a/sys/fs/msdosfs/msdosfs_lookup.c b/sys/fs/msdosfs/msdosfs_lookup.c index 348b97c580ef..d2257030082a 100644 --- a/sys/fs/msdosfs/msdosfs_lookup.c +++ b/sys/fs/msdosfs/msdosfs_lookup.c @@ -90,7 +90,6 @@ msdosfs_lookup(ap) struct componentname *cnp = ap->a_cnp; daddr_t bn; int error; - int lockparent; int wantparent; int slotcount; int slotoffset = 0; @@ -116,7 +115,6 @@ msdosfs_lookup(ap) int wincnt = 1; int chksum = -1, chksum_ok; int olddos = 1; - cnp->cn_flags &= ~PDIRUNLOCK; #ifdef MSDOSFS_DEBUG printf("msdosfs_lookup(): looking for %s\n", cnp->cn_nameptr); @@ -124,7 +122,6 @@ msdosfs_lookup(ap) dp = VTODE(vdp); pmp = dp->de_pmp; *vpp = NULL; - lockparent = flags & LOCKPARENT; wantparent = flags & (LOCKPARENT | WANTPARENT); #ifdef MSDOSFS_DEBUG printf("msdosfs_lookup(): vdp %p, dp %p, Attr %02x\n", @@ -383,10 +380,6 @@ msdosfs_lookup(ap) * information cannot be used. */ cnp->cn_flags |= SAVENAME; - if (!lockparent) { - VOP_UNLOCK(vdp, 0, td); - cnp->cn_flags |= PDIRUNLOCK; - } return (EJUSTRETURN); } /* @@ -474,10 +467,6 @@ msdosfs_lookup(ap) if (error) return (error); *vpp = DETOV(tdp); - if (!lockparent) { - VOP_UNLOCK(vdp, 0, td); - cnp->cn_flags |= PDIRUNLOCK; - } return (0); } @@ -507,10 +496,6 @@ msdosfs_lookup(ap) return (error); *vpp = DETOV(tdp); cnp->cn_flags |= SAVENAME; - if (!lockparent) { - VOP_UNLOCK(vdp, 0, td); - cnp->cn_flags |= PDIRUNLOCK; - } return (0); } @@ -536,21 +521,11 @@ msdosfs_lookup(ap) pdp = vdp; if (flags & ISDOTDOT) { VOP_UNLOCK(pdp, 0, td); - cnp->cn_flags |= PDIRUNLOCK; error = deget(pmp, cluster, blkoff, &tdp); if (error) { vn_lock(pdp, LK_EXCLUSIVE | LK_RETRY, td); - cnp->cn_flags &= ~PDIRUNLOCK; return (error); } - if (lockparent && (flags & ISLASTCN)) { - error = vn_lock(pdp, LK_EXCLUSIVE, td); - if (error) { - vput(DETOV(tdp)); - return (error); - } - cnp->cn_flags &= ~PDIRUNLOCK; - } *vpp = DETOV(tdp); } else if (dp->de_StartCluster == scn && isadir) { VREF(vdp); /* we want ourself, ie "." */ @@ -558,10 +533,6 @@ msdosfs_lookup(ap) } else { if ((error = deget(pmp, cluster, blkoff, &tdp)) != 0) return (error); - if (!lockparent || !(flags & ISLASTCN)) { - VOP_UNLOCK(pdp, 0, td); - cnp->cn_flags |= PDIRUNLOCK; - } *vpp = DETOV(tdp); } diff --git a/sys/fs/ntfs/ntfs_vnops.c b/sys/fs/ntfs/ntfs_vnops.c index 1c0a0bb46d62..545117524d59 100644 --- a/sys/fs/ntfs/ntfs_vnops.c +++ b/sys/fs/ntfs/ntfs_vnops.c @@ -622,13 +622,12 @@ ntfs_lookup(ap) struct componentname *cnp = ap->a_cnp; struct ucred *cred = cnp->cn_cred; int error; - int lockparent = cnp->cn_flags & LOCKPARENT; #if NTFS_DEBUG int wantparent = cnp->cn_flags & (LOCKPARENT|WANTPARENT); #endif - dprintf(("ntfs_lookup: \"%.*s\" (%ld bytes) in %d, lp: %d, wp: %d \n", + dprintf(("ntfs_lookup: \"%.*s\" (%ld bytes) in %d, wp: %d \n", (int)cnp->cn_namelen, cnp->cn_nameptr, cnp->cn_namelen, - dip->i_number, lockparent, wantparent)); + dip->i_number, wantparent)); error = VOP_ACCESS(dvp, VEXEC, cred, cnp->cn_thread); if(error) @@ -657,27 +656,15 @@ ntfs_lookup(ap) return (error); VOP_UNLOCK(dvp,0,cnp->cn_thread); - cnp->cn_flags |= PDIRUNLOCK; - dprintf(("ntfs_lookup: parentdir: %d\n", vap->va_a_name->n_pnumber)); error = VFS_VGET(ntmp->ntm_mountp, vap->va_a_name->n_pnumber, LK_EXCLUSIVE, ap->a_vpp); ntfs_ntvattrrele(vap); if (error) { - if (vn_lock(dvp,LK_EXCLUSIVE|LK_RETRY,cnp->cn_thread)==0) - cnp->cn_flags &= ~PDIRUNLOCK; + vn_lock(dvp,LK_EXCLUSIVE|LK_RETRY,cnp->cn_thread); return (error); } - - if (lockparent && (cnp->cn_flags & ISLASTCN)) { - error = vn_lock(dvp, LK_EXCLUSIVE, cnp->cn_thread); - if (error) { - vput( *(ap->a_vpp) ); - return (error); - } - cnp->cn_flags &= ~PDIRUNLOCK; - } } else { error = ntfs_ntlookupfile(ntmp, dvp, cnp, ap->a_vpp); if (error) { @@ -687,9 +674,6 @@ ntfs_lookup(ap) dprintf(("ntfs_lookup: found ino: %d\n", VTONT(*ap->a_vpp)->i_number)); - - if(!lockparent || !(cnp->cn_flags & ISLASTCN)) - VOP_UNLOCK(dvp, 0, cnp->cn_thread); } if (cnp->cn_flags & MAKEENTRY) diff --git a/sys/fs/portalfs/portal_vnops.c b/sys/fs/portalfs/portal_vnops.c index f6c8d61cefd6..680d1fb6d15d 100644 --- a/sys/fs/portalfs/portal_vnops.c +++ b/sys/fs/portalfs/portal_vnops.c @@ -122,6 +122,8 @@ portal_lookup(ap) VREF(dvp); return (0); } + KASSERT((cnp->cn_flags & ISDOTDOT) == 0, + ("portal_lookup: Can not handle dotdot lookups.")); /* * Do the MALLOC before the getnewvnode since doing so afterward @@ -154,14 +156,6 @@ portal_lookup(ap) *vpp = fvp; vn_lock(fvp, LK_EXCLUSIVE | LK_RETRY, td); - /* - * As we are the last component of the path name, fix up - * the locking on the directory node. - */ - if ((cnp->cn_flags & LOCKPARENT) == 0) { - VOP_UNLOCK(dvp, 0, td); - cnp->cn_flags |= PDIRUNLOCK; - } return (0); bad:; diff --git a/sys/fs/pseudofs/pseudofs_vnops.c b/sys/fs/pseudofs/pseudofs_vnops.c index 042b91345110..3617cdc0da2e 100644 --- a/sys/fs/pseudofs/pseudofs_vnops.c +++ b/sys/fs/pseudofs/pseudofs_vnops.c @@ -322,15 +322,11 @@ pfs_lookup(struct vop_cachedlookup_args *va) struct pfs_node *pd = pvd->pvd_pn; struct pfs_node *pn, *pdn = NULL; pid_t pid = pvd->pvd_pid; - int lockparent; - int wantparent; char *pname; int error, i, namelen; PFS_TRACE(("%.*s", (int)cnp->cn_namelen, cnp->cn_nameptr)); - cnp->cn_flags &= ~PDIRUNLOCK; - if (vn->v_type != VDIR) PFS_RETURN (ENOTDIR); @@ -355,9 +351,6 @@ pfs_lookup(struct vop_cachedlookup_args *va) if (!pfs_visible(curthread, pd, pvd->pvd_pid)) PFS_RETURN (ENOENT); - lockparent = cnp->cn_flags & LOCKPARENT; - wantparent = cnp->cn_flags & (LOCKPARENT | WANTPARENT); - /* self */ namelen = cnp->cn_namelen; pname = cnp->cn_nameptr; @@ -373,8 +366,6 @@ pfs_lookup(struct vop_cachedlookup_args *va) if (pd->pn_type == pfstype_root) PFS_RETURN (EIO); VOP_UNLOCK(vn, 0, cnp->cn_thread); - cnp->cn_flags |= PDIRUNLOCK; - KASSERT(pd->pn_parent, ("non-root directory has no parent")); /* * This one is tricky. Descendents of procdir nodes @@ -413,25 +404,22 @@ pfs_lookup(struct vop_cachedlookup_args *va) got_pnode: if (pn != pd->pn_parent && !pn->pn_parent) pn->pn_parent = pd; - if (!pfs_visible(curthread, pn, pvd->pvd_pid)) - PFS_RETURN (ENOENT); + if (!pfs_visible(curthread, pn, pvd->pvd_pid)) { + error = ENOENT; + goto failed; + } error = pfs_vncache_alloc(vn->v_mount, vpp, pn, pid); if (error) - PFS_RETURN (error); - - if ((cnp->cn_flags & ISDOTDOT) && (cnp->cn_flags & ISLASTCN) && - lockparent) { - vn_lock(vn, LK_EXCLUSIVE|LK_RETRY, cnp->cn_thread); - cnp->cn_flags &= ~PDIRUNLOCK; - } - if (!((lockparent && (cnp->cn_flags & ISLASTCN)) || - (cnp->cn_flags & ISDOTDOT))) - VOP_UNLOCK(vn, 0, cnp->cn_thread); + goto failed; if (cnp->cn_flags & MAKEENTRY) cache_enter(vn, *vpp, cnp); PFS_RETURN (0); + failed: + if (cnp->cn_flags & ISDOTDOT) + vn_lock(vn, LK_EXCLUSIVE|LK_RETRY, cnp->cn_thread); + PFS_RETURN(error); } /* diff --git a/sys/isofs/cd9660/cd9660_lookup.c b/sys/isofs/cd9660/cd9660_lookup.c index bbff6c1075ec..09dbe5f9a939 100644 --- a/sys/isofs/cd9660/cd9660_lookup.c +++ b/sys/isofs/cd9660/cd9660_lookup.c @@ -102,7 +102,6 @@ cd9660_lookup(ap) struct vnode *pdp; /* saved dp during symlink work */ struct vnode *tdp; /* returned by cd9660_vget_internal */ u_long bmask; /* block offset mask */ - int lockparent; /* 1 => lockparent flag is set */ int error; ino_t ino = 0; int reclen; @@ -123,8 +122,6 @@ cd9660_lookup(ap) vdp = ap->a_dvp; dp = VTOI(vdp); imp = dp->i_mnt; - lockparent = flags & LOCKPARENT; - cnp->cn_flags &= ~PDIRUNLOCK; /* * We now have a segment name to search for, and a directory to search. @@ -360,14 +357,6 @@ cd9660_lookup(ap) vn_lock(pdp, LK_EXCLUSIVE | LK_RETRY, td); return (error); } - if (lockparent && (flags & ISLASTCN)) { - if ((error = vn_lock(pdp, LK_EXCLUSIVE, td)) != 0) { - cnp->cn_flags |= PDIRUNLOCK; - vput(tdp); - return (error); - } - } else - cnp->cn_flags |= PDIRUNLOCK; *vpp = tdp; } else if (dp->i_number == dp->i_ino) { brelse(bp); @@ -380,10 +369,6 @@ cd9660_lookup(ap) brelse(bp); if (error) return (error); - if (!lockparent || !(flags & ISLASTCN)) { - cnp->cn_flags |= PDIRUNLOCK; - VOP_UNLOCK(pdp, 0, td); - } *vpp = tdp; } diff --git a/sys/ufs/ufs/ufs_lookup.c b/sys/ufs/ufs/ufs_lookup.c index 8e5a757442cd..ba43c5b17114 100644 --- a/sys/ufs/ufs/ufs_lookup.c +++ b/sys/ufs/ufs/ufs_lookup.c @@ -146,7 +146,6 @@ ufs_lookup(ap) struct vnode *tdp; /* returned by VFS_VGET */ doff_t enduseful; /* pointer past last used dir slot */ u_long bmask; /* block offset mask */ - int lockparent; /* 1 => lockparent flag is set */ int wantparent; /* 1 => wantparent or lockparent flag */ int namlen, error; struct vnode **vpp = ap->a_vpp; @@ -158,7 +157,6 @@ ufs_lookup(ap) bp = NULL; slotoffset = -1; - cnp->cn_flags &= ~PDIRUNLOCK; /* * XXX there was a soft-update diff about this I couldn't merge. * I think this was the equiv. @@ -167,7 +165,6 @@ ufs_lookup(ap) vdp = ap->a_dvp; dp = VTOI(vdp); - lockparent = flags & LOCKPARENT; wantparent = flags & (LOCKPARENT|WANTPARENT); /* @@ -442,10 +439,6 @@ ufs_lookup(ap) * information cannot be used. */ cnp->cn_flags |= SAVENAME; - if (!lockparent) { - VOP_UNLOCK(vdp, 0, td); - cnp->cn_flags |= PDIRUNLOCK; - } return (EJUSTRETURN); } /* @@ -523,10 +516,6 @@ ufs_lookup(ap) return (EPERM); } *vpp = tdp; - if (!lockparent) { - VOP_UNLOCK(vdp, 0, td); - cnp->cn_flags |= PDIRUNLOCK; - } return (0); } @@ -550,10 +539,6 @@ ufs_lookup(ap) return (error); *vpp = tdp; cnp->cn_flags |= SAVENAME; - if (!lockparent) { - VOP_UNLOCK(vdp, 0, td); - cnp->cn_flags |= PDIRUNLOCK; - } return (0); } @@ -578,18 +563,12 @@ ufs_lookup(ap) */ pdp = vdp; if (flags & ISDOTDOT) { - if ((VFS_VGET(pdp->v_mount, dp->i_ino, LK_NOWAIT | LK_EXCLUSIVE, - &tdp)) != 0) { - VOP_UNLOCK(pdp, 0, td); /* race to get the inode */ - error = VFS_VGET(pdp->v_mount, dp->i_ino, - LK_EXCLUSIVE, &tdp); + VOP_UNLOCK(pdp, 0, td); /* race to get the inode */ + error = VFS_VGET(pdp->v_mount, dp->i_ino, + LK_EXCLUSIVE, &tdp); + if (error) { vn_lock(pdp, LK_EXCLUSIVE | LK_RETRY, td); - if (error) - return (error); - } - if (!lockparent || !(flags & ISLASTCN)) { - VOP_UNLOCK(pdp, 0, td); - cnp->cn_flags |= PDIRUNLOCK; + return (error); } *vpp = tdp; } else if (dp->i_number == dp->i_ino) { @@ -599,10 +578,6 @@ ufs_lookup(ap) error = VFS_VGET(pdp->v_mount, dp->i_ino, LK_EXCLUSIVE, &tdp); if (error) return (error); - if (!lockparent || !(flags & ISLASTCN)) { - VOP_UNLOCK(pdp, 0, td); - cnp->cn_flags |= PDIRUNLOCK; - } *vpp = tdp; }