Re: [for-next][PATCH 2/3] eventfs: Stop using dcache_readdir() for getdents()

From: Steven Rostedt
Date: Thu Jan 04 2024 - 14:01:50 EST


On Thu, 4 Jan 2024 10:46:04 -0800
Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:

> And that very fact actually makes me wonder:
>
> > for (i = 0; i < ei->nr_entries; i++) {
> > + void *cdata = ei->data;
> > +
> > + if (c > 0) {
> > + c--;
> > + continue;
> > + }
>
> The 'ei->nr_entries' things are in a stable array, so the indexing for
> them cannot change (ie even if "is_freed" were to be set the array is
> still stable).

Yeah, the entries is fixed. If the ei itself gets freed, so does all the
entries at the same time. The individual entries should too.

Hmm, it probably doesn't even make sense to continue the loop if is_freed
is set as the same variable will be checked every time. :-/ Should just be
a "break;" not a "continue;"

>
> So I wonder if - just from a 'pos' iterator stability standpoint - you
> should change the tracefs directory iterator to always start with the
> non-directory entries in ei->entries[]?

Sure I can do that. I only did it this way because I followed the way the
other functions did the child directories first and then the files (the
entries array represents the files, as the eventfs_inode represents
directories).

>
> That way, even if concurrent dynamic add/remove events might change
> the 'ei->children' list, it could never cause an 'ei->entry[]' to
> disappear (or be returned twice).
>
> This is very nitpicky and I doubt it matters, because I doubt the
> whole "ls on a tracefs directory while changing it" case matters, but
> I thought I'd mention it.

I may add this update, but as a separate patch.

-- Steve