Date: Tue, 12 Jan 2021 13:44:10 GMT From: Mateusz Guzik <mjg@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: cdb62ab74ee0 - main - vfs: add NDFREE_NOTHING and convert several NDFREE_PNBUF callers Message-ID: <202101121344.10CDiAvU053708@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=cdb62ab74ee0cb99988c7831d950a6021aaa4879 commit cdb62ab74ee0cb99988c7831d950a6021aaa4879 Author: Mateusz Guzik <mjg@FreeBSD.org> AuthorDate: 2021-01-12 11:36:30 +0000 Commit: Mateusz Guzik <mjg@FreeBSD.org> CommitDate: 2021-01-12 13:16:10 +0000 vfs: add NDFREE_NOTHING and convert several NDFREE_PNBUF callers Check the comment above the routine for reasoning. --- sys/kern/uipc_usrreq.c | 2 +- sys/kern/vfs_lookup.c | 27 +++++++++++++++++++++++++++ sys/kern/vfs_syscalls.c | 34 +++++++++++++++++----------------- sys/sys/namei.h | 2 ++ 4 files changed, 47 insertions(+), 18 deletions(-) diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index ad369fc7b23e..44e48bc864a3 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1568,7 +1568,7 @@ unp_connectat(int fd, struct socket *so, struct sockaddr *nam, else vp = nd.ni_vp; ASSERT_VOP_LOCKED(vp, "unp_connect"); - NDFREE(&nd, NDF_ONLY_PNBUF); + NDFREE_NOTHING(&nd); if (error) goto bad; diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c index da04dd09af40..3b8ee558e023 100644 --- a/sys/kern/vfs_lookup.c +++ b/sys/kern/vfs_lookup.c @@ -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 (NDFREE)(struct nameidata *ndp, const u_int flags) { diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index ce5da109f168..560a003765d5 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -340,7 +340,7 @@ kern_statfs(struct thread *td, const char *path, enum uio_seg pathseg, return (error); mp = nd.ni_vp->v_mount; vfs_ref(mp); - NDFREE(&nd, NDF_ONLY_PNBUF); + NDFREE_NOTHING(&nd); vput(nd.ni_vp); 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); if ((error = change_dir(nd.ni_vp, td)) != 0) { vput(nd.ni_vp); - NDFREE(&nd, NDF_ONLY_PNBUF); + NDFREE_NOTHING(&nd); return (error); } VOP_UNLOCK(nd.ni_vp); - NDFREE(&nd, NDF_ONLY_PNBUF); + NDFREE_NOTHING(&nd); pwd_chdir(td, nd.ni_vp); return (0); } @@ -991,12 +991,12 @@ sys_chroot(struct thread *td, struct chroot_args *uap) VOP_UNLOCK(nd.ni_vp); error = pwd_chroot(td, nd.ni_vp); vrele(nd.ni_vp); - NDFREE(&nd, NDF_ONLY_PNBUF); + NDFREE_NOTHING(&nd); return (error); e_vunlock: vput(nd.ni_vp); error: - NDFREE(&nd, NDF_ONLY_PNBUF); + NDFREE_NOTHING(&nd); return (error); } @@ -2118,7 +2118,7 @@ kern_accessat(struct thread *td, int fd, const char *path, vp = nd.ni_vp; error = vn_access(vp, amode, usecred, td); - NDFREE(&nd, NDF_ONLY_PNBUF); + NDFREE_NOTHING(&nd); vput(vp); out: if (usecred != cred) { @@ -2417,7 +2417,7 @@ kern_statat(struct thread *td, int flag, int fd, const char *path, if (__predict_false(hook != NULL)) hook(nd.ni_vp, sbp); } - NDFREE(&nd, NDF_ONLY_PNBUF); + NDFREE_NOTHING(&nd); vput(nd.ni_vp); #ifdef __STAT_TIME_T_EXT sbp->st_atim_ext = 0; @@ -2557,7 +2557,7 @@ kern_pathconf(struct thread *td, const char *path, enum uio_seg pathseg, pathseg, path, td); if ((error = namei(&nd)) != 0) return (error); - NDFREE(&nd, NDF_ONLY_PNBUF); + NDFREE_NOTHING(&nd); error = VOP_PATHCONF(nd.ni_vp, name, valuep); vput(nd.ni_vp); @@ -2613,7 +2613,7 @@ kern_readlinkat(struct thread *td, int fd, const char *path, if ((error = namei(&nd)) != 0) return (error); - NDFREE(&nd, NDF_ONLY_PNBUF); + NDFREE_NOTHING(&nd); vp = nd.ni_vp; 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); if ((error = namei(&nd)) != 0) return (error); - NDFREE(&nd, NDF_ONLY_PNBUF); + NDFREE_NOTHING(&nd); error = setfflags(td, nd.ni_vp, flags); vrele(nd.ni_vp); return (error); @@ -2893,7 +2893,7 @@ kern_fchmodat(struct thread *td, int fd, const char *path, &cap_fchmod_rights, td); if ((error = namei(&nd)) != 0) return (error); - NDFREE(&nd, NDF_ONLY_PNBUF); + NDFREE_NOTHING(&nd); error = setfmode(td, td->td_ucred, nd.ni_vp, mode); vrele(nd.ni_vp); return (error); @@ -3006,7 +3006,7 @@ kern_fchownat(struct thread *td, int fd, const char *path, if ((error = namei(&nd)) != 0) return (error); - NDFREE(&nd, NDF_ONLY_PNBUF); + NDFREE_NOTHING(&nd); error = setfown(td, td->td_ucred, nd.ni_vp, uid, gid); vrele(nd.ni_vp); return (error); @@ -3219,7 +3219,7 @@ kern_utimesat(struct thread *td, int fd, const char *path, if ((error = namei(&nd)) != 0) return (error); - NDFREE(&nd, NDF_ONLY_PNBUF); + NDFREE_NOTHING(&nd); error = setutimes(td, nd.ni_vp, ts, 2, tptr == NULL); vrele(nd.ni_vp); 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); if ((error = namei(&nd)) != 0) return (error); - NDFREE(&nd, NDF_ONLY_PNBUF); + NDFREE_NOTHING(&nd); error = setutimes(td, nd.ni_vp, ts, 2, tptr == NULL); vrele(nd.ni_vp); 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." * "Search permission is denied by a component of the path prefix." */ - NDFREE(&nd, NDF_ONLY_PNBUF); + NDFREE_NOTHING(&nd); if ((flags & UTIMENS_EXIT) == 0) error = setutimes(td, nd.ni_vp, ts, 2, flags & UTIMENS_NULL); vrele(nd.ni_vp); @@ -4226,7 +4226,7 @@ sys_revoke(struct thread *td, struct revoke_args *uap) if ((error = namei(&nd)) != 0) return (error); vp = nd.ni_vp; - NDFREE(&nd, NDF_ONLY_PNBUF); + NDFREE_NOTHING(&nd); if (vp->v_type != VCHR || vp->v_rdev == NULL) { error = EINVAL; goto out; @@ -4361,7 +4361,7 @@ kern_getfhat(struct thread *td, int flags, int fd, const char *path, error = namei(&nd); if (error != 0) return (error); - NDFREE(&nd, NDF_ONLY_PNBUF); + NDFREE_NOTHING(&nd); vp = nd.ni_vp; bzero(&fh, sizeof(fh)); fh.fh_fsid = vp->v_mount->mnt_stat.f_fsid; diff --git a/sys/sys/namei.h b/sys/sys/namei.h index ddba9cbd8912..c045bc7c6bc5 100644 --- a/sys/sys/namei.h +++ b/sys/sys/namei.h @@ -288,8 +288,10 @@ void NDFREE(struct nameidata *, const u_int); } while (0) #ifdef INVARIANTS +void NDFREE_NOTHING(struct nameidata *); void NDVALIDATE(struct nameidata *); #else +#define NDFREE_NOTHING(ndp) do { } while (0) #define NDVALIDATE(ndp) do { } while (0) #endif
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202101121344.10CDiAvU053708>