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 2644365329SSteven Rostedt (Google) /** 2744365329SSteven Rostedt (Google) * eventfs_callback - A callback function to create dynamic files in eventfs 2844365329SSteven Rostedt (Google) * @name: The name of the file that is to be created 2944365329SSteven Rostedt (Google) * @mode: return the file mode for the file (RW access, etc) 3044365329SSteven Rostedt (Google) * @data: data to pass to the created file ops 3144365329SSteven Rostedt (Google) * @fops: the file operations of the created file 3244365329SSteven Rostedt (Google) * 3344365329SSteven Rostedt (Google) * The evetnfs files are dynamically created. The struct eventfs_entry array 3444365329SSteven Rostedt (Google) * is passed to eventfs_create_dir() or eventfs_create_events_dir() that will 3544365329SSteven Rostedt (Google) * be used to create the files within those directories. When a lookup 3644365329SSteven Rostedt (Google) * or access to a file within the directory is made, the struct eventfs_entry 3744365329SSteven Rostedt (Google) * array is used to find a callback() with the matching name that is being 3844365329SSteven Rostedt (Google) * referenced (for lookups, the entire array is iterated and each callback 3944365329SSteven Rostedt (Google) * will be called). 4044365329SSteven Rostedt (Google) * 4144365329SSteven Rostedt (Google) * The callback will be called with @name for the name of the file to create. 4244365329SSteven Rostedt (Google) * The callback can return less than 1 to indicate that no file should be 4344365329SSteven Rostedt (Google) * created. 4444365329SSteven Rostedt (Google) * 4544365329SSteven Rostedt (Google) * If a file is to be created, then @mode should be populated with the file 4644365329SSteven Rostedt (Google) * mode (permissions) for which the file is created for. This would be 4744365329SSteven Rostedt (Google) * used to set the created inode i_mode field. 4844365329SSteven Rostedt (Google) * 4944365329SSteven Rostedt (Google) * The @data should be set to the data passed to the other file operations 5044365329SSteven Rostedt (Google) * (read, write, etc). Note, @data will also point to the data passed in 5144365329SSteven Rostedt (Google) * to eventfs_create_dir() or eventfs_create_events_dir(), but the callback 5244365329SSteven Rostedt (Google) * can replace the data if it chooses to. Otherwise, the original data 5344365329SSteven Rostedt (Google) * will be used for the file operation functions. 5444365329SSteven Rostedt (Google) * 5544365329SSteven Rostedt (Google) * The @fops should be set to the file operations that will be used to create 5644365329SSteven Rostedt (Google) * the inode. 5744365329SSteven Rostedt (Google) * 5844365329SSteven Rostedt (Google) * NB. This callback is called while holding internal locks of the eventfs 5944365329SSteven Rostedt (Google) * system. The callback must not call any code that might also call into 6044365329SSteven Rostedt (Google) * the tracefs or eventfs system or it will risk creating a deadlock. 6144365329SSteven 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*b63db58eSSteven Rostedt (Google) typedef void (*eventfs_release)(const char *name, void *data); 66*b63db58eSSteven Rostedt (Google) 6744365329SSteven Rostedt (Google) /** 6844365329SSteven Rostedt (Google) * struct eventfs_entry - dynamically created eventfs file call back handler 6944365329SSteven Rostedt (Google) * @name: Then name of the dynamic file in an eventfs directory 7044365329SSteven Rostedt (Google) * @callback: The callback to get the fops of the file when it is created 7144365329SSteven Rostedt (Google) * 7244365329SSteven Rostedt (Google) * See evenfs_callback() typedef for how to set up @callback. 7344365329SSteven Rostedt (Google) */ 745790b1fbSSteven Rostedt (Google) struct eventfs_entry { 755790b1fbSSteven Rostedt (Google) const char *name; 765790b1fbSSteven Rostedt (Google) eventfs_callback callback; 77*b63db58eSSteven Rostedt (Google) eventfs_release release; 785790b1fbSSteven Rostedt (Google) }; 79c1504e51SAjay Kaher 805790b1fbSSteven Rostedt (Google) struct eventfs_inode; 81c1504e51SAjay Kaher 825790b1fbSSteven Rostedt (Google) struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry *parent, 835790b1fbSSteven Rostedt (Google) const struct eventfs_entry *entries, 845790b1fbSSteven Rostedt (Google) int size, void *data); 8588f349b4SAjay Kaher 865790b1fbSSteven Rostedt (Google) struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode *parent, 875790b1fbSSteven Rostedt (Google) const struct eventfs_entry *entries, 885790b1fbSSteven Rostedt (Google) int size, void *data); 8988f349b4SAjay Kaher 902819f23aSSteven Rostedt (Google) void eventfs_remove_events_dir(struct eventfs_inode *ei); 915790b1fbSSteven Rostedt (Google) void eventfs_remove_dir(struct eventfs_inode *ei); 925bdcd5f5SAjay Kaher 934282d606SSteven Rostedt (Red Hat) struct dentry *tracefs_create_file(const char *name, umode_t mode, 944282d606SSteven Rostedt (Red Hat) struct dentry *parent, void *data, 954282d606SSteven Rostedt (Red Hat) const struct file_operations *fops); 964282d606SSteven Rostedt (Red Hat) 974282d606SSteven Rostedt (Red Hat) struct dentry *tracefs_create_dir(const char *name, struct dentry *parent); 984282d606SSteven Rostedt (Red Hat) 994282d606SSteven Rostedt (Red Hat) void tracefs_remove(struct dentry *dentry); 1004282d606SSteven Rostedt (Red Hat) 101eae47358SSteven Rostedt (Red Hat) struct dentry *tracefs_create_instance_dir(const char *name, struct dentry *parent, 102eae47358SSteven Rostedt (Red Hat) int (*mkdir)(const char *name), 103eae47358SSteven Rostedt (Red Hat) int (*rmdir)(const char *name)); 104eae47358SSteven Rostedt (Red Hat) 1054282d606SSteven Rostedt (Red Hat) bool tracefs_initialized(void); 1064282d606SSteven Rostedt (Red Hat) 1074282d606SSteven Rostedt (Red Hat) #endif /* CONFIG_TRACING */ 1084282d606SSteven Rostedt (Red Hat) 1094282d606SSteven Rostedt (Red Hat) #endif 110