1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * tracefs.h - a pseudo file system for activating tracing
5 * Based on debugfs by: 2004 Greg Kroah-Hartman <greg@kroah.com>
7 * Copyright (C) 2014 Red Hat Inc, author: Steven Rostedt <srostedt@redhat.com>
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
);
65 typedef void (*eventfs_release
)(const char *name
, void *data
);
68 * struct eventfs_entry - dynamically created eventfs file call back handler
69 * @name: Then name of the dynamic file in an eventfs directory
70 * @callback: The callback to get the fops of the file when it is created
72 * See evenfs_callback() typedef for how to set up @callback.
74 struct eventfs_entry
{
76 eventfs_callback callback
;
77 eventfs_release release
;
82 struct eventfs_inode
*eventfs_create_events_dir(const char *name
, struct dentry
*parent
,
83 const struct eventfs_entry
*entries
,
84 int size
, void *data
);
86 struct eventfs_inode
*eventfs_create_dir(const char *name
, struct eventfs_inode
*parent
,
87 const struct eventfs_entry
*entries
,
88 int size
, void *data
);
90 void eventfs_remove_events_dir(struct eventfs_inode
*ei
);
91 void eventfs_remove_dir(struct eventfs_inode
*ei
);
93 struct dentry
*tracefs_create_file(const char *name
, umode_t mode
,
94 struct dentry
*parent
, void *data
,
95 const struct file_operations
*fops
);
97 struct dentry
*tracefs_create_dir(const char *name
, struct dentry
*parent
);
99 void tracefs_remove(struct dentry
*dentry
);
101 struct dentry
*tracefs_create_instance_dir(const char *name
, struct dentry
*parent
,
102 int (*mkdir
)(const char *name
),
103 int (*rmdir
)(const char *name
));
105 bool tracefs_initialized(void);
107 #endif /* CONFIG_TRACING */