Skip to content

Commit 88f349b

Browse files
akaherrostedt
authored andcommitted
eventfs: Implement eventfs file add functions
Add the following functions to add files to evenfs: eventfs_add_events_file() to add the data needed to create a specific file located at the top level events directory. The dentry/inode will be created when the events directory is scanned. eventfs_add_file() to add the data needed for files within the directories below the top level events directory. The dentry/inode of the file will be created when the directory that the file is in is scanned. Link: https://lkml.kernel.org/r/1690568452-46553-6-git-send-email-akaher@vmware.com Signed-off-by: Ajay Kaher <akaher@vmware.com> Co-developed-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Tested-by: Ching-lin Yu <chinglinyu@google.com> Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/oe-lkp/202305051619.9a469a9a-yujie.liu@intel.com Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent c1504e5 commit 88f349b

2 files changed

Lines changed: 94 additions & 0 deletions

File tree

fs/tracefs/event_inode.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,89 @@ struct eventfs_file *eventfs_add_dir(const char *name,
209209
mutex_unlock(&eventfs_mutex);
210210
return ef;
211211
}
212+
213+
/**
214+
* eventfs_add_events_file - add the data needed to create a file for later reference
215+
* @name: the name of the file to create.
216+
* @mode: the permission that the file should have.
217+
* @parent: parent dentry for this file.
218+
* @data: something that the caller will want to get to later on.
219+
* @fop: struct file_operations that should be used for this file.
220+
*
221+
* This function is used to add the information needed to create a
222+
* dentry/inode within the top level events directory. The file created
223+
* will have the @mode permissions. The @data will be used to fill the
224+
* inode.i_private when the open() call is done. The dentry and inodes are
225+
* all created when they are referenced, and removed when they are no
226+
* longer referenced.
227+
*/
228+
int eventfs_add_events_file(const char *name, umode_t mode,
229+
struct dentry *parent, void *data,
230+
const struct file_operations *fop)
231+
{
232+
struct tracefs_inode *ti;
233+
struct eventfs_inode *ei;
234+
struct eventfs_file *ef;
235+
236+
if (!parent)
237+
return -EINVAL;
238+
239+
if (!(mode & S_IFMT))
240+
mode |= S_IFREG;
241+
242+
if (!parent->d_inode)
243+
return -EINVAL;
244+
245+
ti = get_tracefs(parent->d_inode);
246+
if (!(ti->flags & TRACEFS_EVENT_INODE))
247+
return -EINVAL;
248+
249+
ei = ti->private;
250+
ef = eventfs_prepare_ef(name, mode, fop, NULL, data);
251+
252+
if (IS_ERR(ef))
253+
return -ENOMEM;
254+
255+
mutex_lock(&eventfs_mutex);
256+
list_add_tail(&ef->list, &ei->e_top_files);
257+
mutex_unlock(&eventfs_mutex);
258+
return 0;
259+
}
260+
261+
/**
262+
* eventfs_add_file - add eventfs file to list to create later
263+
* @name: the name of the file to create.
264+
* @mode: the permission that the file should have.
265+
* @ef_parent: parent eventfs_file for this file.
266+
* @data: something that the caller will want to get to later on.
267+
* @fop: struct file_operations that should be used for this file.
268+
*
269+
* This function is used to add the information needed to create a
270+
* file within a subdirectory of the events directory. The file created
271+
* will have the @mode permissions. The @data will be used to fill the
272+
* inode.i_private when the open() call is done. The dentry and inodes are
273+
* all created when they are referenced, and removed when they are no
274+
* longer referenced.
275+
*/
276+
int eventfs_add_file(const char *name, umode_t mode,
277+
struct eventfs_file *ef_parent,
278+
void *data,
279+
const struct file_operations *fop)
280+
{
281+
struct eventfs_file *ef;
282+
283+
if (!ef_parent)
284+
return -EINVAL;
285+
286+
if (!(mode & S_IFMT))
287+
mode |= S_IFREG;
288+
289+
ef = eventfs_prepare_ef(name, mode, fop, NULL, data);
290+
if (IS_ERR(ef))
291+
return -ENOMEM;
292+
293+
mutex_lock(&eventfs_mutex);
294+
list_add_tail(&ef->list, &ef_parent->ei->e_top_files);
295+
mutex_unlock(&eventfs_mutex);
296+
return 0;
297+
}

include/linux/tracefs.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ struct eventfs_file *eventfs_add_subsystem_dir(const char *name,
3232
struct eventfs_file *eventfs_add_dir(const char *name,
3333
struct eventfs_file *ef_parent);
3434

35+
int eventfs_add_file(const char *name, umode_t mode,
36+
struct eventfs_file *ef_parent, void *data,
37+
const struct file_operations *fops);
38+
39+
int eventfs_add_events_file(const char *name, umode_t mode,
40+
struct dentry *parent, void *data,
41+
const struct file_operations *fops);
42+
3543
struct dentry *tracefs_create_file(const char *name, umode_t mode,
3644
struct dentry *parent, void *data,
3745
const struct file_operations *fops);

0 commit comments

Comments
 (0)