Re: [PATCH 1/2 v3] eventfs: Remove eventfs_file and just use eventfs_inode
From: Steven Rostedt
Date: Tue Sep 19 2023 - 21:17:44 EST
On Tue, 19 Sep 2023 18:41:09 +0900
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx> wrote:
> > > > ti = get_tracefs(inode);
> > > > if (!(ti->flags & TRACEFS_EVENT_INODE))
> > > > @@ -375,10 +485,18 @@ static int eventfs_release(struct inode *inode, struct file *file)
> > > >
> > > > ei = ti->private;
> > > > idx = srcu_read_lock(&eventfs_srcu);
> > > > - list_for_each_entry_srcu(ef, &ei->e_top_files, list,
> > > > + list_for_each_entry_srcu(ei_child, &ei->children, list,
> > > > srcu_read_lock_held(&eventfs_srcu)) {
> > > > mutex_lock(&eventfs_mutex);
> > > > - dentry = ef->dentry;
> > > > + dentry = ei_child->dentry;
> > > > + mutex_unlock(&eventfs_mutex);
> > >
> > > If someone add a directory via eventfs_create_dir() in parallel, is this
> > > local mutex_lock able to protect from that? (usually it may not happen.)
> >
> > That would require an event being added and created at the same time. Not
> > sure that is possible.
> >
> > We could try it?
>
> Not sure, but both eventfs_release() and eventfs_create_dir() will be
> called from dynamic events, right? But the dynamic events will protect
> the create/delete operation with a mutex, so it should not happen if
> I understand correctly.
> But if the eventfs requires such external exclusion for the operation,
> it should be commented.
Hmm, actually looking at this, it's worse than what you stated. This is
called when a directory is closed. So if you had:
open(dir);
// look at all the content of this dir to create dentries
// another task creates a new entry and looks at it too.
close(dir);
Now we iterate over all the dentries of the dir and dput it.
I think this will cause the ref counts to get out of sync. I'll have to try
to create this scenario and see what happens.
>
> >
> > >
> > > > + if (dentry)
> > > > + dput(dentry);
> > > > + }
> > > > +
> > > > + for (i = 0; i < ei->nr_entries; i++) {
> > > > + mutex_lock(&eventfs_mutex);
> > > > + dentry = ei->d_children[i];
> > > > mutex_unlock(&eventfs_mutex);
> > >
> > > Ditto. Maybe I'm misunderstanding how eventfs_mutex is used.
> >
> > I'll have to go back and look at this part on why I had this. I think it
> > was to make sure ei->d_children existed. But it may also need a test too. I
> > don't remember. :-/
I believe this is to keep this and create_file_dentry() in sync.
But I need to look deeper. I'm still very new with understanding how all
this file system code works :-p
-- Steve