From nobody Mon Jul 6 12:55:19 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4gv48Y3GGgz6jW1G for ; Mon, 06 Jul 2026 12:55:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gv48Y05sqz3mQs for ; Mon, 06 Jul 2026 12:55:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1783342525; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pmV01X40JcRh8uXKIaLSa9q6JAdYMyEEs850jGtskeo=; b=DGk0Kz91H6cIl32AxMamL5cp0WLmy6XbAKbZHAlCN30Rn8DpWBuuZMngrVaPYeHBp2aU4Q 1YJJS0t/9O8T7HHadWaOdGVAVQ6crWX61AcpiiNVyaD+xP6tfUzJRtuuD0CKNJ2DcGsM4Y K5imaZyAZQr10Vfg072H65pQX3NtPFDeFQo/w6VSnbOrQ8b6+f1XUkv6MZr4sLnwBgcPVs Oi44UwTeMnq+2fT2aKVxZWkzAV0mPpWSBZvugKaOWdLRxl8MbERn2dJSah+ByxNZ1fYDH8 M9l0lkdjLuK+iahVNR3qMay5WbDPJ24tI3kAypIHpMH9uQJf8vX0orAFwtueTg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1783342525; a=rsa-sha256; cv=none; b=CLWX7JJG7FvMabk9fdXwqNKeBbTopSXSlOdpyxGu+c0WkSX0BTAzqePr9Vjke0fMUQgFGM N+lAgHYp4YF0n/Mhz3c7AgK0QqVBJ32G9j8mK7Aluknz5+Quy4S+SA6fvSKnLFjKsH0P5M PI/xW2PwTBesD4Hciz4VpztOHb9pEBrY/fnYbfaLEjjN5dA68GM/KqdE4Ln4DdgVxMSHvB G95MU4CfW5DEJgVKdYRHj0Wolh/ws1x1KqzpdYworOiqefTNqc161jNJ2FtEKrazwSK3Un vzM6uoamkrEnnVtQ4yVmj/MA3Oi3YmeZO+21/kDHX7iIrSevJNrZye4zIBHbDQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1783342525; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pmV01X40JcRh8uXKIaLSa9q6JAdYMyEEs850jGtskeo=; b=j+H7mbabTX5WjgViKu6AzVIo5F9IVXjDLF1kQys0PXf2p0ulKnRuuufsYVijg/W6vLP2u/ EeBUGypExR1OC9D17uNqcmunhYsEttlQccEYonRvocglhWvc3tCh0i3BIF/T759yD4yuaw aWgBOXoJfvtL26s9Q0o5bzbKH5gG/O+IgEo0+qT+ptgA7T1mc4e2AmFC9JWoEz7wmPq/DT OCVepSu00lQeNNoJyLyDslYyqFKM4di4wOzpTjaWzd1s4QxPfxCE9rZ34PUhq1xZQIRY0D wpGUFlGJ7wwKRZFrQCrhy4wPWJkLaZ8dxZX/B+g/lKny3otHEslQ4zu/iBic6Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gv48X66Smz14Nh for ; Mon, 06 Jul 2026 12:55:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3de06 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 06 Jul 2026 12:55:19 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: b70997c8c75a - main - inotify: Unconditionally generate IN_IGNORED events for files/dirs List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b70997c8c75adc3ab343c47d5ba7d01c9c774d9e Auto-Submitted: auto-generated Date: Mon, 06 Jul 2026 12:55:19 +0000 Message-Id: <6a4ba5b7.3de06.6244136d@gitrepo.freebsd.org> The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=b70997c8c75adc3ab343c47d5ba7d01c9c774d9e commit b70997c8c75adc3ab343c47d5ba7d01c9c774d9e Author: Mark Johnston AuthorDate: 2026-07-06 12:50:37 +0000 Commit: Mark Johnston CommitDate: 2026-07-06 12:50:37 +0000 inotify: Unconditionally generate IN_IGNORED events for files/dirs The implementation previously only generated an IN_IGNORED event for a deleted watched file if the watch explicitly requested IN_DELETE_SELF. This is not correct, IN_IGNORED should always be raised when the watched subject is deleted. Adjust the implementation of inotify_log_one() accordingly. This also fixes a problem where a deleted watched file's watch would not be removed if IN_DELETE_SELF was not in the watch's event mask, in which case the unlinked vnode would linger until the inotify descriptor itself is closed. Add a regression test. Reported by: jrtc27 Reviewed by: jrtc27 MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D58050 --- sys/kern/vfs_inotify.c | 35 +++++++++++++++++++++++------------ tests/sys/kern/inotify_test.c | 24 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/sys/kern/vfs_inotify.c b/sys/kern/vfs_inotify.c index 94e65973a36b..9269dc0723af 100644 --- a/sys/kern/vfs_inotify.c +++ b/sys/kern/vfs_inotify.c @@ -614,25 +614,37 @@ inotify_log_one(struct inotify_watch *watch, const char *name, size_t namelen, struct inotify_watch key; struct inotify_softc *sc; struct inotify_record *rec; - bool allocfail; + bool allocfail, delete, notify, oneshot, unmount; mtx_assert(&watch->vp->v_pollinfo->vpi_lock, MA_OWNED); sc = watch->sc; - rec = inotify_alloc_record(watch->wd, name, namelen, event, cookie, - M_NOWAIT); - if (rec == NULL) { - rec = &sc->overflow; - allocfail = true; + + delete = (event & IN_DELETE_SELF) != 0; + notify = (watch->mask & event) != 0; + oneshot = (watch->mask & IN_ONESHOT) != 0; + unmount = (event & IN_UNMOUNT) != 0; + if (!notify && !delete && !unmount) + return; + + if (notify || unmount) { + rec = inotify_alloc_record(watch->wd, name, namelen, event, + cookie, M_NOWAIT); + if (rec == NULL) { + rec = &sc->overflow; + allocfail = true; + } else { + allocfail = false; + } } else { - allocfail = false; + rec = NULL; } mtx_lock(&sc->lock); - if (!inotify_queue_record(sc, rec) && rec != &sc->overflow) + if (rec != NULL && !inotify_queue_record(sc, rec) && + rec != &sc->overflow) free(rec, M_INOTIFY); - if ((watch->mask & IN_ONESHOT) != 0 || - (event & (IN_DELETE_SELF | IN_UNMOUNT)) != 0) { + if (oneshot || delete || unmount) { if (!allocfail) { rec = inotify_alloc_record(watch->wd, NULL, 0, IN_IGNORED, 0, M_NOWAIT); @@ -676,8 +688,7 @@ inotify_log(struct vnode *vp, const char *name, size_t namelen, int event, TAILQ_FOREACH_SAFE(watch, &vp->v_pollinfo->vpi_inotify, vlink, tmp) { KASSERT(watch->vp == vp, ("inotify_log: watch %p vp != vp", watch)); - if ((watch->mask & event) != 0 || event == IN_UNMOUNT) - inotify_log_one(watch, name, namelen, event, cookie); + inotify_log_one(watch, name, namelen, event, cookie); } mtx_unlock(&vp->v_pollinfo->vpi_lock); } diff --git a/tests/sys/kern/inotify_test.c b/tests/sys/kern/inotify_test.c index d3799b12ce20..9d5265e71f95 100644 --- a/tests/sys/kern/inotify_test.c +++ b/tests/sys/kern/inotify_test.c @@ -54,6 +54,8 @@ ev2name(int event) return ("IN_MOVED_TO"); case IN_OPEN: return ("IN_OPEN"); + case IN_IGNORED: + return ("IN_IGNORED"); default: return (NULL); } @@ -832,6 +834,27 @@ ATF_TC_BODY(inotify_event_delete, tc) close_inotify(ifd); } +ATF_TC_WITHOUT_HEAD(inotify_event_delete_ignored); +ATF_TC_BODY(inotify_event_delete_ignored, tc) +{ + char path[PATH_MAX]; + int error, ifd, wd; + + ifd = inotify(IN_NONBLOCK); + + wd = watch_dir(ifd, IN_DELETE, path); + + /* + * IN_IGNORED should be generated when a watched directory is removed, + * even if the watch was not configured to raise IN_DELETE_SELF. + */ + error = rmdir(path); + ATF_REQUIRE(error == 0); + consume_event(ifd, wd, 0, IN_IGNORED, NULL); + + close_inotify(ifd); +} + ATF_TC_WITHOUT_HEAD(inotify_event_move); ATF_TC_BODY(inotify_event_move, tc) { @@ -999,6 +1022,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, inotify_event_close_write); ATF_TP_ADD_TC(tp, inotify_event_create); ATF_TP_ADD_TC(tp, inotify_event_delete); + ATF_TP_ADD_TC(tp, inotify_event_delete_ignored); ATF_TP_ADD_TC(tp, inotify_event_move); ATF_TP_ADD_TC(tp, inotify_event_move_dir); ATF_TP_ADD_TC(tp, inotify_event_open);