xref: /linux/include/linux/tracefs.h (revision 44365329f8219fc379097c2c9a75ff53f123764f)
1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
24282d606SSteven Rostedt (Red Hat) /*
34282d606SSteven Rostedt (Red Hat)  *  tracefs.h - a pseudo file system for activating tracing
44282d606SSteven Rostedt (Red Hat)  *
54282d606SSteven Rostedt (Red Hat)  * Based on debugfs by: 2004 Greg Kroah-Hartman <greg@kroah.com>
64282d606SSteven Rostedt (Red Hat)  *
74282d606SSteven Rostedt (Red Hat)  *  Copyright (C) 2014 Red Hat Inc, author: Steven Rostedt <srostedt@redhat.com>
84282d606SSteven Rostedt (Red Hat)  *
94282d606SSteven Rostedt (Red Hat)  * tracefs is the file system that is used by the tracing infrastructure.
104282d606SSteven Rostedt (Red Hat)  */
114282d606SSteven Rostedt (Red Hat) 
124282d606SSteven Rostedt (Red Hat) #ifndef _TRACEFS_H_
134282d606SSteven Rostedt (Red Hat) #define _TRACEFS_H_
144282d606SSteven Rostedt (Red Hat) 
154282d606SSteven Rostedt (Red Hat) #include <linux/fs.h>
164282d606SSteven Rostedt (Red Hat) #include <linux/seq_file.h>
174282d606SSteven Rostedt (Red Hat) 
184282d606SSteven Rostedt (Red Hat) #include <linux/types.h>
194282d606SSteven Rostedt (Red Hat) 
204282d606SSteven Rostedt (Red Hat) struct file_operations;
214282d606SSteven Rostedt (Red Hat) 
224282d606SSteven Rostedt (Red Hat) #ifdef CONFIG_TRACING
234282d606SSteven Rostedt (Red Hat) 
24c1504e51SAjay Kaher struct eventfs_file;
25c1504e51SAjay Kaher 
26*44365329SSteven Rostedt (Google) /**
27*44365329SSteven Rostedt (Google)  * eventfs_callback - A callback function to create dynamic files in eventfs
28*44365329SSteven Rostedt (Google)  * @name: The name of the file that is to be created
29*44365329SSteven Rostedt (Google)  * @mode: return the file mode for the file (RW access, etc)
30*44365329SSteven Rostedt (Google)  * @data: data to pass to the created file ops
31*44365329SSteven Rostedt (Google)  * @fops: the file operations of the created file
32*44365329SSteven Rostedt (Google)  *
33*44365329SSteven Rostedt (Google)  * The evetnfs files are dynamically created. The struct eventfs_entry array
34*44365329SSteven Rostedt (Google)  * is passed to eventfs_create_dir() or eventfs_create_events_dir() that will
35*44365329SSteven Rostedt (Google)  * be used to create the files within those directories. When a lookup
36*44365329SSteven Rostedt (Google)  * or access to a file within the directory is made, the struct eventfs_entry
37*44365329SSteven Rostedt (Google)  * array is used to find a callback() with the matching name that is being
38*44365329SSteven Rostedt (Google)  * referenced (for lookups, the entire array is iterated and each callback
39*44365329SSteven Rostedt (Google)  * will be called).
40*44365329SSteven Rostedt (Google)  *
41*44365329SSteven Rostedt (Google)  * The callback will be called with @name for the name of the file to create.
42*44365329SSteven Rostedt (Google)  * The callback can return less than 1 to indicate  that no file should be
43*44365329SSteven Rostedt (Google)  * created.
44*44365329SSteven Rostedt (Google)  *
45*44365329SSteven Rostedt (Google)  * If a file is to be created, then @mode should be populated with the file
46*44365329SSteven Rostedt (Google)  * mode (permissions) for which the file is created for. This would be
47*44365329SSteven Rostedt (Google)  * used to set the created inode i_mode field.
48*44365329SSteven Rostedt (Google)  *
49*44365329SSteven Rostedt (Google)  * The @data should be set to the data passed to the other file operations
50*44365329SSteven Rostedt (Google)  * (read, write, etc). Note, @data will also point to the data passed in
51*44365329SSteven Rostedt (Google)  * to eventfs_create_dir() or eventfs_create_events_dir(), but the callback
52*44365329SSteven Rostedt (Google)  * can replace the data if it chooses to. Otherwise, the original data
53*44365329SSteven Rostedt (Google)  * will be used for the file operation functions.
54*44365329SSteven Rostedt (Google)  *
55*44365329SSteven Rostedt (Google)  * The @fops should be set to the file operations that will be used to create
56*44365329SSteven Rostedt (Google)  * the inode.
57*44365329SSteven Rostedt (Google)  *
58*44365329SSteven Rostedt (Google)  * NB. This callback is called while holding internal locks of the eventfs
59*44365329SSteven Rostedt (Google)  *     system. The callback must not call any code that might also call into
60*44365329SSteven Rostedt (Google)  *     the tracefs or eventfs system or it will risk creating a deadlock.
61*44365329SSteven Rostedt (Google)  */
625790b1fbSSteven Rostedt (Google) typedef int (*eventfs_callback)(const char *name, umode_t *mode, void **data,
635790b1fbSSteven Rostedt (Google) 				const struct file_operations **fops);
64c1504e51SAjay Kaher 
65*44365329SSteven Rostedt (Google) /**
66*44365329SSteven Rostedt (Google)  * struct eventfs_entry - dynamically created eventfs file call back handler
67*44365329SSteven Rostedt (Google)  * @name:	Then name of the dynamic file in an eventfs directory
68*44365329SSteven Rostedt (Google)  * @callback:	The callback to get the fops of the file when it is created
69*44365329SSteven Rostedt (Google)  *
70*44365329SSteven Rostedt (Google)  * See evenfs_callback() typedef for how to set up @callback.
71*44365329SSteven Rostedt (Google)  */
725790b1fbSSteven Rostedt (Google) struct eventfs_entry {
735790b1fbSSteven Rostedt (Google) 	const char			*name;
745790b1fbSSteven Rostedt (Google) 	eventfs_callback		callback;
755790b1fbSSteven Rostedt (Google) };
76c1504e51SAjay Kaher 
775790b1fbSSteven Rostedt (Google) struct eventfs_inode;
78c1504e51SAjay Kaher 
795790b1fbSSteven Rostedt (Google) struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry *parent,
805790b1fbSSteven Rostedt (Google) 						const struct eventfs_entry *entries,
815790b1fbSSteven Rostedt (Google) 						int size, void *data);
8288f349b4SAjay Kaher 
835790b1fbSSteven Rostedt (Google) struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode *parent,
845790b1fbSSteven Rostedt (Google) 					 const struct eventfs_entry *entries,
855790b1fbSSteven Rostedt (Google) 					 int size, void *data);
8688f349b4SAjay Kaher 
872819f23aSSteven Rostedt (Google) void eventfs_remove_events_dir(struct eventfs_inode *ei);
885790b1fbSSteven Rostedt (Google) void eventfs_remove_dir(struct eventfs_inode *ei);
895bdcd5f5SAjay Kaher 
904282d606SSteven Rostedt (Red Hat) struct dentry *tracefs_create_file(const char *name, umode_t mode,
914282d606SSteven Rostedt (Red Hat) 				   struct dentry *parent, void *data,
924282d606SSteven Rostedt (Red Hat) 				   const struct file_operations *fops);
934282d606SSteven Rostedt (Red Hat) 
944282d606SSteven Rostedt (Red Hat) struct dentry *tracefs_create_dir(const char *name, struct dentry *parent);
954282d606SSteven Rostedt (Red Hat) 
964282d606SSteven Rostedt (Red Hat) void tracefs_remove(struct dentry *dentry);
974282d606SSteven Rostedt (Red Hat) 
98eae47358SSteven Rostedt (Red Hat) struct dentry *tracefs_create_instance_dir(const char *name, struct dentry *parent,
99eae47358SSteven Rostedt (Red Hat) 					   int (*mkdir)(const char *name),
100eae47358SSteven Rostedt (Red Hat) 					   int (*rmdir)(const char *name));
101eae47358SSteven Rostedt (Red Hat) 
1024282d606SSteven Rostedt (Red Hat) bool tracefs_initialized(void);
1034282d606SSteven Rostedt (Red Hat) 
1044282d606SSteven Rostedt (Red Hat) #endif /* CONFIG_TRACING */
1054282d606SSteven Rostedt (Red Hat) 
1064282d606SSteven Rostedt (Red Hat) #endif
107