xref: /linux/include/linux/tracefs.h (revision 3d0fe49454652117522f60bfbefb978ba0e5300b)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  *  tracefs.h - a pseudo file system for activating tracing
4  *
5  * Based on debugfs by: 2004 Greg Kroah-Hartman <greg@kroah.com>
6  *
7  *  Copyright (C) 2014 Red Hat Inc, author: Steven Rostedt <srostedt@redhat.com>
8  *
9  * tracefs is the file system that is used by the tracing infrastructure.
10  */
11 
12 #ifndef _TRACEFS_H_
13 #define _TRACEFS_H_
14 
15 #include <linux/fs.h>
16 #include <linux/seq_file.h>
17 
18 #include <linux/types.h>
19 
20 struct file_operations;
21 
22 #ifdef CONFIG_TRACING
23 
24 struct eventfs_file;
25 
26 /**
27  * eventfs_callback - A callback function to create dynamic files in eventfs
28  * @name: The name of the file that is to be created
29  * @mode: return the file mode for the file (RW access, etc)
30  * @data: data to pass to the created file ops
31  * @fops: the file operations of the created file
32  *
33  * The evetnfs files are dynamically created. The struct eventfs_entry array
34  * is passed to eventfs_create_dir() or eventfs_create_events_dir() that will
35  * be used to create the files within those directories. When a lookup
36  * or access to a file within the directory is made, the struct eventfs_entry
37  * array is used to find a callback() with the matching name that is being
38  * referenced (for lookups, the entire array is iterated and each callback
39  * will be called).
40  *
41  * The callback will be called with @name for the name of the file to create.
42  * The callback can return less than 1 to indicate  that no file should be
43  * created.
44  *
45  * If a file is to be created, then @mode should be populated with the file
46  * mode (permissions) for which the file is created for. This would be
47  * used to set the created inode i_mode field.
48  *
49  * The @data should be set to the data passed to the other file operations
50  * (read, write, etc). Note, @data will also point to the data passed in
51  * to eventfs_create_dir() or eventfs_create_events_dir(), but the callback
52  * can replace the data if it chooses to. Otherwise, the original data
53  * will be used for the file operation functions.
54  *
55  * The @fops should be set to the file operations that will be used to create
56  * the inode.
57  *
58  * NB. This callback is called while holding internal locks of the eventfs
59  *     system. The callback must not call any code that might also call into
60  *     the tracefs or eventfs system or it will risk creating a deadlock.
61  */
62 typedef int (*eventfs_callback)(const char *name, umode_t *mode, void **data,
63 				const struct file_operations **fops);
64 
65 /**
66  * struct eventfs_entry - dynamically created eventfs file call back handler
67  * @name:	Then name of the dynamic file in an eventfs directory
68  * @callback:	The callback to get the fops of the file when it is created
69  *
70  * See evenfs_callback() typedef for how to set up @callback.
71  */
72 struct eventfs_entry {
73 	const char			*name;
74 	eventfs_callback		callback;
75 };
76 
77 struct eventfs_inode;
78 
79 struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry *parent,
80 						const struct eventfs_entry *entries,
81 						int size, void *data);
82 
83 struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode *parent,
84 					 const struct eventfs_entry *entries,
85 					 int size, void *data);
86 
87 void eventfs_remove_events_dir(struct eventfs_inode *ei);
88 void eventfs_remove_dir(struct eventfs_inode *ei);
89 
90 struct dentry *tracefs_create_file(const char *name, umode_t mode,
91 				   struct dentry *parent, void *data,
92 				   const struct file_operations *fops);
93 
94 struct dentry *tracefs_create_dir(const char *name, struct dentry *parent);
95 
96 void tracefs_remove(struct dentry *dentry);
97 
98 struct dentry *tracefs_create_instance_dir(const char *name, struct dentry *parent,
99 					   int (*mkdir)(const char *name),
100 					   int (*rmdir)(const char *name));
101 
102 bool tracefs_initialized(void);
103 
104 #endif /* CONFIG_TRACING */
105 
106 #endif
107