Re: [PATCH v5 02/10] vfs: add for_each_inode()
From: Huang Shijie
Date: Tue Dec 01 2026 - 04:26:07 EST
在 Tue, Dec 01, 2026 at 12:33:38AM -0800,Christoph Hellwig 写道:
> 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
It seems I did the work in the wrong direction..
> magic is a complete nightmare. Compared to a simple interface like
> writeback_iter() this adds tons of gluecode that makes the code really
The v4 code is like the writeback_iter():
v4: https://lore.kernel.org/all/20261125091157.1822521-1-huangsj@xxxxxxxx/
Could you please comment on the V4 code?
Thanks
Huang Shijie
> 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.
>
>