linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6] eventfs: More fixes and clean ups
@ 2024-02-01 15:34 Steven Rostedt
  2024-02-01 15:34 ` [PATCH 1/6] eventfs: Warn if an eventfs_inode is freed without is_freed being set Steven Rostedt
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Steven Rostedt @ 2024-02-01 15:34 UTC (permalink / raw)
  To: linux-kernel, linux-trace-kernel, linux-fsdevel
  Cc: Linus Torvalds, Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers,
	Christian Brauner, Al Viro, Ajay Kaher

Al Viro reviewed the latest patch set from Linus and had some comments.
One was on the return code of the eventfs_root_lookup() which I already
sent a patch for:
  https://lore.kernel.org/linux-trace-kernel/20240131233227.73db55e1@gandalf.local.home/

The other comments had to do with code that was there before Linus's
updates. Those were:

 - It made no sense to have the fsnotify*() functions triggering
   from file/directory creation in the lookup()

 - The directory inode count wasn't accurate. The updates to
   the link nodes for the parent directory was also happening in
   lookup. Al Viro told me to just set them all to 1, as that
   tells user space not to trust the hard link counts.

I added a WARN_ON_ONCE() in case of the eventfs_inode being freed without
is_freed being set.

I restructured the eventfs_inode structure to be a bit more compact.

The last two changes I included here but do not plan on pushing for
v6.8.  Those are:

 - Adding WARN_ON_ONCE() to the conditionals that Al asked about
   as the logic should prevent them from being true.

 - Moving the dentry pointer out of eventfs_inode and creating a new
   eventfs_root_inode that contains the eventfs_inode and the dentry
   pointer. This only gets used by the "events" directory.

Steven Rostedt (Google) (6):
      eventfs: Warn if an eventfs_inode is freed without is_freed being set
      eventfs: Restructure eventfs_inode structure to be more condensed
      eventfs: Remove fsnotify*() functions from lookup()
      eventfs: Keep all directory links at 1
      eventfs: Add WARN_ON_ONCE() to checks in eventfs_root_lookup()
      eventfs: Create eventfs_root_inode to store dentry

----
 fs/tracefs/event_inode.c | 104 +++++++++++++++++++++++++++++++++++++----------
 fs/tracefs/internal.h    |  29 ++++++-------
 2 files changed, 94 insertions(+), 39 deletions(-)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/6] eventfs: Warn if an eventfs_inode is freed without is_freed being set
  2024-02-01 15:34 [PATCH 0/6] eventfs: More fixes and clean ups Steven Rostedt
@ 2024-02-01 15:34 ` Steven Rostedt
  2024-02-01 15:34 ` [PATCH 2/6] eventfs: Restructure eventfs_inode structure to be more condensed Steven Rostedt
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Steven Rostedt @ 2024-02-01 15:34 UTC (permalink / raw)
  To: linux-kernel, linux-trace-kernel, linux-fsdevel
  Cc: Linus Torvalds, Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers,
	Christian Brauner, Al Viro, Ajay Kaher

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

There should never be a case where an evenfs_inode is being freed without
is_freed being set. Add a WARN_ON_ONCE() if it ever happens. That would
mean there was one too many put_ei()s.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 fs/tracefs/event_inode.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c
index 515fdace1eea..ca7daee7c811 100644
--- a/fs/tracefs/event_inode.c
+++ b/fs/tracefs/event_inode.c
@@ -73,6 +73,9 @@ enum {
 static void release_ei(struct kref *ref)
 {
 	struct eventfs_inode *ei = container_of(ref, struct eventfs_inode, kref);
+
+	WARN_ON_ONCE(!ei->is_freed);
+
 	kfree(ei->entry_attrs);
 	kfree_const(ei->name);
 	kfree_rcu(ei, rcu);
@@ -84,6 +87,14 @@ static inline void put_ei(struct eventfs_inode *ei)
 		kref_put(&ei->kref, release_ei);
 }
 
+static inline void free_ei(struct eventfs_inode *ei)
+{
+	if (ei) {
+		ei->is_freed = 1;
+		put_ei(ei);
+	}
+}
+
 static inline struct eventfs_inode *get_ei(struct eventfs_inode *ei)
 {
 	if (ei)
@@ -679,7 +690,7 @@ struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode
 
 	/* Was the parent freed? */
 	if (list_empty(&ei->list)) {
-		put_ei(ei);
+		free_ei(ei);
 		ei = NULL;
 	}
 	return ei;
@@ -770,7 +781,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry
 	return ei;
 
  fail:
-	put_ei(ei);
+	free_ei(ei);
 	tracefs_failed_creating(dentry);
 	return ERR_PTR(-ENOMEM);
 }
@@ -801,9 +812,8 @@ static void eventfs_remove_rec(struct eventfs_inode *ei, int level)
 	list_for_each_entry(ei_child, &ei->children, list)
 		eventfs_remove_rec(ei_child, level + 1);
 
-	ei->is_freed = 1;
 	list_del(&ei->list);
-	put_ei(ei);
+	free_ei(ei);
 }
 
 /**
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/6] eventfs: Restructure eventfs_inode structure to be more condensed
  2024-02-01 15:34 [PATCH 0/6] eventfs: More fixes and clean ups Steven Rostedt
  2024-02-01 15:34 ` [PATCH 1/6] eventfs: Warn if an eventfs_inode is freed without is_freed being set Steven Rostedt
