From: Tejun Heo <tj@kernel.org>
To: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Christian Brauner <christian@brauner.io>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Meta kernel team <kernel-team@meta.com>,
linux-fsdevel@vger.kernel.org, driver-core@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] kernfs: don't repeat or skip an entry when readdir resumes
Date: Thu, 10 Sep 2026 10:15:26 -1000 [thread overview]
Message-ID: <aqMP3hRFEazxZkeN@slm.duckdns.org> (raw)
In-Reply-To: <20260910003650.1680854-2-shakeel.butt@linux.dev>
On Wed, Sep 09, 2026 at 05:36:48PM -0700, Shakeel Butt wrote:
> readdir keeps its place as a name hash in ctx->pos and pins the entry in
> file->private_data. If that entry is gone when the listing comes back,
> kernfs_dir_pos() searches the rbtree for the hash and keeps whatever
> node the descent stopped on. That is the entry before or after the
> missing one, depending on the shape of the tree.
>
> Landing before it repeats an entry the previous getdents(2) call already
> reported. Landing after it, kernfs_dir_next_pos() calls rb_next() and
> steps over an unreported entry.
>
> With children A(10), B(20), C(30):
>
> report A, ctx->pos = 10
> A removed
> kernfs_dir_next_pos(10, A)
> A is gone, the search for 10 stops at B
> rb_next(B) -> C, so B is never reported
>
> Only the repeat happens today, between two getdents(2) calls. The skip
> needs the pinned entry to go away inside one call, which the next patch
> allows when it drops kernfs_rwsem around dir_emit().
>
> Before the commit 4e4d6d860b93 the descent kept a node only on the way
> left, which is a search for the first entry at or after the hash. That
> commit moved the assignment to the top of the loop, where it runs on
> right turns too. Restore that search, and step forward only when the
> pinned entry is still there rather than when the hash matches, since two
> entries in one directory can share a hash.
>
> While here, kernfs_dir_next_pos() called the hash @ino. It is never an
> inode number, so name it @hash.
>
> Fixes: 4e4d6d860b93 ("sysfs: Add s_hash to sysfs_dirent and order directory entries by hash")
> Assisted-by: LLM
> Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
Acked-by: Tejun Heo <tj@kernel.org>
Thanks.
--
tejun
next prev parent reply other threads:[~2026-09-10 20:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 0:36 [PATCH 0/3] kernfs: don't hold kernfs_rwsem across dir_emit() Shakeel Butt
2026-09-10 0:36 ` [PATCH 1/3] kernfs: don't repeat or skip an entry when readdir resumes Shakeel Butt
2026-09-10 20:15 ` Tejun Heo [this message]
2026-09-10 0:36 ` [PATCH 2/3] kernfs: don't hold kernfs_rwsem across dir_emit() Shakeel Butt
2026-09-10 20:24 ` Tejun Heo
2026-09-10 0:36 ` [PATCH 3/3] selftests: cover readdir resuming at a removed entry Shakeel Butt
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=aqMP3hRFEazxZkeN@slm.duckdns.org \
--to=tj@kernel.org \
--cc=bigeasy@linutronix.de \
--cc=christian@brauner.io \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=kernel-team@meta.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=shakeel.butt@linux.dev \
/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