vfs: add NDFREE_NOTHING and convert several NDFREE_PNBUF callers
Check the comment above the routine for reasoning.
This commit is contained in:
parent
6b3a9a0f3d
commit
cdb62ab74e
@ -1568,7 +1568,7 @@ unp_connectat(int fd, struct socket *so, struct sockaddr *nam,
|
|||||||
else
|
else
|
||||||
vp = nd.ni_vp;
|
vp = nd.ni_vp;
|
||||||
ASSERT_VOP_LOCKED(vp, "unp_connect");
|
ASSERT_VOP_LOCKED(vp, "unp_connect");
|
||||||
NDFREE(&nd, NDF_ONLY_PNBUF);
|
NDFREE_NOTHING(&nd);
|
||||||
if (error)
|
if (error)
|
||||||
goto bad;
|
goto bad;
|
||||||
|
|
||||||
|
@ -1487,6 +1487,33 @@ NDFREE_PNBUF(struct nameidata *ndp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
void
|
||||||
(NDFREE)(struct nameidata *ndp, const u_int flags)
|
(NDFREE)(struct nameidata *ndp, const u_int flags)
|
||||||
{
|
{
|
||||||
|
@ -340,7 +340,7 @@ kern_statfs(struct thread *td, const char *path, enum uio_seg pathseg,
|
|||||||
return (error);
|
return (error);
|
||||||
mp = nd.ni_vp->v_mount;
|
mp = nd.ni_vp->v_mount;
|
||||||
vfs_ref(mp);
|
vfs_ref(mp);
|
||||||
NDFREE(&nd, NDF_ONLY_PNBUF);
|
NDFREE_NOTHING(&nd);
|
||||||
vput(nd.ni_vp);
|
vput(nd.ni_vp);
|
||||||
return (kern_do_statfs(td, mp, buf));
|
return (kern_do_statfs(td, mp, buf));
|
||||||
}
|
}
|
||||||
@ -949,11 +949,11 @@ kern_chdir(struct thread *td, const char *path, enum uio_seg pathseg)
|
|||||||
return (error);
|
return (error);
|
||||||
if ((error = change_dir(nd.ni_vp, td)) != 0) {
|
if ((error = change_dir(nd.ni_vp, td)) != 0) {
|
||||||
vput(nd.ni_vp);
|
vput(nd.ni_vp);
|
||||||
NDFREE(&nd, NDF_ONLY_PNBUF);
|
NDFREE_NOTHING(&nd);
|
||||||
return (error);
|
return (error);
|
||||||
}
|
}
|
||||||
VOP_UNLOCK(nd.ni_vp);
|
VOP_UNLOCK(nd.ni_vp);
|
||||||
NDFREE(&nd, NDF_ONLY_PNBUF);
|
NDFREE_NOTHING(&nd);
|
||||||
pwd_chdir(td, nd.ni_vp);
|
pwd_chdir(td, nd.ni_vp);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@ -991,12 +991,12 @@ sys_chroot(struct thread *td, struct chroot_args *uap)
|
|||||||
VOP_UNLOCK(nd.ni_vp);
|
VOP_UNLOCK(nd.ni_vp);
|
||||||
error = pwd_chroot(td, nd.ni_vp);
|
error = pwd_chroot(td, nd.ni_vp);
|
||||||
vrele(nd.ni_vp);
|
vrele(nd.ni_vp);
|
||||||
NDFREE(&nd, NDF_ONLY_PNBUF);
|
NDFREE_NOTHING(&nd);
|
||||||
return (error);
|
return (error);
|
||||||
e_vunlock:
|
e_vunlock:
|
||||||
vput(nd.ni_vp);
|
vput(nd.ni_vp);
|
||||||
error:
|
error:
|
||||||
NDFREE(&nd, NDF_ONLY_PNBUF);
|
NDFREE_NOTHING(&nd);
|
||||||
return (error);
|
return (error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2118,7 +2118,7 @@ kern_accessat(struct thread *td, int fd, const char *path,
|
|||||||
vp = nd.ni_vp;
|
vp = nd.ni_vp;
|
||||||
|
|
||||||
error = vn_access(vp, amode, usecred, td);
|
error = vn_access(vp, amode, usecred, td);
|
||||||
NDFREE(&nd, NDF_ONLY_PNBUF);
|
NDFREE_NOTHING(&nd);
|
||||||
vput(vp);
|
vput(vp);
|
||||||
out:
|
out:
|
||||||
if (usecred != cred) {
|
if (usecred != cred) {
|
||||||
@ -2417,7 +2417,7 @@ kern_statat(struct thread *td, int flag, int fd, const char *path,
|
|||||||
if (__predict_false(hook != NULL))
|
if (__predict_false(hook != NULL))
|
||||||
hook(nd.ni_vp, sbp);
|
hook(nd.ni_vp, sbp);
|
||||||
}
|
}
|
||||||
NDFREE(&nd, NDF_ONLY_PNBUF);
|
NDFREE_NOTHING(&nd);
|
||||||
vput(nd.ni_vp);
|
vput(nd.ni_vp);
|
||||||
#ifdef __STAT_TIME_T_EXT
|
#ifdef __STAT_TIME_T_EXT
|
||||||
sbp->st_atim_ext = 0;
|
sbp->st_atim_ext = 0;
|
||||||
@ -2557,7 +2557,7 @@ kern_pathconf(struct thread *td, const char *path, enum uio_seg pathseg,
|
|||||||
pathseg, path, td);
|
pathseg, path, td);
|
||||||
if ((error = namei(&nd)) != 0)
|
if ((error = namei(&nd)) != 0)
|
||||||
return (error);
|
return (error);
|
||||||
NDFREE(&nd, NDF_ONLY_PNBUF);
|
NDFREE_NOTHING(&nd);
|
||||||
|
|
||||||
error = VOP_PATHCONF(nd.ni_vp, name, valuep);
|
error = VOP_PATHCONF(nd.ni_vp, name, valuep);
|
||||||
vput(nd.ni_vp);
|
vput(nd.ni_vp);
|
||||||
@ -2613,7 +2613,7 @@ kern_readlinkat(struct thread *td, int fd, const char *path,
|
|||||||
|
|
||||||
if ((error = namei(&nd)) != 0)
|
if ((error = namei(&nd)) != 0)
|
||||||
return (error);
|
return (error);
|
||||||
NDFREE(&nd, NDF_ONLY_PNBUF);
|
NDFREE_NOTHING(&nd);
|
||||||
vp = nd.ni_vp;
|
vp = nd.ni_vp;
|
||||||
|
|
||||||
error = kern_readlink_vp(vp, buf, bufseg, count, td);
|
error = kern_readlink_vp(vp, buf, bufseg, count, td);
|
||||||
@ -2764,7 +2764,7 @@ kern_chflagsat(struct thread *td, int fd, const char *path,
|
|||||||
&cap_fchflags_rights, td);
|
&cap_fchflags_rights, td);
|
||||||
if ((error = namei(&nd)) != 0)
|
if ((error = namei(&nd)) != 0)
|
||||||
return (error);
|
return (error);
|
||||||
NDFREE(&nd, NDF_ONLY_PNBUF);
|
NDFREE_NOTHING(&nd);
|
||||||
error = setfflags(td, nd.ni_vp, flags);
|
error = setfflags(td, nd.ni_vp, flags);
|
||||||
vrele(nd.ni_vp);
|
vrele(nd.ni_vp);
|
||||||
return (error);
|
return (error);
|
||||||
@ -2893,7 +2893,7 @@ kern_fchmodat(struct thread *td, int fd, const char *path,
|
|||||||
&cap_fchmod_rights, td);
|
&cap_fchmod_rights, td);
|
||||||
if ((error = namei(&nd)) != 0)
|
if ((error = namei(&nd)) != 0)
|
||||||
return (error);
|
return (error);
|
||||||
NDFREE(&nd, NDF_ONLY_PNBUF);
|
NDFREE_NOTHING(&nd);
|
||||||
error = setfmode(td, td->td_ucred, nd.ni_vp, mode);
|
error = setfmode(td, td->td_ucred, nd.ni_vp, mode);
|
||||||
vrele(nd.ni_vp);
|
vrele(nd.ni_vp);
|
||||||
return (error);
|
return (error);
|
||||||
@ -3006,7 +3006,7 @@ kern_fchownat(struct thread *td, int fd, const char *path,
|
|||||||
|
|
||||||
if ((error = namei(&nd)) != 0)
|
if ((error = namei(&nd)) != 0)
|
||||||
return (error);
|
return (error);
|
||||||
NDFREE(&nd, NDF_ONLY_PNBUF);
|
NDFREE_NOTHING(&nd);
|
||||||
error = setfown(td, td->td_ucred, nd.ni_vp, uid, gid);
|
error = setfown(td, td->td_ucred, nd.ni_vp, uid, gid);
|
||||||
vrele(nd.ni_vp);
|
vrele(nd.ni_vp);
|
||||||
return (error);
|
return (error);
|
||||||
@ -3219,7 +3219,7 @@ kern_utimesat(struct thread *td, int fd, const char *path,
|
|||||||
|
|
||||||
if ((error = namei(&nd)) != 0)
|
if ((error = namei(&nd)) != 0)
|
||||||
return (error);
|
return (error);
|
||||||
NDFREE(&nd, NDF_ONLY_PNBUF);
|
NDFREE_NOTHING(&nd);
|
||||||
error = setutimes(td, nd.ni_vp, ts, 2, tptr == NULL);
|
error = setutimes(td, nd.ni_vp, ts, 2, tptr == NULL);
|
||||||
vrele(nd.ni_vp);
|
vrele(nd.ni_vp);
|
||||||
return (error);
|
return (error);
|
||||||
@ -3255,7 +3255,7 @@ kern_lutimes(struct thread *td, const char *path, enum uio_seg pathseg,
|
|||||||
NDINIT(&nd, LOOKUP, NOFOLLOW | AUDITVNODE1, pathseg, path, td);
|
NDINIT(&nd, LOOKUP, NOFOLLOW | AUDITVNODE1, pathseg, path, td);
|
||||||
if ((error = namei(&nd)) != 0)
|
if ((error = namei(&nd)) != 0)
|
||||||
return (error);
|
return (error);
|
||||||
NDFREE(&nd, NDF_ONLY_PNBUF);
|
NDFREE_NOTHING(&nd);
|
||||||
error = setutimes(td, nd.ni_vp, ts, 2, tptr == NULL);
|
error = setutimes(td, nd.ni_vp, ts, 2, tptr == NULL);
|
||||||
vrele(nd.ni_vp);
|
vrele(nd.ni_vp);
|
||||||
return (error);
|
return (error);
|
||||||
@ -3370,7 +3370,7 @@ kern_utimensat(struct thread *td, int fd, const char *path,
|
|||||||
* "If both tv_nsec fields are UTIME_OMIT... EACCESS may be detected."
|
* "If both tv_nsec fields are UTIME_OMIT... EACCESS may be detected."
|
||||||
* "Search permission is denied by a component of the path prefix."
|
* "Search permission is denied by a component of the path prefix."
|
||||||
*/
|
*/
|
||||||
NDFREE(&nd, NDF_ONLY_PNBUF);
|
NDFREE_NOTHING(&nd);
|
||||||
if ((flags & UTIMENS_EXIT) == 0)
|
if ((flags & UTIMENS_EXIT) == 0)
|
||||||
error = setutimes(td, nd.ni_vp, ts, 2, flags & UTIMENS_NULL);
|
error = setutimes(td, nd.ni_vp, ts, 2, flags & UTIMENS_NULL);
|
||||||
vrele(nd.ni_vp);
|
vrele(nd.ni_vp);
|
||||||
@ -4226,7 +4226,7 @@ sys_revoke(struct thread *td, struct revoke_args *uap)
|
|||||||
if ((error = namei(&nd)) != 0)
|
if ((error = namei(&nd)) != 0)
|
||||||
return (error);
|
return (error);
|
||||||
vp = nd.ni_vp;
|
vp = nd.ni_vp;
|
||||||
NDFREE(&nd, NDF_ONLY_PNBUF);
|
NDFREE_NOTHING(&nd);
|
||||||
if (vp->v_type != VCHR || vp->v_rdev == NULL) {
|
if (vp->v_type != VCHR || vp->v_rdev == NULL) {
|
||||||
error = EINVAL;
|
error = EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
@ -4361,7 +4361,7 @@ kern_getfhat(struct thread *td, int flags, int fd, const char *path,
|
|||||||
error = namei(&nd);
|
error = namei(&nd);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
return (error);
|
return (error);
|
||||||
NDFREE(&nd, NDF_ONLY_PNBUF);
|
NDFREE_NOTHING(&nd);
|
||||||
vp = nd.ni_vp;
|
vp = nd.ni_vp;
|
||||||
bzero(&fh, sizeof(fh));
|
bzero(&fh, sizeof(fh));
|
||||||
fh.fh_fsid = vp->v_mount->mnt_stat.f_fsid;
|
fh.fh_fsid = vp->v_mount->mnt_stat.f_fsid;
|
||||||
|
@ -288,8 +288,10 @@ void NDFREE(struct nameidata *, const u_int);
|
|||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#ifdef INVARIANTS
|
#ifdef INVARIANTS
|
||||||
|
void NDFREE_NOTHING(struct nameidata *);
|
||||||
void NDVALIDATE(struct nameidata *);
|
void NDVALIDATE(struct nameidata *);
|
||||||
#else
|
#else
|
||||||
|
#define NDFREE_NOTHING(ndp) do { } while (0)
|
||||||
#define NDVALIDATE(ndp) do { } while (0)
|
#define NDVALIDATE(ndp) do { } while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user