@ 2024-02-01 15:34 ` Steven Rostedt
  2024-02-01 15:34 ` [PATCH 3/6] eventfs: Remove fsnotify*() functions from lookup() Steven Rostedt
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Steven Rostedt @ 2024-02-01 15:34 UTC (permalink / raw)
  To: linux-kernel, linux-trace-kernel, linux-fsdevel
  Cc: Linus Torvalds, Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers,
	Christian Brauner, Al Viro, Ajay Kaher

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

Some of the eventfs_inode structure has holes in it. Rework the structure
to be a bit more condensed, and also remove the no longer used llist
field.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 fs/tracefs/internal.h | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h
index 1886f1826cd8..beb3dcd0e434 100644
--- a/fs/tracefs/internal.h
+++ b/fs/tracefs/internal.h
@@ -32,40 +32,37 @@ struct eventfs_attr {
 /*
  * struct eventfs_inode - hold the properties of the eventfs directories.
  * @list:	link list into the parent directory
+ * @rcu:	Union with @list for freeing
+ * @children:	link list into the child eventfs_inode
  * @entries:	the array of entries representing the files in the directory
  * @name:	the name of the directory to create
- * @children:	link list into the child eventfs_inode
  * @events_dir: the dentry of the events directory
  * @entry_attrs: Saved mode and ownership of the @d_children
- * @attr:	Saved mode and ownership of eventfs_inode itself
  * @data:	The private data to pass to the callbacks
+ * @attr:	Saved mode and ownership of eventfs_inode itself
  * @is_freed:	Flag set if the eventfs is on its way to be freed
  *                Note if is_freed is set, then dentry is corrupted.
+ * @is_events:	Flag set for only the top level "events" directory
  * @nr_entries: The number of items in @entries
+ * @ino:	The saved inode number
  */
 struct eventfs_inode {
-	struct kref			kref;
-	struct list_head		list;
+	union {
+		struct list_head	list;
+		struct rcu_head		rcu;
+	};
+	struct list_head		children;
 	const struct eventfs_entry	*entries;
 	const char			*name;
-	struct list_head		children;
 	struct dentry			*events_dir;
 	struct eventfs_attr		*entry_attrs;
-	struct eventfs_attr		attr;
 	void				*data;
+	struct eventfs_attr		attr;
+	struct kref			kref;
 	unsigned int			is_freed:1;
 	unsigned int			is_events:1;
 	unsigned int			nr_entries:30;
 	unsigned int			ino;
-	/*
-	 * Union - used for deletion
-	 * @llist:	for calling dput() if needed after RCU
-	 * @rcu:	eventfs_inode to delete in RCU
-	 */
-	union {
-		struct llist_node	llist;
-		struct rcu_head		rcu;
-	};
 };
 
 static inline struct tracefs_inode *get_tracefs(const struct inode *inode)
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/6] eventfs: Remove fsnotify*() functions from lookup()
  2024-02-01 15:34 [PATCH 0/6] eventfs: More fixes and clean ups Steven Rostedt
  2024-02-01 15:34 ` [PATCH 1/6] eventfs: Warn if an eventfs_inode is freed without is_freed being set Steven Rostedt
  2024-02-01 15:34 ` [PATCH 2/6] eventfs: Restructure eventfs_inode structure to be more condensed Steven Rostedt
