Re: git: a1d71cebc05c - main - fstatat(2): restore AT_EMPTY_PATH handling
- In reply to: Mateusz Guzik : "Re: git: a1d71cebc05c - main - fstatat(2): restore AT_EMPTY_PATH handling"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 03 May 2023 09:55:08 UTC
On Tue, May 02, 2023 at 11:08:23PM +0200, Mateusz Guzik wrote: > On 5/2/23, Mateusz Guzik <mjguzik@gmail.com> wrote: > > right, this should do it > > > > diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c > > index e4977392349f..b583eed5e249 100644 > > --- a/sys/kern/vfs_cache.c > > +++ b/sys/kern/vfs_cache.c > > @@ -4435,6 +4435,7 @@ cache_fplookup_dirfd(struct cache_fpl *fpl, > > struct vnode **vpp) > > if ((*vpp)->v_type != VDIR) { > > if (!((cnp->cn_flags & EMPTYPATH) != 0 && > > cnp->cn_pnbuf[0] == '\0')) { > > cache_fpl_smr_exit(fpl); > > + ndp->ni_resflags |= NIRES_EMPTYPATH; > > return (cache_fpl_handled_error(fpl, ENOTDIR)); > > } > > } > > > > on another look it already works fine as is, I miseed the ! in the condition ;) ugh, thanks, looks like it's time for me to sleep it off )) > > #include <sys/stat.h> > #include <fcntl.h> > > int > main(void) > { > struct stat sb; > int fd; > > fd = open("/etc/fstab", O_RDONLY); > > fstatat(fd, "", &sb, AT_EMPTY_PATH); > } > > openat(AT_FDCWD,"/etc/fstab",O_RDONLY,00) = 3 (0x3) > fstatat(3,"",{ mode=-rw-r--r-- ,inode=370100,size=145,blksize=4096 > },AT_EMPTY_PATH) = 0 (0x0) > > dtrace -n 'vfs:fplookup:: /execname == "a.out"/ { @[stack(), arg1, > arg2] = count(); }' > [snip] > kernel`kern_statat+0xec > kernel`sys_fstatat+0x27 > kernel`amd64_syscall+0x109 > kernel`0xffffffff809726bb > 4980 3 1 > > as in handled in cache_fplookup_emptypath > > > > > On 5/2/23, Dmitry Chagin <dchagin@freebsd.org> wrote: > >> On Tue, May 02, 2023 at 03:04:37PM -0400, Mark Johnston wrote: > >>> On Tue, May 02, 2023 at 08:00:01PM +0300, Dmitry Chagin wrote: > >>> > On Tue, May 02, 2023 at 03:12:51PM +0000, Konstantin Belousov wrote: > >>> > > The branch main has been updated by kib: > >>> > > > >>> > > URL: > >>> > > https://cgit.FreeBSD.org/src/commit/?id=a1d71cebc05ccfeedf95f2db3e94b17270167888 > >>> > > > >>> > > commit a1d71cebc05ccfeedf95f2db3e94b17270167888 > >>> > > Author: Konstantin Belousov <kib@FreeBSD.org> > >>> > > AuthorDate: 2023-05-02 15:11:39 +0000 > >>> > > Commit: Konstantin Belousov <kib@FreeBSD.org> > >>> > > CommitDate: 2023-05-02 15:11:39 +0000 > >>> > > > >>> > > fstatat(2): restore AT_EMPTY_PATH handling > >>> > > > >>> > > Fixes: cb858340dcbf214cc4c4d78dbb741620d7b3a252 > >>> > > Reported by: markj > >>> > > Sponsored by: The FreeBSD Foundation > >>> > > --- > >>> > > sys/kern/vfs_syscalls.c | 6 +++++- > >>> > > 1 file changed, 5 insertions(+), 1 deletion(-) > >>> > > > >>> > > diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c > >>> > > index 5c0a291e3b0b..d68af4ea4d51 100644 > >>> > > --- a/sys/kern/vfs_syscalls.c > >>> > > +++ b/sys/kern/vfs_syscalls.c > >>> > > @@ -2438,8 +2438,12 @@ kern_statat(struct thread *td, int flag, int > >>> > > fd, const char *path, > >>> > > AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH) | LOCKSHARED | LOCKLEAF | > >>> > > AUDITVNODE1, pathseg, path, fd, &cap_fstat_rights); > >>> > > > >>> > > - if ((error = namei(&nd)) != 0) > >>> > > + if ((error = namei(&nd)) != 0) { > >>> > > + if (error == ENOTDIR && > >>> > > + (nd.ni_resflags & NIRES_EMPTYPATH) != 0) > >>> > > + error = kern_fstat(td, fd, sbp); > >>> > > return (error); > >>> > > + } > >>> > > >>> > cache_fplookup_dirfd() doesnt set the NIRES_EMPTYPATH flag > >>> > >>> It doesn't, but for an AT_EMPTY_PATH lookup it aborts the lookup and > >>> returns ENOTDIR to namei(), which sets NIRES_EMPTYPATH before passing > >>> the error up. > >>> > >> > >> it call cache_fpl_handled_error() which is set status to > >> CACHE_FPL_STATUS_HADLED, namei() simply return error in that path > >> > >> > >>> > > error = VOP_STAT(nd.ni_vp, sbp, td->td_ucred, NOCRED); > >>> > > NDFREE_PNBUF(&nd); > >>> > > vput(nd.ni_vp); > >>> > > >> > > > > > > -- > > Mateusz Guzik <mjguzik gmail.com> > > > > > -- > Mateusz Guzik <mjguzik gmail.com>