diff --git a/sys/fs/ext2fs/ext2_vnops.c b/sys/fs/ext2fs/ext2_vnops.c index 5948cbd052e3..a7da8249ab4d 100644 --- a/sys/fs/ext2fs/ext2_vnops.c +++ b/sys/fs/ext2fs/ext2_vnops.c @@ -910,7 +910,7 @@ ext2_rename(struct vop_rename_args *ap) if (error) goto out; VREF(tdvp); - error = vfs_relookup(tdvp, &tvp, tcnp); + error = vfs_relookup(tdvp, &tvp, tcnp, true); if (error) goto out; vrele(tdvp); @@ -1036,7 +1036,7 @@ ext2_rename(struct vop_rename_args *ap) fcnp->cn_flags &= ~MODMASK; fcnp->cn_flags |= LOCKPARENT | LOCKLEAF; VREF(fdvp); - error = vfs_relookup(fdvp, &fvp, fcnp); + error = vfs_relookup(fdvp, &fvp, fcnp, true); if (error == 0) vrele(fdvp); if (fvp != NULL) { diff --git a/sys/fs/msdosfs/msdosfs_vnops.c b/sys/fs/msdosfs/msdosfs_vnops.c index 8fb58a58b138..f095a4abea62 100644 --- a/sys/fs/msdosfs/msdosfs_vnops.c +++ b/sys/fs/msdosfs/msdosfs_vnops.c @@ -127,8 +127,7 @@ static vop_vptofh_t msdosfs_vptofh; /* * Create a regular file. On entry the directory to contain the file being * created is locked. We must release before we return. We must also free - * the pathname buffer pointed at by cnp->cn_pnbuf, always on error, or - * only if the SAVESTART bit in cn_flags is clear on success. + * the pathname buffer pointed at by cnp->cn_pnbuf, always on error. */ static int msdosfs_create(struct vop_create_args *ap) @@ -1127,8 +1126,6 @@ msdosfs_rename(struct vop_rename_args *ap) } if (error != 0) goto unlock; - if ((tcnp->cn_flags & SAVESTART) == 0) - panic("msdosfs_rename: lost to startdir"); } if (tip != NULL) { diff --git a/sys/fs/nfsserver/nfs_nfsdport.c b/sys/fs/nfsserver/nfs_nfsdport.c index 5a5b212ae584..e11477b20ee2 100644 --- a/sys/fs/nfsserver/nfs_nfsdport.c +++ b/sys/fs/nfsserver/nfs_nfsdport.c @@ -1172,7 +1172,6 @@ nfsvno_createsub(struct nfsrv_descript *nd, struct nameidata *ndp, error = nd->nd_repstat; if (!error && ndp->ni_vp == NULL) { if (nvap->na_type == VREG || nvap->na_type == VSOCK) { - vrele(ndp->ni_startdir); error = VOP_CREATE(ndp->ni_dvp, &ndp->ni_vp, &ndp->ni_cnd, &nvap->na_vattr); /* For a pNFS server, create the data file on a DS. */ @@ -1213,7 +1212,6 @@ nfsvno_createsub(struct nfsrv_descript *nd, struct nameidata *ndp, nvap->na_type = VFIFO; if (nvap->na_type != VFIFO && (error = priv_check_cred(nd->nd_cred, PRIV_VFS_MKNOD_DEV))) { - vrele(ndp->ni_startdir); nfsvno_relpathbuf(ndp); vput(ndp->ni_dvp); goto out; @@ -1224,11 +1222,9 @@ nfsvno_createsub(struct nfsrv_descript *nd, struct nameidata *ndp, VOP_VPUT_PAIR(ndp->ni_dvp, error == 0 ? &ndp->ni_vp : NULL, false); nfsvno_relpathbuf(ndp); - vrele(ndp->ni_startdir); if (error) goto out; } else { - vrele(ndp->ni_startdir); nfsvno_relpathbuf(ndp); vput(ndp->ni_dvp); error = ENXIO; @@ -1242,7 +1238,6 @@ nfsvno_createsub(struct nfsrv_descript *nd, struct nameidata *ndp, * 1 - clean up the lookup * 2 - iff !error and na_size set, truncate it */ - vrele(ndp->ni_startdir); nfsvno_relpathbuf(ndp); *vpp = ndp->ni_vp; if (ndp->ni_dvp == *vpp) @@ -1285,7 +1280,6 @@ nfsvno_mknod(struct nameidata *ndp, struct nfsvattr *nvap, struct ucred *cred, * Iff doesn't exist, create it. */ if (ndp->ni_vp) { - vrele(ndp->ni_startdir); nfsvno_relpathbuf(ndp); vput(ndp->ni_dvp); vrele(ndp->ni_vp); @@ -1293,14 +1287,12 @@ nfsvno_mknod(struct nameidata *ndp, struct nfsvattr *nvap, struct ucred *cred, goto out; } if (vtyp != VCHR && vtyp != VBLK && vtyp != VSOCK && vtyp != VFIFO) { - vrele(ndp->ni_startdir); nfsvno_relpathbuf(ndp); vput(ndp->ni_dvp); error = NFSERR_BADTYPE; goto out; } if (vtyp == VSOCK) { - vrele(ndp->ni_startdir); error = VOP_CREATE(ndp->ni_dvp, &ndp->ni_vp, &ndp->ni_cnd, &nvap->na_vattr); VOP_VPUT_PAIR(ndp->ni_dvp, error == 0 ? &ndp->ni_vp : NULL, @@ -1309,7 +1301,6 @@ nfsvno_mknod(struct nameidata *ndp, struct nfsvattr *nvap, struct ucred *cred, } else { if (nvap->na_type != VFIFO && (error = priv_check_cred(cred, PRIV_VFS_MKNOD_DEV))) { - vrele(ndp->ni_startdir); nfsvno_relpathbuf(ndp); vput(ndp->ni_dvp); goto out; @@ -1319,7 +1310,6 @@ nfsvno_mknod(struct nameidata *ndp, struct nfsvattr *nvap, struct ucred *cred, VOP_VPUT_PAIR(ndp->ni_dvp, error == 0 ? &ndp->ni_vp : NULL, false); nfsvno_relpathbuf(ndp); - vrele(ndp->ni_startdir); /* * Since VOP_MKNOD returns the ni_vp, I can't * see any reason to do the lookup. @@ -1371,7 +1361,6 @@ nfsvno_symlink(struct nameidata *ndp, struct nfsvattr *nvap, char *pathcp, int error = 0; if (ndp->ni_vp) { - vrele(ndp->ni_startdir); nfsvno_relpathbuf(ndp); if (ndp->ni_dvp == ndp->ni_vp) vrele(ndp->ni_dvp); @@ -1391,7 +1380,6 @@ nfsvno_symlink(struct nameidata *ndp, struct nfsvattr *nvap, char *pathcp, * Just vput it for v2. */ VOP_VPUT_PAIR(ndp->ni_dvp, &ndp->ni_vp, !not_v2 && error == 0); - vrele(ndp->ni_startdir); nfsvno_relpathbuf(ndp); out: @@ -1642,10 +1630,8 @@ nfsvno_rename(struct nameidata *fromndp, struct nameidata *tondp, NFSD_DEBUG(4, "nfsvno_rename: pnfsremove\n"); } - vrele(tondp->ni_startdir); nfsvno_relpathbuf(tondp); out1: - vrele(fromndp->ni_startdir); nfsvno_relpathbuf(fromndp); NFSEXITCODE(error); return (error); @@ -1862,7 +1848,6 @@ nfsvno_open(struct nfsrv_descript *nd, struct nameidata *ndp, stateidp, stp, NULL, nd, p, nd->nd_repstat); if (!nd->nd_repstat) { if (ndp->ni_vp == NULL) { - vrele(ndp->ni_startdir); nd->nd_repstat = VOP_CREATE(ndp->ni_dvp, &ndp->ni_vp, &ndp->ni_cnd, &nvap->na_vattr); /* For a pNFS server, create the data file on a DS. */ @@ -1900,8 +1885,6 @@ nfsvno_open(struct nfsrv_descript *nd, struct nameidata *ndp, } vp = ndp->ni_vp; } else { - if (ndp->ni_startdir) - vrele(ndp->ni_startdir); nfsvno_relpathbuf(ndp); vp = ndp->ni_vp; if (create == NFSV4OPEN_CREATE) { @@ -1935,8 +1918,7 @@ nfsvno_open(struct nfsrv_descript *nd, struct nameidata *ndp, } } else { nfsvno_relpathbuf(ndp); - if (ndp->ni_startdir && create == NFSV4OPEN_CREATE) { - vrele(ndp->ni_startdir); + if (create == NFSV4OPEN_CREATE) { if (ndp->ni_dvp == ndp->ni_vp) vrele(ndp->ni_dvp); else @@ -4186,7 +4168,7 @@ nfsrv_dscreate(struct vnode *dvp, struct vattr *vap, struct vattr *nvap, int error; NFSNAMEICNDSET(&named.ni_cnd, tcred, CREATE, - LOCKPARENT | LOCKLEAF | SAVESTART | NOCACHE); + LOCKPARENT | LOCKLEAF | NOCACHE); nfsvno_setpathbuf(&named, &bufp, &hashp); named.ni_cnd.cn_lkflags = LK_EXCLUSIVE; named.ni_cnd.cn_nameptr = bufp; diff --git a/sys/fs/nfsserver/nfs_nfsdserv.c b/sys/fs/nfsserver/nfs_nfsdserv.c index e37f8f445a11..125dec9f864f 100644 --- a/sys/fs/nfsserver/nfs_nfsdserv.c +++ b/sys/fs/nfsserver/nfs_nfsdserv.c @@ -611,7 +611,7 @@ nfsrvd_lookup(struct nfsrv_descript *nd, __unused int isdgram, } NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, LOOKUP, - LOCKLEAF | SAVESTART); + LOCKLEAF); nfsvno_setpathbuf(&named, &bufp, &hashp); error = nfsrv_parsename(nd, bufp, hashp, &named.ni_pathlen); if (error) { @@ -636,8 +636,6 @@ nfsrvd_lookup(struct nfsrv_descript *nd, __unused int isdgram, nfsrv_postopattr(nd, dattr_ret, &dattr); goto out; } - if (named.ni_startdir) - vrele(named.ni_startdir); nfsvno_relpathbuf(&named); vp = named.ni_vp; if ((nd->nd_flag & ND_NFSV4) != 0 && !NFSVNO_EXPORTED(exp) && @@ -1160,7 +1158,7 @@ nfsrvd_create(struct nfsrv_descript *nd, __unused int isdgram, goto out; } NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, CREATE, - LOCKPARENT | LOCKLEAF | SAVESTART | NOCACHE); + LOCKPARENT | LOCKLEAF | NOCACHE); nfsvno_setpathbuf(&named, &bufp, &hashp); error = nfsrv_parsename(nd, bufp, hashp, &named.ni_pathlen); if (error) @@ -1325,7 +1323,7 @@ nfsrvd_mknod(struct nfsrv_descript *nd, __unused int isdgram, struct thread *p = curthread; NFSVNO_ATTRINIT(&nva); - cnflags = (LOCKPARENT | SAVESTART); + cnflags = (LOCKPARENT); if (nd->nd_repstat) { nfsrv_wcc(nd, dirfor_ret, &dirfor, diraft_ret, &diraft); goto out; @@ -1633,7 +1631,7 @@ nfsrvd_rename(struct nfsrv_descript *nd, int isdgram, fdirfor_ret = nfsvno_getattr(dp, &fdirfor, nd, p, 1, NULL); tond.ni_cnd.cn_nameiop = 0; tond.ni_startdir = NULL; - NFSNAMEICNDSET(&fromnd.ni_cnd, nd->nd_cred, DELETE, WANTPARENT | SAVESTART); + NFSNAMEICNDSET(&fromnd.ni_cnd, nd->nd_cred, DELETE, WANTPARENT); nfsvno_setpathbuf(&fromnd, &bufp, &hashp); error = nfsrv_parsename(nd, bufp, hashp, &fromnd.ni_pathlen); if (error) { @@ -1694,7 +1692,7 @@ nfsrvd_rename(struct nfsrv_descript *nd, int isdgram, } } } - NFSNAMEICNDSET(&tond.ni_cnd, nd->nd_cred, RENAME, LOCKPARENT | LOCKLEAF | NOCACHE | SAVESTART); + NFSNAMEICNDSET(&tond.ni_cnd, nd->nd_cred, RENAME, LOCKPARENT | LOCKLEAF | NOCACHE); nfsvno_setpathbuf(&tond, &tbufp, &hashp); if (!nd->nd_repstat) { error = nfsrv_parsename(nd, tbufp, hashp, &tond.ni_pathlen); @@ -1900,7 +1898,7 @@ nfsrvd_symlink(struct nfsrv_descript *nd, __unused int isdgram, *vpp = NULL; NFSVNO_ATTRINIT(&nva); NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, CREATE, - LOCKPARENT | SAVESTART | NOCACHE); + LOCKPARENT | NOCACHE); nfsvno_setpathbuf(&named, &bufp, &hashp); error = nfsrv_parsename(nd, bufp, hashp, &named.ni_pathlen); if (!error && !nd->nd_repstat) @@ -3018,10 +3016,10 @@ nfsrvd_open(struct nfsrv_descript *nd, __unused int isdgram, } if (create == NFSV4OPEN_CREATE) NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, CREATE, - LOCKPARENT | LOCKLEAF | SAVESTART | NOCACHE); + LOCKPARENT | LOCKLEAF | NOCACHE); else NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, LOOKUP, - LOCKLEAF | SAVESTART); + LOCKLEAF); nfsvno_setpathbuf(&named, &bufp, &hashp); error = nfsrv_parsename(nd, bufp, hashp, &named.ni_pathlen); if (error) { @@ -3687,7 +3685,7 @@ nfsrvd_secinfo(struct nfsrv_descript *nd, int isdgram, * All this just to get the export flags for the name. */ NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, LOOKUP, - LOCKLEAF | SAVESTART); + LOCKLEAF); nfsvno_setpathbuf(&named, &bufp, &hashp); error = nfsrv_parsename(nd, bufp, hashp, &named.ni_pathlen); if (error) { @@ -3705,7 +3703,6 @@ nfsrvd_secinfo(struct nfsrv_descript *nd, int isdgram, vrele(dirp); if (nd->nd_repstat) goto out; - vrele(named.ni_startdir); nfsvno_relpathbuf(&named); fh.nfsrvfh_len = NFSX_MYFH; vp = named.ni_vp; @@ -3826,7 +3823,7 @@ nfsrvd_secinfononame(struct nfsrv_descript *nd, int isdgram, goto nfsmout; } NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, LOOKUP, - LOCKLEAF | SAVESTART); + LOCKLEAF); nfsvno_setpathbuf(&named, &bufp, &hashp); error = nfsrv_parsename(nd, bufp, hashp, &named.ni_pathlen); if (error != 0) { @@ -3840,7 +3837,6 @@ nfsrvd_secinfononame(struct nfsrv_descript *nd, int isdgram, vput(dp); if (dirp != NULL) vrele(dirp); - vrele(named.ni_startdir); nfsvno_relpathbuf(&named); vp = named.ni_vp; break; diff --git a/sys/fs/smbfs/smbfs_vnops.c b/sys/fs/smbfs/smbfs_vnops.c index 044745111543..1b1bb35e9749 100644 --- a/sys/fs/smbfs/smbfs_vnops.c +++ b/sys/fs/smbfs/smbfs_vnops.c @@ -528,8 +528,7 @@ smbfs_write(ap) * smbfs_create call * Create a regular file. On entry the directory to contain the file being * created is locked. We must release before we return. We must also free - * the pathname buffer pointed at by cnp->cn_pnbuf, always on error, or - * only if the SAVESTART bit in cn_flags is clear on success. + * the pathname buffer pointed at by cnp->cn_pnbuf, always on error. */ static int smbfs_create(ap) diff --git a/sys/fs/unionfs/union_subr.c b/sys/fs/unionfs/union_subr.c index 0b9e8fde4b6a..b84da505507a 100644 --- a/sys/fs/unionfs/union_subr.c +++ b/sys/fs/unionfs/union_subr.c @@ -662,6 +662,7 @@ unionfs_relookup(struct vnode *dvp, struct vnode **vpp, char *path, int pathlen, u_long nameiop) { int error; + bool refstart; cn->cn_namelen = pathlen; cn->cn_pnbuf = path; @@ -671,17 +672,19 @@ unionfs_relookup(struct vnode *dvp, struct vnode **vpp, cn->cn_cred = cnp->cn_cred; cn->cn_nameptr = cn->cn_pnbuf; - if (nameiop == DELETE) - cn->cn_flags |= (cnp->cn_flags & (DOWHITEOUT | SAVESTART)); - else if (RENAME == nameiop) - cn->cn_flags |= (cnp->cn_flags & SAVESTART); - else if (nameiop == CREATE) + refstart = false; + if (nameiop == DELETE) { + cn->cn_flags |= (cnp->cn_flags & DOWHITEOUT); + } else if (nameiop == RENAME) { + refstart = true; + } else if (nameiop == CREATE) { cn->cn_flags |= NOCACHE; + } vref(dvp); VOP_UNLOCK(dvp); - if ((error = vfs_relookup(dvp, vpp, cn))) { + if ((error = vfs_relookup(dvp, vpp, cn, refstart))) { vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY); } else vrele(dvp); @@ -1017,7 +1020,7 @@ unionfs_vn_create_on_upper(struct vnode **vpp, struct vnode *udvp, NDPREINIT(&nd); vref(udvp); - if ((error = vfs_relookup(udvp, &vp, &nd.ni_cnd)) != 0) + if ((error = vfs_relookup(udvp, &vp, &nd.ni_cnd, false)) != 0) goto unionfs_vn_create_on_upper_free_out2; vrele(udvp); diff --git a/sys/kern/vfs_acl.c b/sys/kern/vfs_acl.c index dffce9d29291..e5470bd11438 100644 --- a/sys/kern/vfs_acl.c +++ b/sys/kern/vfs_acl.c @@ -380,7 +380,8 @@ kern___acl_get_path(struct thread *td, const char *path, acl_type_t type, error = namei(&nd); if (error == 0) { error = vacl_get_acl(td, nd.ni_vp, type, aclp); - NDFREE(&nd, 0); + vrele(nd.ni_vp); + NDFREE_PNBUF(&nd); } return (error); } @@ -418,7 +419,8 @@ kern___acl_set_path(struct thread *td, const char *path, error = namei(&nd); if (error == 0) { error = vacl_set_acl(td, nd.ni_vp, type, aclp); - NDFREE(&nd, 0); + vrele(nd.ni_vp); + NDFREE_PNBUF(&nd); } return (error); } @@ -494,7 +496,8 @@ kern___acl_delete_path(struct thread *td, const char *path, error = namei(&nd); if (error == 0) { error = vacl_delete(td, nd.ni_vp, type); - NDFREE(&nd, 0); + vrele(nd.ni_vp); + NDFREE_PNBUF(&nd); } return (error); } @@ -551,7 +554,7 @@ kern___acl_aclcheck_path(struct thread *td, const char *path, acl_type_t type, error = namei(&nd); if (error == 0) { error = vacl_aclcheck(td, nd.ni_vp, type, aclp); - NDFREE(&nd, 0); + NDFREE_PNBUF(&nd); } return (error); } diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index e58d3f338085..d7b235c12f7b 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -3153,7 +3153,9 @@ kern___realpathat(struct thread *td, int fd, const char *path, char *buf, error = copyout(retbuf, buf, size); free(freebuf, M_TEMP); } - NDFREE(&nd, 0); + vrele(nd.ni_vp); + vrele(nd.ni_dvp); + NDFREE_PNBUF(&nd); return (error); } @@ -4186,7 +4188,7 @@ cache_fpl_terminated(struct cache_fpl *fpl) #define CACHE_FPL_SUPPORTED_CN_FLAGS \ (NC_NOMAKEENTRY | NC_KEEPPOSENTRY | LOCKLEAF | LOCKPARENT | WANTPARENT | \ - FAILIFEXISTS | FOLLOW | EMPTYPATH | LOCKSHARED | SAVESTART | WILLBEDIR | \ + FAILIFEXISTS | FOLLOW | EMPTYPATH | LOCKSHARED | WILLBEDIR | \ ISOPEN | NOMACCHECK | AUDITVNODE1 | AUDITVNODE2 | NOCAPCHECK | OPENREAD | \ OPENWRITE | WANTIOCTLCAPS) @@ -4422,7 +4424,7 @@ cache_fplookup_final_child(struct cache_fpl *fpl, enum vgetstate tvs) static int __noinline cache_fplookup_final_modifying(struct cache_fpl *fpl) { - struct nameidata *ndp; + struct nameidata *ndp __diagused; struct componentname *cnp; enum vgetstate dvs; struct vnode *dvp, *tvp; @@ -4537,10 +4539,6 @@ cache_fplookup_final_modifying(struct cache_fpl *fpl) fpl->tvp = tvp; if (tvp == NULL) { - if ((cnp->cn_flags & SAVESTART) != 0) { - ndp->ni_startdir = dvp; - vrefact(ndp->ni_startdir); - } MPASS(error == EJUSTRETURN); if ((cnp->cn_flags & LOCKPARENT) == 0) { VOP_UNLOCK(dvp); @@ -4597,11 +4595,6 @@ cache_fplookup_final_modifying(struct cache_fpl *fpl) VOP_UNLOCK(dvp); } - if ((cnp->cn_flags & SAVESTART) != 0) { - ndp->ni_startdir = dvp; - vrefact(ndp->ni_startdir); - } - return (cache_fpl_handled(fpl)); } @@ -4756,8 +4749,6 @@ cache_fplookup_degenerate(struct cache_fpl *fpl) return (cache_fpl_handled_error(fpl, EISDIR)); } - MPASS((cnp->cn_flags & SAVESTART) == 0); - if ((cnp->cn_flags & (LOCKPARENT|WANTPARENT)) != 0) { return (cache_fplookup_final_withparent(fpl)); } @@ -4878,8 +4869,6 @@ cache_fplookup_noentry(struct cache_fpl *fpl) return (cache_fplookup_modifying(fpl)); } - MPASS((cnp->cn_flags & SAVESTART) == 0); - /* * Only try to fill in the component if it is the last one, * otherwise not only there may be several to handle but the @@ -6058,9 +6047,6 @@ cache_fplookup(struct nameidata *ndp, enum cache_fpl_status *status, KASSERT ((cnp->cn_flags & CACHE_FPL_INTERNAL_CN_FLAGS) == 0, ("%s: internal flags found in cn_flags %" PRIx64, __func__, cnp->cn_flags)); - if ((cnp->cn_flags & SAVESTART) != 0) { - MPASS(cnp->cn_nameiop != LOOKUP); - } MPASS(cnp->cn_nameptr == cnp->cn_pnbuf); if (__predict_false(!cache_can_fplookup(&fpl))) { diff --git a/sys/kern/vfs_extattr.c b/sys/kern/vfs_extattr.c index d389b33d0634..d190ec60205a 100644 --- a/sys/kern/vfs_extattr.c +++ b/sys/kern/vfs_extattr.c @@ -108,7 +108,7 @@ sys_extattrctl(struct thread *td, struct extattrctl_args *uap) if (error) return (error); filename_vp = nd.ni_vp; - NDFREE(&nd, NDF_NO_VP_RELE); + NDFREE_PNBUF(&nd); } /* uap->path is always defined. */ @@ -120,13 +120,15 @@ sys_extattrctl(struct thread *td, struct extattrctl_args *uap) mp = nd.ni_vp->v_mount; error = vfs_busy(mp, 0); if (error) { - NDFREE(&nd, 0); + vput(nd.ni_vp); + NDFREE_PNBUF(&nd); mp = NULL; goto out; } VOP_UNLOCK(nd.ni_vp); error = vn_start_write(nd.ni_vp, &mp_writable, V_WAIT | V_PCATCH); - NDFREE(&nd, NDF_NO_VP_UNLOCK); + vrele(nd.ni_vp); + NDFREE_PNBUF(&nd); if (error) goto out; if (filename_vp != NULL) { diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c index 404c41a1bf2c..d6e0c824a323 100644 --- a/sys/kern/vfs_lookup.c +++ b/sys/kern/vfs_lookup.c @@ -800,9 +800,6 @@ vfs_lookup_degenerate(struct nameidata *ndp, struct vnode *dp, int wantparent) if (!(cnp->cn_flags & (LOCKPARENT | LOCKLEAF))) VOP_UNLOCK(dp); - /* XXX This should probably move to the top of function. */ - if (cnp->cn_flags & SAVESTART) - panic("lookup: SAVESTART"); return (0); bad: VOP_UNLOCK(dp); @@ -1208,10 +1205,6 @@ vfs_lookup(struct nameidata *ndp) * doesn't currently exist, leaving a pointer to the * (possibly locked) directory vnode in ndp->ni_dvp. */ - if (cnp->cn_flags & SAVESTART) { - ndp->ni_startdir = ndp->ni_dvp; - VREF(ndp->ni_startdir); - } goto success; } @@ -1366,10 +1359,6 @@ vfs_lookup(struct nameidata *ndp) error = EROFS; goto bad2; } - if (cnp->cn_flags & SAVESTART) { - ndp->ni_startdir = ndp->ni_dvp; - VREF(ndp->ni_startdir); - } if (!wantparent) { ni_dvp_unlocked = 2; if (ndp->ni_dvp != dp) @@ -1435,7 +1424,8 @@ vfs_lookup(struct nameidata *ndp) * Used by lookup to re-acquire things. */ int -vfs_relookup(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp) +vfs_relookup(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp, + bool refstart) { struct vnode *dp = NULL; /* the directory we are searching */ int rdonly; /* lookup read-only flag bit */ @@ -1479,7 +1469,7 @@ vfs_relookup(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp) VOP_UNLOCK(dp); *vpp = dp; /* XXX This should probably move to the top of function. */ - if (cnp->cn_flags & SAVESTART) + if (refstart) panic("lookup: SAVESTART"); return (0); } @@ -1506,7 +1496,7 @@ vfs_relookup(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp) goto bad; } /* ASSERT(dvp == ndp->ni_startdir) */ - if (cnp->cn_flags & SAVESTART) + if (refstart) VREF(dvp); if ((cnp->cn_flags & LOCKPARENT) == 0) VOP_UNLOCK(dp); @@ -1544,7 +1534,7 @@ vfs_relookup(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp) ("relookup: symlink found.\n")); /* ASSERT(dvp == ndp->ni_startdir) */ - if (cnp->cn_flags & SAVESTART) + if (refstart) VREF(dvp); if ((cnp->cn_flags & LOCKLEAF) == 0) @@ -1556,53 +1546,6 @@ vfs_relookup(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp) return (error); } -void -(NDFREE)(struct nameidata *ndp, const u_int flags) -{ - int unlock_dvp; - int unlock_vp; - - unlock_dvp = 0; - unlock_vp = 0; - - if (!(flags & NDF_NO_FREE_PNBUF)) { - NDFREE_PNBUF(ndp); - } - if (!(flags & NDF_NO_VP_UNLOCK) && - (ndp->ni_cnd.cn_flags & LOCKLEAF) && ndp->ni_vp) - unlock_vp = 1; - if (!(flags & NDF_NO_DVP_UNLOCK) && - (ndp->ni_cnd.cn_flags & LOCKPARENT) && - ndp->ni_dvp != ndp->ni_vp) - unlock_dvp = 1; - if (!(flags & NDF_NO_VP_RELE) && ndp->ni_vp) { - if (unlock_vp) { - vput(ndp->ni_vp); - unlock_vp = 0; - } else - vrele(ndp->ni_vp); - ndp->ni_vp = NULL; - } - if (unlock_vp) - VOP_UNLOCK(ndp->ni_vp); - if (!(flags & NDF_NO_DVP_RELE) && - (ndp->ni_cnd.cn_flags & (LOCKPARENT|WANTPARENT))) { - if (unlock_dvp) { - vput(ndp->ni_dvp); - unlock_dvp = 0; - } else - vrele(ndp->ni_dvp); - ndp->ni_dvp = NULL; - } - if (unlock_dvp) - VOP_UNLOCK(ndp->ni_dvp); - if (!(flags & NDF_NO_STARTDIR_RELE) && - (ndp->ni_cnd.cn_flags & SAVESTART)) { - vrele(ndp->ni_startdir); - ndp->ni_startdir = NULL; - } -} - #ifdef INVARIANTS /* * Validate the final state of ndp after the lookup. diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index 4aea0f263e46..63a30cbbdb3d 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -415,7 +415,8 @@ sysctl_try_reclaim_vnode(SYSCTL_HANDLER_ARGS) counter_u64_add(recycles_count, 1); vgone(vp); putvnode: - NDFREE(&nd, 0); + vput(vp); + NDFREE_PNBUF(&nd); out: free(buf, M_TEMP); return (error); diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index b3223e620962..fa5888ad836c 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -3637,8 +3637,8 @@ kern_renameat_mac(struct thread *td, int oldfd, const char *old, int newfd, { int error; - NDINIT_ATRIGHTS(fromnd, DELETE, LOCKPARENT | LOCKLEAF | SAVESTART | - AUDITVNODE1, pathseg, old, oldfd, &cap_renameat_source_rights); + NDINIT_ATRIGHTS(fromnd, DELETE, LOCKPARENT | LOCKLEAF | AUDITVNODE1, + pathseg, old, oldfd, &cap_renameat_source_rights); if ((error = namei(fromnd)) != 0) return (error); error = mac_vnode_check_rename_from(td->td_ucred, fromnd->ni_dvp, @@ -3650,8 +3650,6 @@ kern_renameat_mac(struct thread *td, int oldfd, const char *old, int newfd, NDFREE_PNBUF(fromnd); vrele(fromnd->ni_dvp); vrele(fromnd->ni_vp); - if (fromnd->ni_startdir) - vrele(fromnd->ni_startdir); } return (error); } @@ -3677,7 +3675,7 @@ kern_renameat(struct thread *td, int oldfd, const char *old, int newfd, return (error); } else { #endif - NDINIT_ATRIGHTS(&fromnd, DELETE, WANTPARENT | SAVESTART | AUDITVNODE1, + NDINIT_ATRIGHTS(&fromnd, DELETE, WANTPARENT | AUDITVNODE1, pathseg, old, oldfd, &cap_renameat_source_rights); if ((error = namei(&fromnd)) != 0) return (error); @@ -3685,7 +3683,7 @@ kern_renameat(struct thread *td, int oldfd, const char *old, int newfd, } #endif fvp = fromnd.ni_vp; - tondflags = LOCKPARENT | LOCKLEAF | NOCACHE | SAVESTART | AUDITVNODE2; + tondflags = LOCKPARENT | LOCKLEAF | NOCACHE | AUDITVNODE2; if (fromnd.ni_vp->v_type == VDIR) tondflags |= WILLBEDIR; NDINIT_ATRIGHTS(&tond, RENAME, tondflags, pathseg, new, newfd, @@ -3713,9 +3711,6 @@ kern_renameat(struct thread *td, int oldfd, const char *old, int newfd, vput(tdvp); vrele(fromnd.ni_dvp); vrele(fvp); - vrele(tond.ni_startdir); - if (fromnd.ni_startdir != NULL) - vrele(fromnd.ni_startdir); error = vn_start_write(NULL, &mp, V_XSLEEP | V_PCATCH); if (error != 0) return (error); @@ -3775,11 +3770,8 @@ kern_renameat(struct thread *td, int oldfd, const char *old, int newfd, vrele(fromnd.ni_dvp); vrele(fvp); } - vrele(tond.ni_startdir); vn_finished_write(mp); out1: - if (fromnd.ni_startdir) - vrele(fromnd.ni_startdir); if (error == ERESTART) return (0); if (error == ERELOOKUP) diff --git a/sys/security/mac/mac_syscalls.c b/sys/security/mac/mac_syscalls.c index 9bc334686aa4..ecb451ac2018 100644 --- a/sys/security/mac/mac_syscalls.c +++ b/sys/security/mac/mac_syscalls.c @@ -369,7 +369,8 @@ kern___mac_get_path(struct thread *td, const char *path_p, struct mac *mac_p, mac_vnode_copy_label(nd.ni_vp->v_label, intlabel); error = mac_vnode_externalize_label(intlabel, elements, buffer, mac.m_buflen); - NDFREE(&nd, 0); + vput(nd.ni_vp); + NDFREE_PNBUF(&nd); mac_vnode_label_free(intlabel); if (error == 0) @@ -542,9 +543,9 @@ kern___mac_set_path(struct thread *td, const char *path_p, struct mac *mac_p, td->td_ucred); vn_finished_write(mp); } + vput(nd.ni_vp); + NDFREE_PNBUF(&nd); } - - NDFREE(&nd, 0); out: mac_vnode_label_free(intlabel); return (error); diff --git a/sys/sys/namei.h b/sys/sys/namei.h index 75e4051d8879..fb709b8713d7 100644 --- a/sys/sys/namei.h +++ b/sys/sys/namei.h @@ -161,7 +161,7 @@ int cache_fplookup(struct nameidata *ndp, enum cache_fpl_status *status, */ #define RDONLY 0x00000200 /* lookup with read-only semantics */ /* UNUSED 0x00000400 */ -#define SAVESTART 0x00000800 /* save starting directory */ +/* UNUSED 0x00000800 */ #define ISWHITEOUT 0x00001000 /* found whiteout */ #define DOWHITEOUT 0x00002000 /* do whiteouts */ #define WILLBEDIR 0x00004000 /* new files will be dirs; allow trailing / */ @@ -290,12 +290,10 @@ do { \ _ndp->ni_cnd.cn_pnbuf = NULL; \ } while (0) -void NDFREE(struct nameidata *, const u_int); - int namei(struct nameidata *ndp); int vfs_lookup(struct nameidata *ndp); int vfs_relookup(struct vnode *dvp, struct vnode **vpp, - struct componentname *cnp); + struct componentname *cnp, bool refstart); #endif /* diff --git a/sys/ufs/ufs/ufs_vnops.c b/sys/ufs/ufs/ufs_vnops.c index 9ea38bc149a5..ecb8cb6900ca 100644 --- a/sys/ufs/ufs/ufs_vnops.c +++ b/sys/ufs/ufs/ufs_vnops.c @@ -1510,8 +1510,6 @@ ufs_rename( } if (error) goto unlockout; - if ((tcnp->cn_flags & SAVESTART) == 0) - panic("ufs_rename: lost to startdir"); } if (fip->i_effnlink == 0 || fdp->i_effnlink == 0 || tdp->i_effnlink == 0)