@ 2024-02-01 15:34 ` Steven Rostedt
  2024-02-01 15:34 ` [PATCH 4/6] eventfs: Keep all directory links at 1 Steven Rostedt
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Steven Rostedt @ 2024-02-01 15:34 UTC (permalink / raw)
  To: linux-kernel, linux-trace-kernel, linux-fsdevel
  Cc: Linus Torvalds, Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers,
	Christian Brauner, Al Viro, Ajay Kaher, stable, Al Viro

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

The dentries and inodes are created when referenced in the lookup code.
There's no reason to call fsnotify_*() functions when they are created by
a reference. It doesn't make any sense.

Link: https://lore.kernel.org/linux-trace-kernel/20240201002719.GS2087318@ZenIV/

Cc: stable@vger.kernel.org
Fixes: a376007917776 ("eventfs: Implement functions to create files and dirs when accessed");
Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 fs/tracefs/event_inode.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c
index ca7daee7c811..9e031e5a2713 100644
--- a/fs/tracefs/event_inode.c
+++ b/fs/tracefs/event_inode.c
@@ -366,7 +366,6 @@ static struct dentry *lookup_file(struct eventfs_inode *parent_ei,
 	dentry->d_fsdata = get_ei(parent_ei);
 
 	d_add(dentry, inode);
-	fsnotify_create(dentry->d_parent->d_inode, dentry);
 	return NULL;
 };
 
@@ -408,7 +407,6 @@ static struct dentry *lookup_dir_entry(struct dentry *dentry,
 	inc_nlink(inode);
 	d_add(dentry, inode);
 	inc_nlink(dentry->d_parent->d_inode);
-	fsnotify_mkdir(dentry->d_parent->d_inode, dentry);
 	return NULL;
 }
 
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/6] eventfs: Keep all directory links at 1
  2024-02-01 15:34 [PATCH 0/6] eventfs: More fixes and clean ups Steven Rostedt
                   ` (2 preceding siblings ...)
  2024-02-01 15:34 ` [PATCH 3/6] eventfs: Remove fsnotify*() functions from lookup() Steven Rostedt
@ 2024-02-01 15:34 ` Steven Rostedt
  2024-02-01 15:34 ` [PATCH 5/6] eventfs: Add WARN_ON_ONCE() to checks in eventfs_root_lookup() Steven Rostedt
  2024-02-01 15:34 ` [PATCH 6/6] eventfs: Create eventfs_root_inode to store dentry Steven Rostedt
  5 siblings, 0 replies; 8+ messages in thread
From: Steven Rostedt @ 2024-02-01 15:34 UTC (permalink / raw)
  To: linux-kernel, linux-trace-kernel, linux-fsdevel
  Cc: Linus Torvalds, Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers,
	Christian Brauner, Al Viro, Ajay Kaher, stable, Al Viro

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

The directory link count in eventfs was somewhat bogus. It was only being
updated when a directory child was being looked up and not on creation.

One solution would be to update in get_attr() the link count by iterating
the ei->children list and then adding 2. But that could slow down simple
stat() calls, especially if it's done on all directories in eventfs.

Another solution would be to add a parent pointer to the eventfs_inode
and keep track of the number of sub directories it has on creation. But
this adds overhead for something not really worthwhile.

The solution decided upon is to keep all directory links in eventfs as 1.
This tells user space not to rely on the hard links of directories. Which
in this case it shouldn't.

Link: https://lore.kernel.org/linux-trace-kernel/20240201002719.GS2087318@ZenIV/

Cc: stable@vger.kernel.org
Fixes: c1504e510238 ("eventfs: Implement eventfs dir creation functions")
Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 fs/tracefs/event_inode.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c
index 9e031e5a2713..110e8a272189 100644
--- a/fs/tracefs/event_inode.c
+++ b/fs/tracefs/event_inode.c
@@ -404,9 +404,7 @@ static struct dentry *lookup_dir_entry(struct dentry *dentry,
 
 	dentry->d_fsdata = get_ei(ei);
 
-	inc_nlink(inode);
 	d_add(dentry, inode);
-	inc_nlink(dentry->d_parent->d_inode);
 	return NULL;
 }
 
@@ -769,9 +767,17 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry
 
 	dentry->d_fsdata = get_ei(ei);
 
-	/* directory inodes start off with i_nlink == 2 (for "." entry) */
-	inc_nlink(inode);
+	/*
+	 * Keep all eventfs directories with i_nlink == 1.
+	 * Due to the dynamic nature of the dentry creations and not
+	 * wanting to add a pointer to the parent eventfs_inode in the
+	 * eventfs_inode structure, keeping the i_nlink in sync with the
+	 * number of directories would cause too much complexity for
+	 * something not worth much. Keeping directory links at 1
+	 * tells userspace not to trust the link number.
+	 */
 	d_instantiate(dentry, inode);
+	/* The dentry of the "events" parent does keep track though */
 	inc_nlink(dentry->d_parent->d_inode);
 	fsnotify_mkdir(dentry->d_parent->d_inode, dentry);
 	tracefs_end_creating(dentry);
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 5/6] eventfs: Add WARN_ON_ONCE() to checks in eventfs_root_lookup()
  2024-02-01 15:34 [PATCH 0/6] eventfs: More fixes and clean ups Steven Rostedt
                   ` (3 preceding siblings ...)
  2024-02-01 15:34 ` [PATCH 4/6] eventfs: Keep all directory links at 1 Steven Rostedt
@ 2024-02-01 15:34 ` Steven Rostedt
  2024-02-01 17:23   ` Steven Rostedt
  2024-02-01 15:34 ` [PATCH 6/6] eventfs: Create eventfs_root_inode to store dentry Steven Rostedt
  5 siblings, 1 reply; 8+ messages in thread
