inotify: Open target the directory when adding a watch

When an application uses inotify to watch a directory,
vn_inotify_add_watch() reads the directory entries and does a name
lookup so as to induce the filesystem to create namecache entries.
Some filesystems expect the directory to be opened before VOP_READDIR
can be called, so do that.

PR:		299239
Reviewed by:	kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D60782

(cherry picked from commit de80428118)
This commit is contained in:
Mark Johnston committed 2026-10-26 14:35:02 +00:00
1 parent 72ec5a2b25
commit a5f61370a3
1 file changed
+9
+9
View File
@@ -781,6 +781,14 @@ vn_inotify_add_watch(struct vnode *vp, struct inotify_softc *sc, uint32_t mask,
size_t buflen, len;
int eof, error;
/*
* Some filesystems, at least fuse, require that the directory
* be opened before reading it.
*/
error = VOP_OPEN(vp, FREAD, td->td_ucred, td, NULL);
if (error != 0)
return (error);
buflen = 128 * sizeof(struct dirent);
buf = malloc(buflen, M_TEMP, M_WAITOK);
@@ -817,6 +825,7 @@ vn_inotify_add_watch(struct vnode *vp, struct inotify_softc *sc, uint32_t mask,
vrele(nd.ni_vp);
}
free(buf, M_TEMP);
VOP_CLOSE(vp, FREAD, td->td_ucred, td);
if (error != 0)
return (error);
}