git: b7b9b68e08c8 - releng/15.2 - inotify: Open target the directory when adding a watch
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 09 Nov 2026 19:31:35 UTC
The branch releng/15.2 has been updated by cperciva:
URL: https://cgit.FreeBSD.org/src/commit/?id=b7b9b68e08c8bb0006bd5946c06818d2ce18e43e
commit b7b9b68e08c8bb0006bd5946c06818d2ce18e43e
Author: Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2026-10-19 13:44:41 +0000
Commit: Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2026-11-09 19:30:33 +0000
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.
Approved by: re (cperciva)
PR: 299239
Reviewed by: kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D60782
(cherry picked from commit de80428118101624aaeaae02d59665d1027ff10e)
(cherry picked from commit d4f4bd11adf266b926400b4725682d39187a489d)
---
sys/kern/vfs_inotify.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/sys/kern/vfs_inotify.c b/sys/kern/vfs_inotify.c
index bc8db76d848b..fe9dedfaa942 100644
--- a/sys/kern/vfs_inotify.c
+++ b/sys/kern/vfs_inotify.c
@@ -785,6 +785,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);
@@ -821,6 +829,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);
}