From: Steven Rostedt @ 2024-02-01 15:34 UTC (permalink / raw)
  To: linux-kernel, linux-trace-kernel, linux-fsdevel
  Cc: Linus Torvalds, Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers,
	Christian Brauner, Al Viro, Ajay Kaher, Al Viro

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

There's a couple of if statements in eventfs_root_lookup() that should
never be true. Instead of removing them, add WARN_ON_ONCE() around them.

  One is a tracefs_inode not being for eventfs.

  The other is a child being freed but still on the parent's children
  list. When a child is freed, it is removed from the list under the
  same mutex that is held during the iteration.

Link: https://lore.kernel.org/linux-trace-kernel/20240201002719.GS2087318@ZenIV/

Reported-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 fs/tracefs/event_inode.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c
index 110e8a272189..1a831ba1042b 100644
--- a/fs/tracefs/event_inode.c
+++ b/fs/tracefs/event_inode.c
@@ -483,7 +483,7 @@ static struct dentry *eventfs_root_lookup(struct inode *dir,
 	struct dentry *result = NULL;
 
 	ti = get_tracefs(dir);
-	if (!(ti->flags & TRACEFS_EVENT_INODE))
+	if (WARN_ON_ONCE!(ti->flags & TRACEFS_EVENT_INODE)))
 		return ERR_PTR(-EIO);
 
 	mutex_lock(&eventfs_mutex);
