Commit 8dce06e9 authored by Linus Torvalds's avatar Linus Torvalds Committed by Steven Rostedt (Google)

eventfs: Clean up dentry ops and add revalidate function

In order for the dentries to stay up-to-date with the eventfs changes,
just add a 'd_revalidate' function that checks the 'is_freed' bit.

Also, clean up the dentry release to actually use d_release() rather
than the slightly odd d_iput() function.  We don't care about the inode,
all we want to do is to get rid of the refcount to the eventfs data
added by dentry->d_fsdata.

It would probably be cleaner to make eventfs its own filesystem, or at
least set its own dentry ops when looking up eventfs files.  But as it
is, only eventfs dentries use d_fsdata, so we don't really need to split
these things up by use.

Another thing that might be worth doing is to make all eventfs lookups
mark their dentries as not worth caching.  We could do that with
d_delete(), but the DCACHE_DONTCACHE flag would likely be even better.

As it is, the dentries are all freeable, but they only tend to get freed
at memory pressure rather than more proactively.  But that's a separate
issue.

Link: https://lore.kernel.org/linux-trace-kernel/202401291043.e62e89dc-oliver.sang@intel.com/
Link: https://lore.kernel.org/linux-trace-kernel/20240131185513.124644253@goodmis.org

Cc: stable@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Ajay Kaher <ajay.kaher@broadcom.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Fixes: c1504e51 ("eventfs: Implement eventfs dir creation functions")
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
parent 408600be
...@@ -378,13 +378,12 @@ static void free_ei(struct eventfs_inode *ei) ...@@ -378,13 +378,12 @@ static void free_ei(struct eventfs_inode *ei)
} }
/** /**
* eventfs_set_ei_status_free - remove the dentry reference from an eventfs_inode * eventfs_d_release - dentry is going away
* @ti: the tracefs_inode of the dentry
* @dentry: dentry which has the reference to remove. * @dentry: dentry which has the reference to remove.
* *
* Remove the association between a dentry from an eventfs_inode. * Remove the association between a dentry from an eventfs_inode.
*/ */
void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry) void eventfs_d_release(struct dentry *dentry)
{ {
struct eventfs_inode *ei; struct eventfs_inode *ei;
int i; int i;
......
...@@ -377,21 +377,30 @@ static const struct super_operations tracefs_super_operations = { ...@@ -377,21 +377,30 @@ static const struct super_operations tracefs_super_operations = {
.show_options = tracefs_show_options, .show_options = tracefs_show_options,
}; };
static void tracefs_dentry_iput(struct dentry *dentry, struct inode *inode) /*
* It would be cleaner if eventfs had its own dentry ops.
*
* Note that d_revalidate is called potentially under RCU,
* so it can't take the eventfs mutex etc. It's fine - if
* we open a file just as it's marked dead, things will
* still work just fine, and just see the old stale case.
*/
static void tracefs_d_release(struct dentry *dentry)
{ {
struct tracefs_inode *ti; if (dentry->d_fsdata)
eventfs_d_release(dentry);
}
if (!dentry || !inode) static int tracefs_d_revalidate(struct dentry *dentry, unsigned int flags)
return; {
struct eventfs_inode *ei = dentry->d_fsdata;
ti = get_tracefs(inode); return !(ei && ei->is_freed);
if (ti && ti->flags & TRACEFS_EVENT_INODE)
eventfs_set_ei_status_free(ti, dentry);
iput(inode);
} }
static const struct dentry_operations tracefs_dentry_operations = { static const struct dentry_operations tracefs_dentry_operations = {
.d_iput = tracefs_dentry_iput, .d_revalidate = tracefs_d_revalidate,
.d_release = tracefs_d_release,
}; };
static int trace_fill_super(struct super_block *sb, void *data, int silent) static int trace_fill_super(struct super_block *sb, void *data, int silent)
......
...@@ -78,6 +78,7 @@ struct dentry *tracefs_start_creating(const char *name, struct dentry *parent); ...@@ -78,6 +78,7 @@ struct dentry *tracefs_start_creating(const char *name, struct dentry *parent);
struct dentry *tracefs_end_creating(struct dentry *dentry); struct dentry *tracefs_end_creating(struct dentry *dentry);
struct dentry *tracefs_failed_creating(struct dentry *dentry); struct dentry *tracefs_failed_creating(struct dentry *dentry);
struct inode *tracefs_get_inode(struct super_block *sb); struct inode *tracefs_get_inode(struct super_block *sb);
void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry);
void eventfs_d_release(struct dentry *dentry);
#endif /* _TRACEFS_INTERNAL_H */ #endif /* _TRACEFS_INTERNAL_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment