From nobody Thu Jul 9 15:59:27 2026 X-Original-To: dev-commits-src-branches@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 4gx05W2Xwdz6kQd6 for ; Thu, 09 Jul 2026 15:59:27 +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 4gx05W1zCNz3Swr for ; Thu, 09 Jul 2026 15:59:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1783612767; 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=8Wu7NyfHsEJWSg1qhFesz3vmf9JkEP6KCJkCCi3xs6I=; b=HZmaZQ4KWplCiGWLy4B8Ip0Hnq7LfhEPCLZMpXlRYplrUYXGSii4Aj+Sj2mhqpDJhpPcgb /hRZt8E9EzIU4m5/WroWgCJi8Z37ag1EjGNATNsloMMpXhsDE8Rmb7+eTR+Ep2y/TH2+w3 SdBpuhBNNYhSAt5hI5U8MHMMq04qKaNJU/rkCqz0aPKP+ccyotqBOYkyI8B432fxGsa+/G 2jYnlH+BawaI8zzx0HwH17wbSz3t8u2gQz8S6S1t3wjkwNuXPyKY4FjT/+e7+6yauEayd2 MB1hbx2w7ultvzC5mTsC3qLFjCwnpToHB7M8OH4bQZ91xga2j6IlRSpu+hZYZg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1783612767; a=rsa-sha256; cv=none; b=vWOSMTxhX9O4T8EylEL7stSrKDy06JWFFdrMrkBYTkhPDVsSX9W+IwGAtj7JnA2jhRZPhc sjj3qKumEsLrQv+su4aHWHPsVQonByoScRtxuHAX+p/kqwWXMCOUpILyXyYtNYXnO8FtDH M9YqqkFrsnRSh0Wl5z0fPplCmZHSFMaR055GUsjULuL5eq67CL9HH37LBPRMZw6v24Yse1 0IAA25w2WxSg1pbLhu89WU0pwmtyG3OYKRd0ONJ7nDv+j5YDeyIo5LvrJhXceuwNBJN54Q w/YOjH/iAFJ9PGWBa8rV28S2jUUy8fCTrOBSBUY0PqKKNz/L6BlABQx7UP5a9A== 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=1783612767; 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=8Wu7NyfHsEJWSg1qhFesz3vmf9JkEP6KCJkCCi3xs6I=; b=Wf4mF4GS9gtdvaR9aMjHY1HRJzBvXUaB5A5JtbkVx8CFbUVig68NYlQJZNxKUg1LmsL5lp hzZ6TqB/6YoG3S4xrUkFDR1omQvvO1C8sqWvhHnTMOLjcYG1VwJAyYJDBB2lry1adJ/ckJ xKbWKUvtItMReaghK6NrliJXOQBgWjWUnIs4FaDGi4CDdNAnRXyQFuqiAI53ixntvakP4Q /68xuM3aqWSw3tdm3OROkHSdbyePYweUaXBR6QB6kElud1zeHe0vnqUaE8suAo6CSFPanq cRNVo+X3kbfBzBVon/HTxvAYYgbOgS9Q2rZYqRUaK3xCPD4yPJMPLuMtBPaHAQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gx05W0j1szrx for ; Thu, 09 Jul 2026 15:59:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 340c8 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 09 Jul 2026 15:59:27 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 242c9c86c8ca - stable/15 - inotify: Unconditionally generate IN_IGNORED events for files/dirs List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/stable/15 X-Git-Reftype: branch X-Git-Commit: 242c9c86c8cad6aa29bc1af9161d4f0eec45f29b Auto-Submitted: auto-generated Date: Thu, 09 Jul 2026 15:59:27 +0000 Message-Id: <6a4fc55f.340c8.10b0e24b@gitrepo.freebsd.org> The branch stable/15 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=242c9c86c8cad6aa29bc1af9161d4f0eec45f29b commit 242c9c86c8cad6aa29bc1af9161d4f0eec45f29b Author: Mark Johnston AuthorDate: 2026-07-06 12:50:37 +0000 Commit: Mark Johnston CommitDate: 2026-07-09 15:59:19 +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 (cherry picked from commit b70997c8c75adc3ab343c47d5ba7d01c9c774d9e) --- 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);