@@ -495,7 +495,8 @@ static struct dentry *eventfs_root_lookup(struct inode *dir,
 	list_for_each_entry(ei_child, &ei->children, list) {
 		if (strcmp(ei_child->name, name) != 0)
 			continue;
-		if (ei_child->is_freed)
+		/* A child is freed and removed from the list at the same time */
+		if (WARN_ON_ONCE(ei_child->is_freed))
 			goto out;
 		result = lookup_dir_entry(dentry, ei, ei_child);
 		goto out;
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 6/6] eventfs: Create eventfs_root_inode to store dentry
  2024-02-01 15:34 [PATCH 0/6] eventfs: More fixes and clean ups Steven Rostedt
                   ` (4 preceding siblings ...)
  2024-02-01 15:34 ` [PATCH 5/6] eventfs: Add WARN_ON_ONCE() to checks in eventfs_root_lookup() Steven Rostedt
@ 2024-02-01 15:34 ` Steven Rostedt
  5 siblings, 0 replies; 8+ messages in thread
From: Steven Rostedt @ 2024-02-01 15:34 UTC (permalink / raw)
  To: linux-kernel, linux-trace-kernel, linux-fsdevel
  Cc: Linus Torvalds, Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers,
	Christian Brauner, Al Viro, Ajay Kaher

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

Only the root "events" directory stores a dentry. There's no reason to
hold a dentry pointer for every eventfs_inode as it is never set except
for the root "events" eventfs_inode.

Create a eventfs_root_inode structure that holds the events_dir dentry.
The "events" eventfs_inode *is* special, let it have its own descriptor.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 fs/tracefs/event_inode.c | 65 +++++++++++++++++++++++++++++++++-------
 fs/tracefs/internal.h    |  2 --
 2 files changed, 55 insertions(+), 12 deletions(-)

diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c
index 1a831ba1042b..c50d089c9a7f 100644
--- a/fs/tracefs/event_inode.c
+++ b/fs/tracefs/event_inode.c
@@ -35,6 +35,17 @@ static DEFINE_MUTEX(eventfs_mutex);
 /* Choose something "unique" ;-) */
 #define EVENTFS_FILE_INODE_INO		0x12c4e37
 
+struct eventfs_root_inode {
+	struct eventfs_inode		ei;
+	struct dentry			*events_dir;
+};
+
+static struct eventfs_root_inode *get_root_inode(struct eventfs_inode *ei)
+{
+	WARN_ON_ONCE(!ei->is_events);
+	return container_of(ei, struct eventfs_root_inode, ei);
+}
+
 /* Just try to make something consistent and unique */
 static int eventfs_dir_ino(struct eventfs_inode *ei)
 {
@@ -73,12 +84,18 @@ enum {
 static void release_ei(struct kref *ref)
 {
 	struct eventfs_inode *ei = container_of(ref, struct eventfs_inode, kref);
+	struct eventfs_root_inode *rei;
 
 	WARN_ON_ONCE(!ei->is_freed);
 
 	kfree(ei->entry_attrs);
 	kfree_const(ei->name);
-	kfree_rcu(ei, rcu);
+	if (ei->is_events) {
+		rei = get_root_inode(ei);
+		kfree_rcu(rei, ei.rcu);
+	} else {
+		kfree_rcu(ei, rcu);
+	}
 }
 
 static inline void put_ei(struct eventfs_inode *ei)
@@ -408,19 +425,43 @@ static struct dentry *lookup_dir_entry(struct dentry *dentry,
 	return NULL;
 }
 
+static inline struct eventfs_inode *init_ei(struct eventfs_inode *ei, const char *name)
+{
+	ei->name = kstrdup_const(name, GFP_KERNEL);
+	if (!ei->name)
+		return NULL;
+	kref_init(&ei->kref);
+	return ei;
+}
+
 static inline struct eventfs_inode *alloc_ei(const char *name)
 {
 	struct eventfs_inode *ei = kzalloc(sizeof(*ei), GFP_KERNEL);
+	struct eventfs_inode *result;
 
 	if (!ei)
 		return NULL;
 
-	ei->name = kstrdup_const(name, GFP_KERNEL);
-	if (!ei->name) {
+	result = init_ei(ei, name);
+	if (!result)
 		kfree(ei);
+
+	return result;
+}
+
+static inline struct eventfs_inode *alloc_root_ei(const char *name)
+{
+	struct eventfs_root_inode *rei = kzalloc(sizeof(*rei), GFP_KERNEL);
+	struct eventfs_inode *ei;
+
+	if (!rei)
 		return NULL;
-	}
-	kref_init(&ei->kref);
+
+	rei->ei.is_events = 1;
+	ei = init_ei(&rei->ei, name);
+	if (!ei)
+		kfree(rei);
+
 	return ei;
 }
 
@@ -710,6 +751,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry
 						int size, void *data)
 {
 	struct dentry *dentry = tracefs_start_creating(name, parent);
+	struct eventfs_root_inode *rei;
 	struct eventfs_inode *ei;
 	struct tracefs_inode *ti;
 	struct inode *inode;
@@ -722,7 +764,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry
 	if (IS_ERR(dentry))
 		return ERR_CAST(dentry);
 
-	ei = alloc_ei(name);
+	ei = alloc_root_ei(name);
 	if (!ei)
 		goto fail;
 
@@ -731,10 +773,11 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry
 		goto fail;
 
 	// Note: we have a ref to the dentry from tracefs_start_creating()
-	ei->events_dir = dentry;
+	rei = get_root_inode(ei);
+	rei->events_dir = dentry;
+
 	ei->entries = entries;
 	ei->nr_entries = size;
-	ei->is_events = 1;
 	ei->data = data;
 
 	/* Save the ownership of this directory */
@@ -845,13 +888,15 @@ void eventfs_remove_dir(struct eventfs_inode *ei)
  */
 void eventfs_remove_events_dir(struct eventfs_inode *ei)
 {
+	struct eventfs_root_inode *rei;
 	struct dentry *dentry;
 
-	dentry = ei->events_dir;
+	rei = get_root_inode(ei);
+	dentry = rei->events_dir;
 	if (!dentry)
 		return;
 
-	ei->events_dir = NULL;
+	rei->events_dir = NULL;
 	eventfs_remove_dir(ei);
 
 	/*
diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h
index beb3dcd0e434..15c26f9aaad4 100644
--- a/fs/tracefs/internal.h
+++ b/fs/tracefs/internal.h
@@ -36,7 +36,6 @@ struct eventfs_attr {
  * @children:	link list into the child eventfs_inode
  * @entries:	the array of entries representing the files in the directory
  * @name:	the name of the directory to create
- * @events_dir: the dentry of the events directory
  * @entry_attrs: Saved mode and ownership of the @d_children
  * @data:	The private data to pass to the callbacks
  * @attr:	Saved mode and ownership of eventfs_inode itself
@@ -54,7 +53,6 @@ struct eventfs_inode {
 	struct list_head		children;
 	const struct eventfs_entry	*entries;
 	const char			*name;
-	struct dentry			*events_dir;
 	struct eventfs_attr		*entry_attrs;
 	void				*data;
 	struct eventfs_attr		attr;
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 5/6] eventfs: Add WARN_ON_ONCE() to checks in eventfs_root_lookup()
  2024-02-01 15:34 ` [PATCH 5/6] eventfs: Add WARN_ON_ONCE() to checks in eventfs_root_lookup() Steven Rostedt
@ 2024-02-01 17:23   ` Steven Rostedt
  0 siblings, 0 replies; 8+ messages in thread
From: Steven Rostedt @ 2024-02-01 17:23 UTC (permalink / raw)
  To: linux-kernel, linux-trace-kernel, linux-fsdevel
  Cc: Linus Torvalds, Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers,
	Christian Brauner, Al Viro, Ajay Kaher

On Thu, 01 Feb 2024 10:34:51 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:

> --- a/fs/tracefs/event_inode.c
> +++ b/fs/tracefs/event_inode.c
> @@ -483,7 +483,7 @@ static struct dentry *eventfs_root_lookup(struct inode *dir,
>  	struct dentry *result = NULL;
>  
>  	ti = get_tracefs(dir);
> -	if (!(ti->flags & TRACEFS_EVENT_INODE))
> +	if (WARN_ON_ONCE!(ti->flags & TRACEFS_EVENT_INODE)))

I added this patch at the end but never tested it :-p

I then did a rebase to move it ahead of patch 6, which was tested.

Will resend this patch.

-- Steve


>  		return ERR_PTR(-EIO);
>  
>  	mutex_lock(&eventfs_mutex);

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-02-01 17:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-01 15:34 [PATCH 0/6] eventfs: More fixes and clean ups Steven Rostedt
2024-02-01 15:34 ` [PATCH 1/6] eventfs: Warn if an eventfs_inode is freed without is_freed being set Steven Rostedt
2024-02-01 15:34 ` [PATCH 2/6] eventfs: Restructure eventfs_inode structure to be more condensed Steven Rostedt
2024-02-01 15:34 ` [PATCH 3/6] eventfs: Remove fsnotify*() functions from lookup() Steven Rostedt
2024-02-01 15:34 ` [PATCH 4/6] eventfs: Keep all directory links at 1 Steven Rostedt
2024-02-01 15:34 ` [PATCH 5/6] eventfs: Add WARN_ON_ONCE() to checks in eventfs_root_lookup() Steven Rostedt
2024-02-01 17:23   ` Steven Rostedt
2024-02-01 15:34 ` [PATCH 6/6] eventfs: Create eventfs_root_inode to store dentry Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).