From: NeilBrown <neilb@ownmail.net>
To: Paulo Alcantara <pc@manguebit.org>,
Namjae Jeon <linkinjeon@kernel.org>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>
Cc: Jeff Layton <jlayton@kernel.org>, Jan Kara <jack@suse.cz>,
linux-fsdevel@vger.kernel.org, linux-cifs@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 3/3] smb/client: Use d_alloc_trylock() in cifs_prime_dcache()
Date: Mon, 28 Sep 2026 11:25:04 +1000 [thread overview]
Message-ID: <20260928012812.2890035-4-neilb@ownmail.net> (raw)
In-Reply-To: <20260928012812.2890035-1-neilb@ownmail.net>
From: NeilBrown <neil@brown.name>
cifs uses the results of readdir to prime the dcache. Using
d_alloc_parallel() can block if there is a concurrent lookup. Blocking
in that case is pointless as the lookup will add info to the dcache and
there is no value in the readdir waiting to see if it should add the
info too.
Also this call to d_alloc_parallel() is made while the parent
directory is locked. A proposed change to locking will lock the parent
later, after d_alloc_parallel(). This means it won't be safe to wait in
d_alloc_parallel() while holding the directory lock.
So change to use d_alloc_trylock(). As d_alloc_trylock() includes a
try_lookup we don't need both. Rearrange the code so we can choose
either a try_lookup or d_alloc_trylock.
Signed-off-by: NeilBrown <neil@brown.name>
---
fs/smb/client/readdir.c | 50 ++++++++++++++++++++---------------------
1 file changed, 24 insertions(+), 26 deletions(-)
diff --git a/fs/smb/client/readdir.c b/fs/smb/client/readdir.c
index 32a75afca8f5..19d0c77046ab 100644
--- a/fs/smb/client/readdir.c
+++ b/fs/smb/client/readdir.c
@@ -77,36 +77,34 @@ cifs_prime_dcache(struct dentry *parent, struct qstr *name,
cifs_dbg(FYI, "%s: for %s\n", __func__, name->name);
- dentry = try_lookup_noperm(name, parent);
- if (!dentry) {
- /*
- * If we know that the inode will need to be revalidated
- * immediately, then don't create a new dentry for it.
- * We'll end up doing an on the wire call either way and
- * this spares us an invalidation.
- */
-retry:
- if (posix) {
- switch (fattr->cf_mode & S_IFMT) {
- case S_IFLNK:
- case S_IFBLK:
- case S_IFCHR:
- reparse_need_reval = true;
- break;
- default:
- break;
- }
- } else if (fattr->cf_cifsattrs & ATTR_REPARSE_POINT) {
+ /*
+ * If we know that the inode will need to be revalidated
+ * immediately, then don't create a new dentry for it.
+ * We'll end up doing an on the wire call either way and
+ * this spares us an invalidation.
+ */
+ if (posix) {
+ switch (fattr->cf_mode & S_IFMT) {
+ case S_IFLNK:
+ case S_IFBLK:
+ case S_IFCHR:
reparse_need_reval = true;
+ break;
+ default:
+ break;
}
+ } else if (fattr->cf_cifsattrs & ATTR_REPARSE_POINT) {
+ reparse_need_reval = true;
+ }
- if (reparse_need_reval ||
- (fattr->cf_flags & CIFS_FATTR_NEED_REVAL))
- return;
+retry:
+ if (reparse_need_reval ||
+ (fattr->cf_flags & CIFS_FATTR_NEED_REVAL))
+ dentry = try_lookup_noperm(name, parent);
+ else
+ dentry = d_alloc_trylock(parent, name);
- dentry = d_alloc_parallel(parent, name);
- }
- if (IS_ERR(dentry))
+ if (!dentry || IS_ERR(dentry))
return;
if (!d_in_lookup(dentry)) {
inode = d_inode(dentry);
--
2.50.0.107.gf914562f5916.dirty
next prev parent reply other threads:[~2026-09-28 1:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 1:25 [PATCH 0/3] smb/client(cifs): prepare for locking changes NeilBrown
2026-09-28 1:25 ` [PATCH 1/3] smb/client: don't unhash and rehash to prevent new opens NeilBrown
2026-10-21 15:30 ` Tom Talpey
2026-09-28 1:25 ` [PATCH 2/3] smb/client: use d_alloc_trylock in cifs_silly_fullpath() NeilBrown
2026-09-28 1:25 ` NeilBrown [this message]
2026-10-21 9:55 ` [PATCH 0/3] smb/client(cifs): prepare for locking changes Christian Brauner
2026-10-21 15:31 ` Tom Talpey
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=20260928012812.2890035-4-neilb@ownmail.net \
--to=neilb@ownmail.net \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=jlayton@kernel.org \
--cc=linkinjeon@kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=neil@brown.name \
--cc=pc@manguebit.org \
--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®