Re: [PATCH v5 02/10] vfs: add for_each_inode()
From: Christoph Hellwig
Date: Tue Dec 01 2026 - 03:34:01 EST
On Tue, Dec 01, 2026 at 02:46:31PM +0800, Huang Shijie wrote:
> Walking sb->s_inodes requires taking s_inode_list_lock, grabbing a
> reference on the next inode, dropping the lock and then working on the
> inode. That sequence is open coded in several places, each with its own
> subtleties around the inode state checks and the reference count.
>
> Add a caller-owned cursor wrapped in a cleanup class, so that the
> iterator goes out of scope as soon as the loop ends:
>
> for_each_inode(inode, sb) {
> /* inode is referenced and unlocked here */
> }
I know you've gotten contrary feedback, but all this CLASS and macro
magic is a complete nightmare. Compared to a simple interface like
writeback_iter() this adds tons of gluecode that makes the code really
hard to understand, even more so when in backtraces after a crash.
All for the tiny "benefit" of allowing a break or goto out of the loop,
which isn't even needed in the usual patterns.