From: NeilBrown <neilb@ownmail.net>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
Amir Goldstein <amir73il@gmail.com>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Ian Kent <raven@themaw.net>, Jake Edge <jake@lwn.net>
Subject: [PATCH v4 3/5] fsnotify: don't hold i_lock while walking d_children in fsnotify_set_children_dentry_flags()
Date: Mon, 19 Oct 2026 11:00:41 +1100 [thread overview]
Message-ID: <20261019000810.1837917-4-neilb@ownmail.net> (raw)
In-Reply-To: <20261019000810.1837917-1-neilb@ownmail.net>
From: NeilBrown <neil@brown.name>
Rather than hold i_lock across a d_children walk, dget() a reference to
the dentry and drop the i_lock before the walk. This is easily done
with d_find_alias().
This requires that we dput() which can sleep. Now that no locks are
held across calls to fsnotify_set_children_dentry_flags(), this is safe.
Signed-off-by: NeilBrown <neil@brown.name>
---
fs/notify/fsnotify.c | 40 ++++++++++++++++++++--------------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c
index 7e2f330fd283..465e875dec57 100644
--- a/fs/notify/fsnotify.c
+++ b/fs/notify/fsnotify.c
@@ -71,32 +71,32 @@ void fsnotify_sb_free(struct super_block *sb)
*/
void fsnotify_set_children_dentry_flags(struct inode *inode)
{
- struct dentry *alias;
+ struct dentry *alias, *child;
if (!S_ISDIR(inode->i_mode))
return;
- spin_lock(&inode->i_lock);
- /* run all of the dentries associated with this inode. Since this is a
- * directory, there damn well better only be one item on this list */
- for_each_alias(alias, inode) {
- struct dentry *child;
-
- /* run all of the children of the original inode and fix their
- * d_flags to indicate parental interest (their parent is the
- * original inode) */
- spin_lock(&alias->d_lock);
- hlist_for_each_entry(child, &alias->d_children, d_sib) {
- if (!child->d_inode)
- continue;
+ /* Find the dentry for inode - there can only be one */
+ alias = d_find_alias(inode);
+ if (!alias)
+ return;
- spin_lock_nested(&child->d_lock, DENTRY_D_LOCK_NESTED);
- child->d_flags |= DCACHE_FSNOTIFY_PARENT_WATCHED;
- spin_unlock(&child->d_lock);
- }
- spin_unlock(&alias->d_lock);
+ /*
+ * run all of the children of the original inode and fix their
+ * d_flags to indicate parental interest (their parent is the
+ * original inode)
+ */
+ spin_lock(&alias->d_lock);
+ hlist_for_each_entry(child, &alias->d_children, d_sib) {
+ if (!child->d_inode)
+ continue;
+
+ spin_lock_nested(&child->d_lock, DENTRY_D_LOCK_NESTED);
+ child->d_flags |= DCACHE_FSNOTIFY_PARENT_WATCHED;
+ spin_unlock(&child->d_lock);
}
- spin_unlock(&inode->i_lock);
+ spin_unlock(&alias->d_lock);
+ dput(alias);
}
/*
--
2.50.0.107.gf914562f5916.dirty
next prev parent reply other threads:[~2026-10-19 0:08 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-19 0:00 [PATCH v4 0/5] Fix easy bits of the negative dentry problem NeilBrown
2026-10-19 0:00 ` [PATCH v4 1/5] VFS: don't count references through ->d_parent NeilBrown
2026-10-21 9:54 ` NeilBrown
2026-10-21 11:47 ` Ian Kent
2026-10-22 3:04 ` Ian Kent
2026-10-22 5:20 ` NeilBrown
2026-10-19 0:00 ` [PATCH v4 2/5] fsnotify: update children flags only when adding mask bits NeilBrown
2026-10-19 0:00 ` NeilBrown [this message]
2026-10-19 0:00 ` [PATCH v4 4/5] Add d_for_each_positive_child family of iterators NeilBrown
2026-10-19 0:00 ` [PATCH v4 5/5] Use d_for_each_positive_child() in fsnotify NeilBrown
2026-10-19 1:59 ` [PATCH v4 0/5] Fix easy bits of the negative dentry problem Ian Kent
2026-10-19 2:29 ` NeilBrown
2026-10-20 1:29 ` Ian Kent
2026-10-21 0:01 ` NeilBrown
2026-10-22 12:30 ` Miklos Szeredi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261019000810.1837917-4-neilb@ownmail.net \
--to=neilb@ownmail.net \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=jake@lwn.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=neil@brown.name \
--cc=raven@themaw.net \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®