xref: /openbmc/linux/fs/tracefs/internal.h (revision 5f91fc82)
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 	TRACEFS_GID_PERM_SET		= BIT(3),
9 	TRACEFS_UID_PERM_SET		= BIT(4),
10 	TRACEFS_INSTANCE_INODE		= BIT(5),
11 };
12 
13 struct tracefs_inode {
14 	union {
15 		struct inode            vfs_inode;
16 		struct rcu_head		rcu;
17 	};
18 	/* The below gets initialized with memset_after(ti, 0, vfs_inode) */
19 	struct list_head	list;
20 	unsigned long           flags;
21 	void                    *private;
22 };
23 
24 /*
25  * struct eventfs_attr - cache the mode and ownership of a eventfs entry
26  * @mode:	saved mode plus flags of what is saved
27  * @uid:	saved uid if changed
28  * @gid:	saved gid if changed
29  */
30 struct eventfs_attr {
31 	int				mode;
32 	kuid_t				uid;
33 	kgid_t				gid;
34 };
35 
36 /*
37  * struct eventfs_inode - hold the properties of the eventfs directories.
38  * @list:	link list into the parent directory
39  * @rcu:	Union with @list for freeing
40  * @children:	link list into the child eventfs_inode
41  * @entries:	the array of entries representing the files in the directory
42  * @name:	the name of the directory to create
43  * @events_dir: the dentry of the events directory
44  * @entry_attrs: Saved mode and ownership of the @d_children
45  * @data:	The private data to pass to the callbacks
46  * @attr:	Saved mode and ownership of eventfs_inode itself
47  * @is_freed:	Flag set if the eventfs is on its way to be freed
48  *                Note if is_freed is set, then dentry is corrupted.
49  * @is_events:	Flag set for only the top level "events" directory
50  * @nr_entries: The number of items in @entries
51  * @ino:	The saved inode number
52  */
53 struct eventfs_inode {
54 	union {
55 		struct list_head	list;
56 		struct rcu_head		rcu;
57 	};
58 	struct list_head		children;
59 	const struct eventfs_entry	*entries;
60 	const char			*name;
61 	struct dentry			*events_dir;
62 	struct eventfs_attr		*entry_attrs;
63 	void				*data;
64 	struct eventfs_attr		attr;
65 	struct kref			kref;
66 	unsigned int			is_freed:1;
67 	unsigned int			is_events:1;
68 	unsigned int			nr_entries:30;
69 	unsigned int			ino;
70 };
71 
72 static inline struct tracefs_inode *get_tracefs(const struct inode *inode)
73 {
74 	return container_of(inode, struct tracefs_inode, vfs_inode);
75 }
76 
77 struct dentry *tracefs_start_creating(const char *name, struct dentry *parent);
78 struct dentry *tracefs_end_creating(struct dentry *dentry);
79 struct dentry *tracefs_failed_creating(struct dentry *dentry);
80 struct inode *tracefs_get_inode(struct super_block *sb);
81 
82 void eventfs_remount(struct tracefs_inode *ti, bool update_uid, bool update_gid);
83 void eventfs_d_release(struct dentry *dentry);
84 
85 #endif /* _TRACEFS_INTERNAL_H */
86