xref: /linux/fs/tracefs/internal.h (revision 0678df8271820bcf8fb4f877129f05d68a237de4)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _TRACEFS_INTERNAL_H
3 #define _TRACEFS_INTERNAL_H
4 
5 enum {
6 	TRACEFS_EVENT_INODE		= BIT(1),
7 	TRACEFS_EVENT_TOP_INODE		= BIT(2),
8 };
9 
10 struct tracefs_inode {
11 	unsigned long           flags;
12 	void                    *private;
13 	struct inode            vfs_inode;
14 };
15 
16 /*
17  * struct eventfs_attr - cache the mode and ownership of a eventfs entry
18  * @mode:	saved mode plus flags of what is saved
19  * @uid:	saved uid if changed
20  * @gid:	saved gid if changed
21  */
22 struct eventfs_attr {
23 	int				mode;
24 	kuid_t				uid;
25 	kgid_t				gid;
26 };
27 
28 /*
29  * struct eventfs_inode - hold the properties of the eventfs directories.
30  * @list:	link list into the parent directory
31  * @entries:	the array of entries representing the files in the directory
32  * @name:	the name of the directory to create
33  * @children:	link list into the child eventfs_inode
34  * @dentry:     the dentry of the directory
35  * @d_parent:   pointer to the parent's dentry
36  * @d_children: The array of dentries to represent the files when created
37  * @entry_attrs: Saved mode and ownership of the @d_children
38  * @attr:	Saved mode and ownership of eventfs_inode itself
39  * @data:	The private data to pass to the callbacks
40  * @is_freed:	Flag set if the eventfs is on its way to be freed
41  *                Note if is_freed is set, then dentry is corrupted.
42  * @nr_entries: The number of items in @entries
43  */
44 struct eventfs_inode {
45 	struct list_head		list;
46 	const struct eventfs_entry	*entries;
47 	const char			*name;
48 	struct list_head		children;
49 	struct dentry			*dentry; /* Check is_freed to access */
50 	struct dentry			*d_parent;
51 	struct dentry			**d_children;
52 	struct eventfs_attr		*entry_attrs;
53 	struct eventfs_attr		attr;
54 	void				*data;
55 	/*
56 	 * Union - used for deletion
57 	 * @llist:	for calling dput() if needed after RCU
58 	 * @rcu:	eventfs_inode to delete in RCU
59 	 */
60 	union {
61 		struct llist_node	llist;
62 		struct rcu_head		rcu;
63 	};
64 	unsigned int			is_freed:1;
65 	unsigned int			nr_entries:31;
66 };
67 
68 static inline struct tracefs_inode *get_tracefs(const struct inode *inode)
69 {
70 	return container_of(inode, struct tracefs_inode, vfs_inode);
71 }
72 
73 struct dentry *tracefs_start_creating(const char *name, struct dentry *parent);
74 struct dentry *tracefs_end_creating(struct dentry *dentry);
75 struct dentry *tracefs_failed_creating(struct dentry *dentry);
76 struct inode *tracefs_get_inode(struct super_block *sb);
77 struct dentry *eventfs_start_creating(const char *name, struct dentry *parent);
78 struct dentry *eventfs_failed_creating(struct dentry *dentry);
79 struct dentry *eventfs_end_creating(struct dentry *dentry);
80 void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry);
81 
82 #endif /* _TRACEFS_INTERNAL_H */
83