vfs: always retain path buffer after lookup

This removes some of the complexity needed to maintain HASBUF and
allows for removing injecting SAVENAME by filesystems.

Reviewed by:	kib (previous version)
Differential Revision:	https://reviews.freebsd.org/D36542
This commit is contained in:
Mateusz Guzik 2022-09-17 09:10:38 +00:00
parent 3df3d88cc5
commit 5b5b7e2ca2
26 changed files with 96 additions and 361 deletions

View File

@ -965,13 +965,17 @@ zfs_lookup(vnode_t *dvp, const char *nm, vnode_t **vpp,
case RENAME:
if (error == ENOENT) {
error = EJUSTRETURN;
#if __FreeBSD_version < 1400068
cnp->cn_flags |= SAVENAME;
#endif
break;
}
zfs_fallthrough;
case DELETE:
#if __FreeBSD_version < 1400068
if (error == 0)
cnp->cn_flags |= SAVENAME;
#endif
break;
}
}
@ -1318,7 +1322,10 @@ zfs_lookup_internal(znode_t *dzp, const char *name, vnode_t **vpp,
cnp->cn_nameptr = __DECONST(char *, name);
cnp->cn_namelen = strlen(name);
cnp->cn_nameiop = nameiop;
cnp->cn_flags = ISLASTCN | SAVENAME;
cnp->cn_flags = ISLASTCN;
#if __FreeBSD_version < 1400068
cnp->cn_flags |= SAVENAME;
#endif
cnp->cn_lkflags = LK_EXCLUSIVE | LK_RETRY;
cnp->cn_cred = kcred;
#if __FreeBSD_version < 1400037
@ -4620,7 +4627,9 @@ zfs_freebsd_create(struct vop_create_args *ap)
znode_t *zp = NULL;
int rc, mode;
#if __FreeBSD_version < 1400068
ASSERT(cnp->cn_flags & SAVENAME);
#endif
vattr_init_mask(vap);
mode = vap->va_mode & ALLPERMS;
@ -4650,7 +4659,9 @@ static int
zfs_freebsd_remove(struct vop_remove_args *ap)
{
#if __FreeBSD_version < 1400068
ASSERT(ap->a_cnp->cn_flags & SAVENAME);
#endif
return (zfs_remove_(ap->a_dvp, ap->a_vp, ap->a_cnp->cn_nameptr,
ap->a_cnp->cn_cred));
@ -4672,7 +4683,9 @@ zfs_freebsd_mkdir(struct vop_mkdir_args *ap)
znode_t *zp = NULL;
int rc;
#if __FreeBSD_version < 1400068
ASSERT(ap->a_cnp->cn_flags & SAVENAME);
#endif
vattr_init_mask(vap);
*ap->a_vpp = NULL;
@ -4698,7 +4711,9 @@ zfs_freebsd_rmdir(struct vop_rmdir_args *ap)
{
struct componentname *cnp = ap->a_cnp;
#if __FreeBSD_version < 1400068
ASSERT(cnp->cn_flags & SAVENAME);
#endif
return (zfs_rmdir_(ap->a_dvp, ap->a_vp, cnp->cn_nameptr, cnp->cn_cred));
}
@ -4952,8 +4967,10 @@ zfs_freebsd_rename(struct vop_rename_args *ap)
vnode_t *tvp = ap->a_tvp;
int error;
#if __FreeBSD_version < 1400068
ASSERT(ap->a_fcnp->cn_flags & (SAVENAME|SAVESTART));
ASSERT(ap->a_tcnp->cn_flags & (SAVENAME|SAVESTART));
#endif
error = zfs_do_rename(fdvp, &fvp, ap->a_fcnp, tdvp, &tvp,
ap->a_tcnp, ap->a_fcnp->cn_cred);
@ -4989,7 +5006,9 @@ zfs_freebsd_symlink(struct vop_symlink_args *ap)
#endif
int rc;
#if __FreeBSD_version < 1400068
ASSERT(cnp->cn_flags & SAVENAME);
#endif
vap->va_type = VLNK; /* FreeBSD: Syscall only sets va_mode. */
vattr_init_mask(vap);
@ -5083,7 +5102,9 @@ zfs_freebsd_link(struct vop_link_args *ap)
if (tdvp->v_mount != vp->v_mount)
return (EXDEV);
#if __FreeBSD_version < 1400068
ASSERT(cnp->cn_flags & SAVENAME);
#endif
return (zfs_link(VTOZ(tdvp), VTOZ(vp),
cnp->cn_nameptr, cnp->cn_cred, 0));

View File

@ -1140,7 +1140,6 @@ devfs_lookupx(struct vop_lookup_args *ap, int *dm_unlock)
if (de == NULL || de->de_flags & DE_WHITEOUT) {
if ((nameiop == CREATE || nameiop == RENAME) &&
(flags & (LOCKPARENT | WANTPARENT)) && (flags & ISLASTCN)) {
cnp->cn_flags |= SAVENAME;
return (EJUSTRETURN);
}
return (ENOENT);

View File

@ -514,13 +514,10 @@ ext2_lookup_ino(struct vnode *vdp, struct vnode **vpp, struct componentname *cnp
* We return ni_vp == NULL to indicate that the entry
* does not currently exist; we leave a pointer to
* the (locked) directory inode in ndp->ni_dvp.
* The pathname buffer is saved so that the name
* can be obtained later.
*
* NB - if the directory is unlocked, then this
* information cannot be used.
*/
cnp->cn_flags |= SAVENAME;
return (EJUSTRETURN);
}
/*
@ -631,7 +628,6 @@ ext2_lookup_ino(struct vnode *vdp, struct vnode **vpp, struct componentname *cnp
&tdp)) != 0)
return (error);
*vpp = tdp;
cnp->cn_flags |= SAVENAME;
return (0);
}
if (dd_ino != NULL)
@ -925,10 +921,6 @@ ext2_direnter(struct inode *ip, struct vnode *dvp, struct componentname *cnp)
int DIRBLKSIZ = ip->i_e2fs->e2fs_bsize;
int error;
#ifdef INVARIANTS
if ((cnp->cn_flags & SAVENAME) == 0)
panic("ext2_direnter: missing name");
#endif
dp = VTOI(dvp);
newdir.e2d_ino = htole32(ip->i_number);
if (EXT2_HAS_INCOMPAT_FEATURE(ip->i_e2fs,

View File

@ -709,10 +709,6 @@ ext2_link(struct vop_link_args *ap)
struct inode *ip;
int error;
#ifdef INVARIANTS
if ((cnp->cn_flags & HASBUF) == 0)
panic("ext2_link: no name");
#endif
ip = VTOI(vp);
if ((nlink_t)ip->i_nlink >= EXT4_LINK_MAX) {
error = EMLINK;
@ -801,11 +797,6 @@ ext2_rename(struct vop_rename_args *ap)
int error = 0;
u_char namlen;
#ifdef INVARIANTS
if ((tcnp->cn_flags & HASBUF) == 0 ||
(fcnp->cn_flags & HASBUF) == 0)
panic("ext2_rename: no name");
#endif
/*
* Check for cross-device rename.
*/
@ -1315,10 +1306,6 @@ ext2_mkdir(struct vop_mkdir_args *ap)
char *buf = NULL;
int error, dmode;
#ifdef INVARIANTS
if ((cnp->cn_flags & HASBUF) == 0)
panic("ext2_mkdir: no name");
#endif
dp = VTOI(dvp);
if ((nlink_t)dp->i_nlink >= EXT4_LINK_MAX &&
!EXT2_HAS_RO_COMPAT_FEATURE(dp->i_e2fs, EXT2F_ROCOMPAT_DIR_NLINK)) {
@ -1946,10 +1933,6 @@ ext2_makeinode(int mode, struct vnode *dvp, struct vnode **vpp,
int error;
pdir = VTOI(dvp);
#ifdef INVARIANTS
if ((cnp->cn_flags & HASBUF) == 0)
panic("ext2_makeinode: no name");
#endif
*vpp = NULL;
if ((mode & IFMT) == 0)
mode |= IFREG;

View File

@ -1391,7 +1391,6 @@ fuse_vnop_lookup(struct vop_lookup_args *ap)
int nameiop = cnp->cn_nameiop;
int flags = cnp->cn_flags;
int wantparent = flags & (LOCKPARENT | WANTPARENT);
int islastcn = flags & ISLASTCN;
struct mount *mp = vnode_mount(dvp);
struct fuse_data *data = fuse_get_mpdata(mp);
@ -1533,13 +1532,6 @@ fuse_vnop_lookup(struct vop_lookup_args *ap)
else
err = 0;
if (!err) {
/*
* Set the SAVENAME flag to hold onto the
* pathname for use later in VOP_CREATE or
* VOP_RENAME.
*/
cnp->cn_flags |= SAVENAME;
err = EJUSTRETURN;
}
} else {
@ -1619,12 +1611,6 @@ fuse_vnop_lookup(struct vop_lookup_args *ap)
goto out;
}
}
if (islastcn && (
(nameiop == DELETE) ||
(nameiop == RENAME && wantparent))) {
cnp->cn_flags |= SAVENAME;
}
}
}
out:

View File

@ -421,13 +421,10 @@ msdosfs_lookup_ino(struct vnode *vdp, struct vnode **vpp, struct componentname
* We return ni_vp == NULL to indicate that the entry
* does not currently exist; we leave a pointer to
* the (locked) directory inode in ndp->ni_dvp.
* The pathname buffer is saved so that the name
* can be obtained later.
*
* NB - if the directory is unlocked, then this
* information cannot be used.
*/
cnp->cn_flags |= SAVENAME;
return (EJUSTRETURN);
}
#if 0
@ -554,7 +551,6 @@ msdosfs_lookup_ino(struct vnode *vdp, struct vnode **vpp, struct componentname
if ((error = msdosfs_lookup_checker(pmp, vdp, tdp, vpp))
!= 0)
return (error);
cnp->cn_flags |= SAVENAME;
return (0);
}

View File

@ -161,10 +161,6 @@ msdosfs_create(struct vop_create_args *ap)
* use the absence of the owner write bit to make the file
* readonly.
*/
#ifdef DIAGNOSTIC
if ((cnp->cn_flags & HASBUF) == 0)
panic("msdosfs_create: no name");
#endif
memset(&ndirent, 0, sizeof(ndirent));
error = uniqdosname(pdep, cnp, ndirent.de_Name);
if (error)
@ -958,11 +954,6 @@ msdosfs_rename(struct vop_rename_args *ap)
fcnp = ap->a_fcnp;
pmp = VFSTOMSDOSFS(fdvp->v_mount);
#ifdef DIAGNOSTIC
if ((tcnp->cn_flags & HASBUF) == 0 ||
(fcnp->cn_flags & HASBUF) == 0)
panic("msdosfs_rename: no name");
#endif
/*
* Check for cross-device rename.
*/
@ -1414,10 +1405,6 @@ msdosfs_mkdir(struct vop_mkdir_args *ap)
* cluster. This will be written to an empty slot in the parent
* directory.
*/
#ifdef DIAGNOSTIC
if ((cnp->cn_flags & HASBUF) == 0)
panic("msdosfs_mkdir: no name");
#endif
error = uniqdosname(pdep, cnp, ndirent.de_Name);
if (error)
goto bad;

View File

@ -1250,10 +1250,6 @@ nfs_lookup(struct vop_lookup_args *ap)
* associated locking bookkeeping, etc.
*/
if (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
/* XXX: Is this really correct? */
if (cnp->cn_nameiop != LOOKUP &&
(flags & ISLASTCN))
cnp->cn_flags |= SAVENAME;
return (0);
}
@ -1288,9 +1284,6 @@ nfs_lookup(struct vop_lookup_args *ap)
VOP_GETATTR(newvp, &vattr, cnp->cn_cred) == 0 &&
timespeccmp(&vattr.va_ctime, &nctime, ==))) {
NFSINCRGLOBAL(nfsstatsv1.lookupcache_hits);
if (cnp->cn_nameiop != LOOKUP &&
(flags & ISLASTCN))
cnp->cn_flags |= SAVENAME;
return (0);
}
cache_purge(newvp);
@ -1372,7 +1365,6 @@ nfs_lookup(struct vop_lookup_args *ap)
*/
if (mp->mnt_flag & MNT_RDONLY)
return (EROFS);
cnp->cn_flags |= SAVENAME;
return (EJUSTRETURN);
}
@ -1428,7 +1420,6 @@ nfs_lookup(struct vop_lookup_args *ap)
if (attrflag)
(void) nfscl_loadattrcache(&newvp, &nfsva, NULL, 0, 1);
*vpp = newvp;
cnp->cn_flags |= SAVENAME;
return (0);
}
@ -1513,8 +1504,6 @@ nfs_lookup(struct vop_lookup_args *ap)
NFSUNLOCKNODE(np);
}
}
if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN))
cnp->cn_flags |= SAVENAME;
if ((cnp->cn_flags & MAKEENTRY) && dvp != newvp &&
(cnp->cn_nameiop != DELETE || !(flags & ISLASTCN)) &&
attrflag != 0 && (newvp->v_type != VDIR || dattrflag != 0))
@ -1881,7 +1870,6 @@ nfs_remove(struct vop_remove_args *ap)
int error = 0;
struct vattr vattr;
KASSERT((cnp->cn_flags & HASBUF) != 0, ("nfs_remove: no name"));
KASSERT(vrefcnt(vp) > 0, ("nfs_remove: bad v_usecount"));
if (vp->v_type == VDIR)
error = EPERM;
@ -1994,8 +1982,6 @@ nfs_rename(struct vop_rename_args *ap)
struct nfsv4node *newv4 = NULL;
int error;
KASSERT((tcnp->cn_flags & HASBUF) != 0 &&
(fcnp->cn_flags & HASBUF) != 0, ("nfs_rename: no name"));
/* Check for cross-device rename */
if ((fvp->v_mount != tdvp->v_mount) ||
(tvp && (fvp->v_mount != tvp->v_mount))) {

View File

@ -686,8 +686,6 @@ nfsvno_namei(struct nfsrv_descript *nd, struct nameidata *ndp,
* termination occurs if no symlink encountered.
*/
if ((cnp->cn_flags & ISSYMLINK) == 0) {
if ((cnp->cn_flags & (SAVENAME | SAVESTART)) == 0)
nfsvno_relpathbuf(ndp);
if (ndp->ni_vp && !lockleaf)
NFSVOPUNLOCK(ndp->ni_vp);
break;
@ -796,7 +794,7 @@ nfsvno_setpathbuf(struct nameidata *ndp, char **bufpp, u_long **hashpp)
{
struct componentname *cnp = &ndp->ni_cnd;
cnp->cn_flags |= (NOMACCHECK | HASBUF);
cnp->cn_flags |= (NOMACCHECK);
cnp->cn_pnbuf = uma_zalloc(namei_zone, M_WAITOK);
if (hashpp != NULL)
*hashpp = NULL;
@ -810,10 +808,8 @@ void
nfsvno_relpathbuf(struct nameidata *ndp)
{
if ((ndp->ni_cnd.cn_flags & HASBUF) == 0)
panic("nfsrelpath");
uma_zfree(namei_zone, ndp->ni_cnd.cn_pnbuf);
ndp->ni_cnd.cn_flags &= ~HASBUF;
ndp->ni_cnd.cn_pnbuf = NULL;
}
/*
@ -1478,8 +1474,7 @@ nfsvno_removesub(struct nameidata *ndp, int is_v4, struct ucred *cred,
else
vput(ndp->ni_dvp);
vput(vp);
if ((ndp->ni_cnd.cn_flags & SAVENAME) != 0)
nfsvno_relpathbuf(ndp);
nfsvno_relpathbuf(ndp);
NFSEXITCODE(error);
return (error);
}
@ -1519,8 +1514,7 @@ nfsvno_rmdirsub(struct nameidata *ndp, int is_v4, struct ucred *cred,
else
vput(ndp->ni_dvp);
vput(vp);
if ((ndp->ni_cnd.cn_flags & SAVENAME) != 0)
nfsvno_relpathbuf(ndp);
nfsvno_relpathbuf(ndp);
NFSEXITCODE(error);
return (error);
}
@ -1939,8 +1933,7 @@ nfsvno_open(struct nfsrv_descript *nd, struct nameidata *ndp,
}
}
} else {
if (ndp->ni_cnd.cn_flags & HASBUF)
nfsvno_relpathbuf(ndp);
nfsvno_relpathbuf(ndp);
if (ndp->ni_startdir && create == NFSV4OPEN_CREATE) {
vrele(ndp->ni_startdir);
if (ndp->ni_dvp == ndp->ni_vp)
@ -4578,7 +4571,7 @@ nfsrv_dsremove(struct vnode *dvp, char *fname, struct ucred *tcred,
named.ni_cnd.cn_nameiop = DELETE;
named.ni_cnd.cn_lkflags = LK_EXCLUSIVE | LK_RETRY;
named.ni_cnd.cn_cred = tcred;
named.ni_cnd.cn_flags = ISLASTCN | LOCKPARENT | LOCKLEAF | SAVENAME;
named.ni_cnd.cn_flags = ISLASTCN | LOCKPARENT | LOCKLEAF;
nfsvno_setpathbuf(&named, &bufp, &hashp);
named.ni_cnd.cn_nameptr = bufp;
named.ni_cnd.cn_namelen = strlen(fname);
@ -6351,7 +6344,7 @@ nfsrv_pnfslookupds(struct vnode *vp, struct vnode *dvp, struct pnfsdsfile *pf,
named.ni_cnd.cn_nameiop = LOOKUP;
named.ni_cnd.cn_lkflags = LK_SHARED | LK_RETRY;
named.ni_cnd.cn_cred = tcred;
named.ni_cnd.cn_flags = ISLASTCN | LOCKPARENT | LOCKLEAF | SAVENAME;
named.ni_cnd.cn_flags = ISLASTCN | LOCKPARENT | LOCKLEAF;
nfsvno_setpathbuf(&named, &bufp, &hashp);
named.ni_cnd.cn_nameptr = bufp;
named.ni_cnd.cn_namelen = strlen(pf->dsf_filename);

View File

@ -1360,7 +1360,7 @@ nfsrvd_mknod(struct nfsrv_descript *nd, __unused int isdgram,
case NFFIFO:
break;
case NFDIR:
cnflags = (LOCKPARENT | SAVENAME);
cnflags = LOCKPARENT;
break;
default:
nd->nd_repstat = NFSERR_BADTYPE;
@ -1823,8 +1823,7 @@ nfsrvd_link(struct nfsrv_descript *nd, int isdgram,
NFSVOPUNLOCK(dp);
}
}
NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, CREATE,
LOCKPARENT | SAVENAME | NOCACHE);
NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, CREATE, LOCKPARENT | NOCACHE);
if (!nd->nd_repstat) {
nfsvno_setpathbuf(&named, &bufp, &hashp);
error = nfsrv_parsename(nd, bufp, hashp, &named.ni_pathlen);
@ -2018,8 +2017,7 @@ nfsrvd_mkdir(struct nfsrv_descript *nd, __unused int isdgram,
nfsrv_wcc(nd, dirfor_ret, &dirfor, diraft_ret, &diraft);
goto out;
}
NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, CREATE,
LOCKPARENT | SAVENAME | NOCACHE);
NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, CREATE, LOCKPARENT | NOCACHE);
nfsvno_setpathbuf(&named, &bufp, &hashp);
error = nfsrv_parsename(nd, bufp, hashp, &named.ni_pathlen);
if (error)

View File

@ -1241,8 +1241,6 @@ smbfs_lookup(ap)
killit = 1;
else if (error == 0
/* && vattr.va_ctime.tv_sec == VTOSMB(vp)->n_ctime*/) {
if (nameiop != LOOKUP && islastcn)
cnp->cn_flags |= SAVENAME;
SMBVDEBUG("use cached vnode\n");
return (0);
}
@ -1296,7 +1294,6 @@ smbfs_lookup(ap)
error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, td);
if (error)
goto out;
cnp->cn_flags |= SAVENAME;
error = EJUSTRETURN;
goto out;
}
@ -1321,7 +1318,6 @@ smbfs_lookup(ap)
if (error)
goto out;
*vpp = vp;
cnp->cn_flags |= SAVENAME;
goto out;
}
if (nameiop == RENAME && islastcn) {
@ -1336,7 +1332,6 @@ smbfs_lookup(ap)
if (error)
goto out;
*vpp = vp;
cnp->cn_flags |= SAVENAME;
goto out;
}
if (flags & ISDOTDOT) {

View File

@ -1051,7 +1051,6 @@ tmpfs_alloc_file(struct vnode *dvp, struct vnode **vpp, struct vattr *vap,
struct tmpfs_node *parent;
ASSERT_VOP_ELOCKED(dvp, "tmpfs_alloc_file");
MPASS(cnp->cn_flags & HASBUF);
tmp = VFS_TO_TMPFS(dvp->v_mount);
dnode = VP_TO_TMPFS_DIR(dvp);

View File

@ -140,12 +140,6 @@ tmpfs_lookup1(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp)
if (error != 0)
goto out;
/*
* Keep the component name in the buffer for
* future uses.
*/
cnp->cn_flags |= SAVENAME;
error = EJUSTRETURN;
} else
error = ENOENT;
@ -199,7 +193,6 @@ tmpfs_lookup1(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp)
*vpp = NULL;
goto out;
}
cnp->cn_flags |= SAVENAME;
} else {
error = tmpfs_alloc_vp(dvp->v_mount, tnode,
cnp->cn_lkflags, vpp);
@ -778,7 +771,6 @@ tmpfs_link(struct vop_link_args *v)
struct tmpfs_node *node;
MPASS(VOP_ISLOCKED(dvp));
MPASS(cnp->cn_flags & HASBUF);
MPASS(dvp != vp); /* XXX When can this be false? */
node = VP_TO_TMPFS_NODE(vp);
@ -971,8 +963,6 @@ tmpfs_rename(struct vop_rename_args *v)
MPASS(VOP_ISLOCKED(tdvp));
MPASS(IMPLIES(tvp != NULL, VOP_ISLOCKED(tvp)));
MPASS(fcnp->cn_flags & HASBUF);
MPASS(tcnp->cn_flags & HASBUF);
want_seqc_end = false;

View File

@ -666,7 +666,7 @@ unionfs_relookup(struct vnode *dvp, struct vnode **vpp,
cn->cn_namelen = pathlen;
cn->cn_pnbuf = path;
cn->cn_nameiop = nameiop;
cn->cn_flags = (LOCKPARENT | LOCKLEAF | HASBUF | SAVENAME | ISLASTCN);
cn->cn_flags = (LOCKPARENT | LOCKLEAF | ISLASTCN);
cn->cn_lkflags = LK_EXCLUSIVE;
cn->cn_cred = cnp->cn_cred;
cn->cn_nameptr = cn->cn_pnbuf;
@ -686,10 +686,6 @@ unionfs_relookup(struct vnode *dvp, struct vnode **vpp,
} else
vrele(dvp);
KASSERT((cn->cn_flags & HASBUF) != 0,
("%s: HASBUF cleared", __func__));
KASSERT((cn->cn_flags & SAVENAME) != 0,
("%s: SAVENAME cleared", __func__));
KASSERT(cn->cn_pnbuf == path, ("%s: cn_pnbuf changed", __func__));
return (error);
@ -716,8 +712,6 @@ unionfs_relookup_for_create(struct vnode *dvp, struct componentname *cnp,
udvp = UNIONFSVPTOUPPERVP(dvp);
vp = NULLVP;
KASSERT((cnp->cn_flags & HASBUF) != 0,
("%s called without HASBUF", __func__));
error = unionfs_relookup(udvp, &vp, cnp, &cn, td, cnp->cn_nameptr,
cnp->cn_namelen, CREATE);
if (error)
@ -752,8 +746,6 @@ unionfs_relookup_for_delete(struct vnode *dvp, struct componentname *cnp,
udvp = UNIONFSVPTOUPPERVP(dvp);
vp = NULLVP;
KASSERT((cnp->cn_flags & HASBUF) != 0,
("%s called without HASBUF", __func__));
error = unionfs_relookup(udvp, &vp, cnp, &cn, td, cnp->cn_nameptr,
cnp->cn_namelen, DELETE);
if (error)
@ -788,8 +780,6 @@ unionfs_relookup_for_rename(struct vnode *dvp, struct componentname *cnp,
udvp = UNIONFSVPTOUPPERVP(dvp);
vp = NULLVP;
KASSERT((cnp->cn_flags & HASBUF) != 0,
("%s called without HASBUF", __func__));
error = unionfs_relookup(udvp, &vp, cnp, &cn, td, cnp->cn_nameptr,
cnp->cn_namelen, RENAME);
if (error)
@ -1020,8 +1010,7 @@ unionfs_vn_create_on_upper(struct vnode **vpp, struct vnode *udvp,
nd.ni_cnd.cn_namelen = unp->un_pathlen;
nd.ni_cnd.cn_pnbuf = unp->un_path;
nd.ni_cnd.cn_nameiop = CREATE;
nd.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF | HASBUF | SAVENAME |
ISLASTCN;
nd.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF | ISLASTCN;
nd.ni_cnd.cn_lkflags = LK_EXCLUSIVE;
nd.ni_cnd.cn_cred = cred;
nd.ni_cnd.cn_nameptr = nd.ni_cnd.cn_pnbuf;
@ -1061,10 +1050,6 @@ unionfs_vn_create_on_upper(struct vnode **vpp, struct vnode *udvp,
VOP_UNLOCK(udvp);
unionfs_vn_create_on_upper_free_out2:
KASSERT((nd.ni_cnd.cn_flags & HASBUF) != 0,
("%s: HASBUF cleared", __func__));
KASSERT((nd.ni_cnd.cn_flags & SAVENAME) != 0,
("%s: SAVENAME cleared", __func__));
KASSERT(nd.ni_cnd.cn_pnbuf == unp->un_path,
("%s: cn_pnbuf changed", __func__));
@ -1290,8 +1275,7 @@ unionfs_check_rmdir(struct vnode *vp, struct ucred *cred, struct thread *td)
cn.cn_pnbuf = NULL;
cn.cn_nameptr = dp->d_name;
cn.cn_nameiop = LOOKUP;
cn.cn_flags = LOCKPARENT | LOCKLEAF | SAVENAME |
RDONLY | ISLASTCN;
cn.cn_flags = LOCKPARENT | LOCKLEAF | RDONLY | ISLASTCN;
cn.cn_lkflags = LK_EXCLUSIVE;
cn.cn_cred = cred;
@ -1312,8 +1296,7 @@ unionfs_check_rmdir(struct vnode *vp, struct ucred *cred, struct thread *td)
* If it has no exist/whiteout entry in upper,
* directory is not empty.
*/
cn.cn_flags = LOCKPARENT | LOCKLEAF | SAVENAME |
RDONLY | ISLASTCN;
cn.cn_flags = LOCKPARENT | LOCKLEAF | RDONLY | ISLASTCN;
lookuperr = VOP_LOOKUP(uvp, &tvp, &cn);
if (!lookuperr)

View File

@ -348,10 +348,6 @@ unionfs_lookup(struct vop_cachedlookup_args *ap)
unionfs_lookup_return:
/* Ensure subsequent vnops will get a valid pathname buffer. */
if (nameiop != LOOKUP && (error == 0 || error == EJUSTRETURN))
cnp->cn_flags |= SAVENAME;
UNIONFS_INTERNAL_DEBUG("unionfs_lookup: leave (%d)\n", error);
return (error);
@ -1205,11 +1201,6 @@ unionfs_rename(struct vop_rename_args *ap)
rtvp = tvp;
needrelookup = 0;
#ifdef DIAGNOSTIC
if (!(fcnp->cn_flags & HASBUF) || !(tcnp->cn_flags & HASBUF))
panic("unionfs_rename: no name");
#endif
/* check for cross device rename */
if (fvp->v_mount != tdvp->v_mount ||
(tvp != NULLVP && fvp->v_mount != tvp->v_mount)) {

View File

@ -474,7 +474,7 @@ do_execve(struct thread *td, struct image_args *args, struct mac *mac_p,
* pointer in ni_vp among other things.
*/
NDINIT(&nd, LOOKUP, ISOPEN | LOCKLEAF | LOCKSHARED | FOLLOW |
SAVENAME | AUDITVNODE1 | WANTPARENT, UIO_SYSSPACE,
AUDITVNODE1 | WANTPARENT, UIO_SYSSPACE,
args->fname);
error = namei(&nd);

View File

@ -941,7 +941,6 @@ mqfs_lookupx(struct vop_cachedlookup_args *ap)
error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, td);
if (error)
return (error);
cnp->cn_flags |= SAVENAME;
return (EJUSTRETURN);
}
return (ENOENT);
@ -997,8 +996,6 @@ mqfs_create(struct vop_create_args *ap)
if (mq == NULL)
return (EAGAIN);
sx_xlock(&mqfs->mi_lock);
if ((cnp->cn_flags & HASBUF) == 0)
panic("%s: no name", __func__);
pn = mqfs_create_file(pd, cnp->cn_nameptr, cnp->cn_namelen,
cnp->cn_cred, ap->a_vap->va_mode);
if (pn == NULL) {
@ -1492,8 +1489,6 @@ mqfs_mkdir(struct vop_mkdir_args *ap)
if (pd->mn_type != mqfstype_root && pd->mn_type != mqfstype_dir)
return (ENOTDIR);
sx_xlock(&mqfs->mi_lock);
if ((cnp->cn_flags & HASBUF) == 0)
panic("%s: no name", __func__);
pn = mqfs_create_dir(pd, cnp->cn_nameptr, cnp->cn_namelen,
ap->a_vap->cn_cred, ap->a_vap->va_mode);
if (pn != NULL)

View File

@ -593,7 +593,7 @@ uipc_bindat(int fd, struct socket *so, struct sockaddr *nam, struct thread *td)
buf[namelen] = 0;
restart:
NDINIT_ATRIGHTS(&nd, CREATE, NOFOLLOW | LOCKPARENT | SAVENAME | NOCACHE,
NDINIT_ATRIGHTS(&nd, CREATE, NOFOLLOW | LOCKPARENT | NOCACHE,
UIO_SYSSPACE, buf, fd, cap_rights_init_one(&rights, CAP_BINDAT));
/* SHOULD BE ABLE TO ADOPT EXISTING AND wakeup() ALA FIFO's */
error = namei(&nd);
@ -1919,9 +1919,9 @@ unp_connectat(int fd, struct socket *so, struct sockaddr *nam,
else
vp = nd.ni_vp;
ASSERT_VOP_LOCKED(vp, "unp_connect");
NDFREE_NOTHING(&nd);
if (error)
goto bad;
NDFREE_PNBUF(&nd);
if (vp->v_type != VSOCK) {
error = ENOTSOCK;

View File

@ -3134,7 +3134,7 @@ kern___realpathat(struct thread *td, int fd, const char *path, char *buf,
if (flags != 0)
return (EINVAL);
NDINIT_ATRIGHTS(&nd, LOOKUP, FOLLOW | SAVENAME | WANTPARENT | AUDITVNODE1,
NDINIT_ATRIGHTS(&nd, LOOKUP, FOLLOW | WANTPARENT | AUDITVNODE1,
pathseg, path, fd, &cap_fstat_rights);
if ((error = namei(&nd)) != 0)
return (error);
@ -3600,9 +3600,9 @@ vn_fullpath_any(struct vnode *vp, struct vnode *rdir, char *buf, char **retbuf,
/*
* Resolve an arbitrary vnode to a pathname (taking care of hardlinks).
*
* Since the namecache does not track hardlinks, the caller is
* expected to first look up the target vnode with SAVENAME |
* WANTPARENT flags passed to namei to get dvp and vp.
* Since the namecache does not track hardlinks, the caller is expected to
* first look up the target vnode with WANTPARENT flag passed to namei to get
* dvp and vp.
*
* Then we have 2 cases:
* - if the found vnode is a directory, the path can be constructed just by
@ -3928,7 +3928,6 @@ struct cache_fpl {
enum cache_fpl_status status:8;
bool in_smr;
bool fsearch;
bool savename;
struct pwd **pwd;
#ifdef INVARIANTS
struct cache_fpl_debug debug;
@ -3951,10 +3950,8 @@ cache_fpl_cleanup_cnp(struct componentname *cnp)
{
uma_zfree(namei_zone, cnp->cn_pnbuf);
#ifdef DIAGNOSTIC
cnp->cn_pnbuf = NULL;
cnp->cn_nameptr = NULL;
#endif
}
static struct vnode *
@ -4166,7 +4163,6 @@ cache_fpl_handled_error_impl(struct cache_fpl *fpl, int error, int line)
fpl->line = line;
fpl->dvp = NULL;
fpl->tvp = NULL;
fpl->savename = false;
return (error);
}
@ -4181,9 +4177,9 @@ cache_fpl_terminated(struct cache_fpl *fpl)
#define CACHE_FPL_SUPPORTED_CN_FLAGS \
(NC_NOMAKEENTRY | NC_KEEPPOSENTRY | LOCKLEAF | LOCKPARENT | WANTPARENT | \
FAILIFEXISTS | FOLLOW | EMPTYPATH | LOCKSHARED | SAVENAME | SAVESTART | \
WILLBEDIR | ISOPEN | NOMACCHECK | AUDITVNODE1 | AUDITVNODE2 | NOCAPCHECK | \
OPENREAD | OPENWRITE | WANTIOCTLCAPS)
FAILIFEXISTS | FOLLOW | EMPTYPATH | LOCKSHARED | SAVESTART | WILLBEDIR | \
ISOPEN | NOMACCHECK | AUDITVNODE1 | AUDITVNODE2 | NOCAPCHECK | OPENREAD | \
OPENWRITE | WANTIOCTLCAPS)
#define CACHE_FPL_INTERNAL_CN_FLAGS \
(ISDOTDOT | MAKEENTRY | ISLASTCN)
@ -4530,14 +4526,11 @@ cache_fplookup_final_modifying(struct cache_fpl *fpl)
}
fpl->tvp = tvp;
fpl->savename = (cnp->cn_flags & SAVENAME) != 0;
if (tvp == NULL) {
if ((cnp->cn_flags & SAVESTART) != 0) {
ndp->ni_startdir = dvp;
vrefact(ndp->ni_startdir);
cnp->cn_flags |= SAVENAME;
fpl->savename = true;
}
MPASS(error == EJUSTRETURN);
if ((cnp->cn_flags & LOCKPARENT) == 0) {
@ -4598,8 +4591,6 @@ cache_fplookup_final_modifying(struct cache_fpl *fpl)
if ((cnp->cn_flags & SAVESTART) != 0) {
ndp->ni_startdir = dvp;
vrefact(ndp->ni_startdir);
cnp->cn_flags |= SAVENAME;
fpl->savename = true;
}
return (cache_fpl_handled(fpl));
@ -4944,9 +4935,6 @@ cache_fplookup_noentry(struct cache_fpl *fpl)
}
fpl->tvp = tvp;
if (!fpl->savename) {
MPASS((cnp->cn_flags & SAVENAME) == 0);
}
if (tvp == NULL) {
MPASS(error == EJUSTRETURN);
@ -6080,7 +6068,6 @@ cache_fplookup(struct nameidata *ndp, enum cache_fpl_status *status,
#endif
fpl.nulchar = &cnp->cn_nameptr[ndp->ni_pathlen - 1];
fpl.fsearch = false;
fpl.savename = (cnp->cn_flags & SAVENAME) != 0;
fpl.tvp = NULL; /* for degenerate path handling */
fpl.pwd = pwdp;
pwd = pwd_get_smr();
@ -6119,17 +6106,12 @@ cache_fplookup(struct nameidata *ndp, enum cache_fpl_status *status,
if (__predict_true(fpl.status == CACHE_FPL_STATUS_HANDLED)) {
MPASS(error != CACHE_FPL_FAILED);
if (error != 0) {
cache_fpl_cleanup_cnp(fpl.cnp);
MPASS(fpl.dvp == NULL);
MPASS(fpl.tvp == NULL);
MPASS(fpl.savename == false);
}
ndp->ni_dvp = fpl.dvp;
ndp->ni_vp = fpl.tvp;
if (fpl.savename) {
cnp->cn_flags |= HASBUF;
} else {
cache_fpl_cleanup_cnp(cnp);
}
}
return (error);
}

View File

@ -75,11 +75,12 @@ __FBSDID("$FreeBSD$");
#undef NAMEI_DIAGNOSTIC
#ifdef INVARIANTS
static void NDVALIDATE(struct nameidata *);
#else
#define NDVALIDATE(ndp) do { } while (0)
static void NDVALIDATE_impl(struct nameidata *, int);
#endif
#define NDVALIDATE(ndp) NDVALIDATE_impl(ndp, __LINE__)
SDT_PROVIDER_DEFINE(vfs);
SDT_PROBE_DEFINE4(vfs, namei, lookup, entry, "struct vnode *", "char *",
"unsigned long", "bool");
@ -260,10 +261,8 @@ namei_cleanup_cnp(struct componentname *cnp)
{
uma_zfree(namei_zone, cnp->cn_pnbuf);
#ifdef DIAGNOSTIC
cnp->cn_pnbuf = NULL;
cnp->cn_nameptr = NULL;
#endif
}
static int
@ -439,7 +438,6 @@ namei_emptypath(struct nameidata *ndp)
ndp->ni_resflags |= NIRES_EMPTYPATH;
error = namei_setup(ndp, &dp, &pwd);
if (error != 0) {
namei_cleanup_cnp(cnp);
goto errout;
}
@ -447,7 +445,6 @@ namei_emptypath(struct nameidata *ndp)
* Usecount on dp already provided by namei_setup.
*/
ndp->ni_vp = dp;
namei_cleanup_cnp(cnp);
pwd_drop(pwd);
NDVALIDATE(ndp);
if ((cnp->cn_flags & LOCKLEAF) != 0) {
@ -464,6 +461,7 @@ namei_emptypath(struct nameidata *ndp)
errout:
SDT_PROBE4(vfs, namei, lookup, return, error, NULL, false, ndp);
namei_cleanup_cnp(cnp);
return (error);
}
@ -585,13 +583,6 @@ namei(struct nameidata *ndp)
("%s: FAILIFEXISTS must be passed with LOCKPARENT and without LOCKLEAF",
__func__));
}
/*
* For NDVALIDATE.
*
* While NDINIT may seem like a more natural place to do it, there are
* callers which directly modify flags past invoking init.
*/
cnp->cn_origflags = cnp->cn_flags;
#endif
ndp->ni_cnd.cn_cred = td->td_ucred;
KASSERT(ndp->ni_resflags == 0, ("%s: garbage in ni_resflags: %x\n",
@ -689,10 +680,6 @@ namei(struct nameidata *ndp)
if ((cnp->cn_flags & ISSYMLINK) == 0) {
SDT_PROBE4(vfs, namei, lookup, return, error,
ndp->ni_vp, false, ndp);
if ((cnp->cn_flags & (SAVENAME | SAVESTART)) == 0) {
namei_cleanup_cnp(cnp);
} else
cnp->cn_flags |= HASBUF;
nameicap_cleanup(ndp);
pwd_drop(pwd);
NDVALIDATE(ndp);
@ -996,9 +983,7 @@ vfs_lookup(struct nameidata *ndp)
* Search a new directory.
*
* The last component of the filename is left accessible via
* cnp->cn_nameptr for callers that need the name. Callers needing
* the name set the SAVENAME flag. When done, they assume
* responsibility for freeing the pathname buffer.
* cnp->cn_nameptr. It has to be freed with a call to NDFREE*.
*
* Store / as a temporary sentinel so that we only have one character
* to test for. Pathnames tend to be short so this should not be
@ -1443,10 +1428,7 @@ vfs_relookup(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp)
/*
* Search a new directory.
*
* The last component of the filename is left accessible via
* cnp->cn_nameptr for callers that need the name. Callers needing
* the name set the SAVENAME flag. When done, they assume
* responsibility for freeing the pathname buffer.
* See a comment in vfs_lookup for cnp->cn_nameptr.
*/
#ifdef NAMEI_DIAGNOSTIC
printf("{%s}: ", cnp->cn_nameptr);
@ -1545,47 +1527,6 @@ vfs_relookup(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp)
return (error);
}
/*
* Free data allocated by namei(); see namei(9) for details.
*/
void
NDFREE_PNBUF(struct nameidata *ndp)
{
if ((ndp->ni_cnd.cn_flags & HASBUF) != 0) {
MPASS((ndp->ni_cnd.cn_flags & (SAVENAME | SAVESTART)) != 0);
uma_zfree(namei_zone, ndp->ni_cnd.cn_pnbuf);
ndp->ni_cnd.cn_flags &= ~HASBUF;
}
}
/*
* NDFREE_PNBUF replacement for callers that know there is no buffer.
*
* This is a hack. Preferably the VFS layer would not produce anything more
* than it was asked to do. Unfortunately several non-LOOKUP cases can add the
* HASBUF flag to the result. Even then an interface could be implemented where
* the caller specifies what they expected to see in the result and what they
* are going to take care of.
*
* In the meantime provide this kludge as a trivial replacement for NDFREE_PNBUF
* calls scattered throughout the kernel where we know for a fact the flag must not
* be seen.
*/
#ifdef INVARIANTS
void
NDFREE_NOTHING(struct nameidata *ndp)
{
struct componentname *cnp;
cnp = &ndp->ni_cnd;
KASSERT(cnp->cn_nameiop == LOOKUP, ("%s: got non-LOOKUP op %d\n",
__func__, cnp->cn_nameiop));
KASSERT((cnp->cn_flags & (SAVENAME | HASBUF)) == 0,
("%s: bad flags \%" PRIx64 "\n", __func__, cnp->cn_flags));
}
#endif
void
(NDFREE)(struct nameidata *ndp, const u_int flags)
{
@ -1636,63 +1577,17 @@ void
#ifdef INVARIANTS
/*
* Validate the final state of ndp after the lookup.
*
* Historically filesystems were allowed to modify cn_flags. Most notably they
* can add SAVENAME to the request, resulting in HASBUF and pushing subsequent
* clean up to the consumer. In practice this seems to only concern != LOOKUP
* operations.
*
* As a step towards stricter API contract this routine validates the state to
* clean up. Note validation is a work in progress with the intent of becoming
* stricter over time.
*/
#define NDMODIFYINGFLAGS (LOCKLEAF | LOCKPARENT | WANTPARENT | SAVENAME | SAVESTART | HASBUF)
static void
NDVALIDATE(struct nameidata *ndp)
NDVALIDATE_impl(struct nameidata *ndp, int line)
{
struct componentname *cnp;
uint64_t used, orig;
cnp = &ndp->ni_cnd;
orig = cnp->cn_origflags;
used = cnp->cn_flags;
switch (cnp->cn_nameiop) {
case LOOKUP:
/*
* For plain lookup we require strict conformance -- nothing
* to clean up if it was not requested by the caller.
*/
orig &= NDMODIFYINGFLAGS;
used &= NDMODIFYINGFLAGS;
if ((orig & (SAVENAME | SAVESTART)) != 0)
orig |= HASBUF;
if (orig != used) {
goto out_mismatch;
}
break;
case CREATE:
case DELETE:
case RENAME:
/*
* Some filesystems set SAVENAME to provoke HASBUF, accommodate
* for it until it gets fixed.
*/
orig &= NDMODIFYINGFLAGS;
orig |= (SAVENAME | HASBUF);
used &= NDMODIFYINGFLAGS;
used |= (SAVENAME | HASBUF);
if (orig != used) {
goto out_mismatch;
}
break;
}
return;
out_mismatch:
panic("%s: mismatched flags for op %d: added %" PRIx64 ", "
"removed %" PRIx64" (%" PRIx64" != %" PRIx64"; stored %" PRIx64" != %" PRIx64")",
__func__, cnp->cn_nameiop, used & ~orig, orig &~ used,
orig, used, cnp->cn_origflags, cnp->cn_flags);
if (cnp->cn_pnbuf == NULL)
panic("%s: got no buf! called from %d", __func__, line);
}
#endif
/*

View File

@ -395,7 +395,7 @@ sysctl_try_reclaim_vnode(SYSCTL_HANDLER_ARGS)
buf[req->newlen] = '\0';
ndflags = LOCKLEAF | NOFOLLOW | AUDITVNODE1 | SAVENAME;
ndflags = LOCKLEAF | NOFOLLOW | AUDITVNODE1;
NDINIT(&nd, LOOKUP, ndflags, UIO_SYSSPACE, buf);
if ((error = namei(&nd)) != 0)
goto out;

View File

@ -338,8 +338,8 @@ kern_statfs(struct thread *td, const char *path, enum uio_seg pathseg,
error = namei(&nd);
if (error != 0)
return (error);
NDFREE_PNBUF(&nd);
mp = vfs_ref_from_vp(nd.ni_vp);
NDFREE_NOTHING(&nd);
vrele(nd.ni_vp);
return (kern_do_statfs(td, mp, buf));
}
@ -957,11 +957,11 @@ kern_chdir(struct thread *td, const char *path, enum uio_seg pathseg)
return (error);
if ((error = change_dir(nd.ni_vp, td)) != 0) {
vput(nd.ni_vp);
NDFREE_NOTHING(&nd);
NDFREE_PNBUF(&nd);
return (error);
}
VOP_UNLOCK(nd.ni_vp);
NDFREE_NOTHING(&nd);
NDFREE_PNBUF(&nd);
pwd_chdir(td, nd.ni_vp);
return (0);
}
@ -1001,7 +1001,7 @@ sys_chroot(struct thread *td, struct chroot_args *uap)
error = namei(&nd);
if (error != 0)
return (error);
NDFREE_NOTHING(&nd);
NDFREE_PNBUF(&nd);
error = change_dir(nd.ni_vp, td);
if (error != 0)
goto e_vunlock;
@ -1352,8 +1352,8 @@ kern_mknodat(struct thread *td, int fd, const char *path, enum uio_seg pathseg,
NDPREINIT(&nd);
restart:
bwillwrite();
NDINIT_ATRIGHTS(&nd, CREATE, LOCKPARENT | SAVENAME | AUDITVNODE1 |
NOCACHE, pathseg, path, fd, &cap_mknodat_rights);
NDINIT_ATRIGHTS(&nd, CREATE, LOCKPARENT | AUDITVNODE1 | NOCACHE,
pathseg, path, fd, &cap_mknodat_rights);
if ((error = namei(&nd)) != 0)
return (error);
vp = nd.ni_vp;
@ -1460,8 +1460,8 @@ kern_mkfifoat(struct thread *td, int fd, const char *path,
NDPREINIT(&nd);
restart:
bwillwrite();
NDINIT_ATRIGHTS(&nd, CREATE, LOCKPARENT | SAVENAME | AUDITVNODE1 |
NOCACHE, pathseg, path, fd, &cap_mkfifoat_rights);
NDINIT_ATRIGHTS(&nd, CREATE, LOCKPARENT | AUDITVNODE1 | NOCACHE,
pathseg, path, fd, &cap_mkfifoat_rights);
if ((error = namei(&nd)) != 0)
return (error);
if (nd.ni_vp != NULL) {
@ -1619,7 +1619,7 @@ kern_linkat_vp(struct thread *td, struct vnode *vp, int fd, const char *path,
return (EPERM); /* POSIX */
}
NDINIT_ATRIGHTS(&nd, CREATE,
LOCKPARENT | SAVENAME | AUDITVNODE2 | NOCACHE, segflag, path, fd,
LOCKPARENT | AUDITVNODE2 | NOCACHE, segflag, path, fd,
&cap_linkat_target_rights);
if ((error = namei(&nd)) == 0) {
if (nd.ni_vp != NULL) {
@ -1737,8 +1737,8 @@ kern_symlinkat(struct thread *td, const char *path1, int fd, const char *path2,
NDPREINIT(&nd);
restart:
bwillwrite();
NDINIT_ATRIGHTS(&nd, CREATE, LOCKPARENT | SAVENAME | AUDITVNODE1 |
NOCACHE, segflg, path2, fd, &cap_symlinkat_rights);
NDINIT_ATRIGHTS(&nd, CREATE, LOCKPARENT | AUDITVNODE1 | NOCACHE, segflg,
path2, fd, &cap_symlinkat_rights);
if ((error = namei(&nd)) != 0)
goto out;
if (nd.ni_vp) {
@ -2149,7 +2149,7 @@ kern_accessat(struct thread *td, int fd, const char *path,
vp = nd.ni_vp;
error = vn_access(vp, amode, usecred, td);
NDFREE_NOTHING(&nd);
NDFREE_PNBUF(&nd);
vput(vp);
out:
if (usecred != cred) {
@ -2453,7 +2453,7 @@ kern_statat(struct thread *td, int flag, int fd, const char *path,
hook(nd.ni_vp, sbp);
}
}
NDFREE_NOTHING(&nd);
NDFREE_PNBUF(&nd);
vput(nd.ni_vp);
#ifdef __STAT_TIME_T_EXT
sbp->st_atim_ext = 0;
@ -2604,7 +2604,7 @@ kern_pathconf(struct thread *td, const char *path, enum uio_seg pathseg,
pathseg, path);
if ((error = namei(&nd)) != 0)
return (error);
NDFREE_NOTHING(&nd);
NDFREE_PNBUF(&nd);
error = VOP_PATHCONF(nd.ni_vp, name, valuep);
vput(nd.ni_vp);
@ -2660,7 +2660,7 @@ kern_readlinkat(struct thread *td, int fd, const char *path,
if ((error = namei(&nd)) != 0)
return (error);
NDFREE_NOTHING(&nd);
NDFREE_PNBUF(&nd);
vp = nd.ni_vp;
error = kern_readlink_vp(vp, buf, bufseg, count, td);
@ -2811,7 +2811,7 @@ kern_chflagsat(struct thread *td, int fd, const char *path,
fd, &cap_fchflags_rights);
if ((error = namei(&nd)) != 0)
return (error);
NDFREE_NOTHING(&nd);
NDFREE_PNBUF(&nd);
error = setfflags(td, nd.ni_vp, flags);
vrele(nd.ni_vp);
return (error);
@ -2942,7 +2942,7 @@ kern_fchmodat(struct thread *td, int fd, const char *path,
fd, &cap_fchmod_rights);
if ((error = namei(&nd)) != 0)
return (error);
NDFREE_NOTHING(&nd);
NDFREE_PNBUF(&nd);
error = setfmode(td, td->td_ucred, nd.ni_vp, mode);
vrele(nd.ni_vp);
return (error);
@ -3055,7 +3055,7 @@ kern_fchownat(struct thread *td, int fd, const char *path,
if ((error = namei(&nd)) != 0)
return (error);
NDFREE_NOTHING(&nd);
NDFREE_PNBUF(&nd);
error = setfown(td, td->td_ucred, nd.ni_vp, uid, gid);
vrele(nd.ni_vp);
return (error);
@ -3272,7 +3272,7 @@ kern_utimesat(struct thread *td, int fd, const char *path,
if ((error = namei(&nd)) != 0)
return (error);
NDFREE_NOTHING(&nd);
NDFREE_PNBUF(&nd);
error = setutimes(td, nd.ni_vp, ts, 2, tptr == NULL);
vrele(nd.ni_vp);
return (error);
@ -3308,7 +3308,7 @@ kern_lutimes(struct thread *td, const char *path, enum uio_seg pathseg,
NDINIT(&nd, LOOKUP, NOFOLLOW | AUDITVNODE1, pathseg, path);
if ((error = namei(&nd)) != 0)
return (error);
NDFREE_NOTHING(&nd);
NDFREE_PNBUF(&nd);
error = setutimes(td, nd.ni_vp, ts, 2, tptr == NULL);
vrele(nd.ni_vp);
return (error);
@ -3427,7 +3427,7 @@ kern_utimensat(struct thread *td, int fd, const char *path,
* "If both tv_nsec fields are UTIME_OMIT... EACCESS may be detected."
* "Search permission is denied by a component of the path prefix."
*/
NDFREE_NOTHING(&nd);
NDFREE_PNBUF(&nd);
if ((flags & UTIMENS_EXIT) == 0)
error = setutimes(td, nd.ni_vp, ts, 2, flags & UTIMENS_NULL);
vrele(nd.ni_vp);
@ -3469,7 +3469,7 @@ kern_truncate(struct thread *td, const char *path, enum uio_seg pathseg,
if ((error = namei(&nd)) != 0)
return (error);
vp = nd.ni_vp;
NDFREE_NOTHING(&nd);
NDFREE_PNBUF(&nd);
rl_cookie = vn_rangelock_wlock(vp, 0, OFF_MAX);
if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0) {
vn_rangelock_unlock(vp, rl_cookie);
@ -3831,7 +3831,7 @@ kern_mkdirat(struct thread *td, int fd, const char *path, enum uio_seg segflg,
NDPREINIT(&nd);
restart:
bwillwrite();
NDINIT_ATRIGHTS(&nd, CREATE, LOCKPARENT | SAVENAME | AUDITVNODE1 |
NDINIT_ATRIGHTS(&nd, CREATE, LOCKPARENT | AUDITVNODE1 |
NC_NOMAKEENTRY | NC_KEEPPOSENTRY | FAILIFEXISTS | WILLBEDIR,
segflg, path, fd, &cap_mkdirat_rights);
if ((error = namei(&nd)) != 0)
@ -4284,7 +4284,7 @@ sys_revoke(struct thread *td, struct revoke_args *uap)
if ((error = namei(&nd)) != 0)
return (error);
vp = nd.ni_vp;
NDFREE_NOTHING(&nd);
NDFREE_PNBUF(&nd);
if (vp->v_type != VCHR || vp->v_rdev == NULL) {
error = EINVAL;
goto out;
@ -4448,7 +4448,7 @@ kern_getfhat(struct thread *td, int flags, int fd, const char *path,
error = namei(&nd);
if (error != 0)
return (error);
NDFREE_NOTHING(&nd);
NDFREE_PNBUF(&nd);
vp = nd.ni_vp;
bzero(&fh, sizeof(fh));
fh.fh_fsid = vp->v_mount->mnt_stat.f_fsid;

View File

@ -158,20 +158,9 @@ int cache_fplookup(struct nameidata *ndp, enum cache_fpl_status *status,
/*
* Namei parameter descriptors.
*
* SAVENAME may be set by either the callers of namei or by VOP_LOOKUP.
* If the caller of namei sets the flag (for example execve wants to
* know the name of the program that is being executed), then it must
* free the buffer. If VOP_LOOKUP sets the flag, then the buffer must
* be freed by either the commit routine or the VOP_ABORT routine.
* SAVESTART is set only by the callers of namei. It implies SAVENAME
* plus the addition of saving the parent directory that contains the
* name in ni_startdir. It allows repeated calls to lookup for the
* name being sought. The caller is responsible for releasing the
* buffer and for vrele'ing ni_startdir.
*/
#define RDONLY 0x00000200 /* lookup with read-only semantics */
#define SAVENAME 0x00000400 /* save pathname buffer */
/* UNUSED 0x00000400 */
#define SAVESTART 0x00000800 /* save starting directory */
#define ISWHITEOUT 0x00001000 /* found whiteout */
#define DOWHITEOUT 0x00002000 /* do whiteouts */
@ -185,7 +174,7 @@ int cache_fplookup(struct nameidata *ndp, enum cache_fpl_status *status,
#define OPENREAD 0x00200000 /* open for reading */
#define OPENWRITE 0x00400000 /* open for writing */
#define WANTIOCTLCAPS 0x00800000 /* leave ioctl caps for the caller */
#define HASBUF 0x01000000 /* has allocated pathname buffer */
/* UNUSED 0x01000000 */
#define NOEXECCHECK 0x02000000 /* do not perform exec check on dir */
#define MAKEENTRY 0x04000000 /* entry is to be added to name cache */
#define ISSYMLINK 0x08000000 /* symlink needs interpretation */
@ -198,7 +187,7 @@ int cache_fplookup(struct nameidata *ndp, enum cache_fpl_status *status,
* Flags which must not be passed in by callers.
*/
#define NAMEI_INTERNAL_FLAGS \
(HASBUF | NOEXECCHECK | MAKEENTRY | ISSYMLINK | ISLASTCN | ISDOTDOT | \
(NOEXECCHECK | MAKEENTRY | ISSYMLINK | ISLASTCN | ISDOTDOT | \
TRAILINGSLASH)
/*
@ -293,14 +282,15 @@ do { \
struct nameidata *_ndp = (ndp); \
filecaps_free(&_ndp->ni_filecaps); \
} while (0)
void NDFREE_PNBUF(struct nameidata *);
void NDFREE(struct nameidata *, const u_int);
#ifdef INVARIANTS
void NDFREE_NOTHING(struct nameidata *);
#else
#define NDFREE_NOTHING(ndp) do { } while (0)
#endif
#define NDFREE_PNBUF(ndp) do { \
struct nameidata *_ndp = (ndp); \
MPASS(_ndp->ni_cnd.cn_pnbuf != NULL); \
uma_zfree(namei_zone, _ndp->ni_cnd.cn_pnbuf); \
_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);

View File

@ -76,7 +76,7 @@
* cannot include sys/param.h and should only be updated here.
*/
#undef __FreeBSD_version
#define __FreeBSD_version 1400067
#define __FreeBSD_version 1400068
/*
* __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,

View File

@ -524,13 +524,10 @@ ufs_lookup_ino(struct vnode *vdp, struct vnode **vpp, struct componentname *cnp,
* We return ni_vp == NULL to indicate that the entry
* does not currently exist; we leave a pointer to
* the (locked) directory inode in ndp->ni_dvp.
* The pathname buffer is saved so that the name
* can be obtained later.
*
* NB - if the directory is unlocked, then this
* information cannot be used.
*/
cnp->cn_flags |= SAVENAME;
return (EJUSTRETURN);
}
/*
@ -670,7 +667,6 @@ ufs_lookup_ino(struct vnode *vdp, struct vnode **vpp, struct componentname *cnp,
#endif
*vpp = tdp;
cnp->cn_flags |= SAVENAME;
return (0);
}
if (dd_ino != NULL)
@ -830,8 +826,6 @@ ufs_makedirentry(struct inode *ip, struct componentname *cnp,
u_int namelen;
namelen = (unsigned)cnp->cn_namelen;
KASSERT((cnp->cn_flags & SAVENAME) != 0,
("ufs_makedirentry: missing name"));
KASSERT(namelen <= UFS_MAXNAMLEN,
("ufs_makedirentry: name too long"));
newdirp->d_ino = ip->i_number;

View File

@ -1099,11 +1099,6 @@ ufs_link(
struct direct newdir;
int error;
#ifdef INVARIANTS
if ((cnp->cn_flags & HASBUF) == 0)
panic("ufs_link: no name");
#endif
if (DOINGSUJ(tdvp)) {
error = softdep_prelink(tdvp, vp, cnp);
if (error != 0) {
@ -1194,8 +1189,6 @@ ufs_whiteout(
case CREATE:
/* create a new directory whiteout */
#ifdef INVARIANTS
if ((cnp->cn_flags & SAVENAME) == 0)
panic("ufs_whiteout: missing name");
if (OFSFMT(dvp))
panic("ufs_whiteout: old format filesystem");
#endif
@ -1283,11 +1276,6 @@ ufs_rename(
checkpath_locked = want_seqc_end = false;
#ifdef INVARIANTS
if ((tcnp->cn_flags & HASBUF) == 0 ||
(fcnp->cn_flags & HASBUF) == 0)
panic("ufs_rename: no name");
#endif
endoff = 0;
mp = tdvp->v_mount;
VOP_UNLOCK(tdvp);
@ -2020,10 +2008,6 @@ ufs_mkdir(
int error, dmode;
long blkoff;
#ifdef INVARIANTS
if ((cnp->cn_flags & HASBUF) == 0)
panic("ufs_mkdir: no name");
#endif
dp = VTOI(dvp);
error = ufs_sync_nlink(dvp, NULL);
if (error != 0)
@ -2789,10 +2773,6 @@ ufs_makeinode(int mode, struct vnode *dvp, struct vnode **vpp,
int error;
pdir = VTOI(dvp);
#ifdef INVARIANTS
if ((cnp->cn_flags & HASBUF) == 0)
panic("%s: no name", callfunc);
#endif
*vpp = NULL;
if ((mode & IFMT) == 0)
mode |= IFREG;