1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * tracefs.h - a pseudo file system for activating tracing
9 * tracefs is the file system that is used by the tracing infrastructure.
16 #include <linux/seq_file.h>
18 #include <linux/types.h>
20 struct file_operations;
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
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
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
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.
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.
55 * The @fops should be set to the file operations that will be used to create
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.
62 typedef int (*eventfs_callback)(const char *name, umode_t *mode, void **data,
63 const struct file_operations **fops);
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
70 * See evenfs_callback() typedef for how to set up @callback.
72 struct eventfs_entry {
74 eventfs_callback callback;
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);
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);
87 void eventfs_remove_events_dir(struct eventfs_inode *ei);
88 void eventfs_remove_dir(struct eventfs_inode *ei);
90 struct dentry *tracefs_create_file(const char *name, umode_t mode,
91 struct dentry *parent, void *data,
92 const struct file_operations *fops);
94 struct dentry *tracefs_create_dir(const char *name, struct dentry *parent);
96 void tracefs_remove(struct dentry *dentry);
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));
102 bool tracefs_initialized(void);
104 #endif /* CONFIG_TRACING */