Merge tag 'sched_ext-for-6.12' of git://git.kernel.org/pub/scm/linux/kernel/git/tj...
[linux-2.6-block.git] / include / linux / tracefs.h
CommitLineData
d2912cb1 1/* SPDX-License-Identifier: GPL-2.0-only */
4282d606
SRRH
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 *
4282d606 9 * tracefs is the file system that is used by the tracing infrastructure.
4282d606
SRRH
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
20struct file_operations;
21
22#ifdef CONFIG_TRACING
23
c1504e51
AK
24struct eventfs_file;
25
44365329
SRG
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 */
5790b1fb
SRG
62typedef int (*eventfs_callback)(const char *name, umode_t *mode, void **data,
63 const struct file_operations **fops);
c1504e51 64
b63db58e
SRG
65typedef void (*eventfs_release)(const char *name, void *data);
66
44365329
SRG
67/**
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
71 *
72 * See evenfs_callback() typedef for how to set up @callback.
73 */
5790b1fb
SRG
74struct eventfs_entry {
75 const char *name;
76 eventfs_callback callback;
b63db58e 77 eventfs_release release;
5790b1fb 78};
c1504e51 79
5790b1fb 80struct eventfs_inode;
c1504e51 81
5790b1fb
SRG
82struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry *parent,
83 const struct eventfs_entry *entries,
84 int size, void *data);
88f349b4 85
5790b1fb
SRG
86struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode *parent,
87 const struct eventfs_entry *entries,
88 int size, void *data);
88f349b4 89
2819f23a 90void eventfs_remove_events_dir(struct eventfs_inode *ei);
5790b1fb 91void eventfs_remove_dir(struct eventfs_inode *ei);
5bdcd5f5 92
4282d606
SRRH
93struct dentry *tracefs_create_file(const char *name, umode_t mode,
94 struct dentry *parent, void *data,
95 const struct file_operations *fops);
96
97struct dentry *tracefs_create_dir(const char *name, struct dentry *parent);
98
99void tracefs_remove(struct dentry *dentry);
4282d606 100
eae47358
SRRH
101struct dentry *tracefs_create_instance_dir(const char *name, struct dentry *parent,
102 int (*mkdir)(const char *name),
103 int (*rmdir)(const char *name));
104
4282d606
SRRH
105bool tracefs_initialized(void);
106
107#endif /* CONFIG_TRACING */
108
109#endif