Skip to content

Commit

Permalink
eventfs: adding eventfs file, directory remove function
Browse files Browse the repository at this point in the history
Adding eventfs_remove(), this function will recursively remove
dir or file info from eventfs.

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>
  • Loading branch information
akaher authored and intel-lab-lkp committed May 2, 2023
1 parent 67ecafa commit 9a36b39
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
78 changes: 78 additions & 0 deletions fs/tracefs/event_inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,81 @@ int eventfs_add_file(const char *name, umode_t mode,
eventfs_up_write(eventfs_rwsem);
return 0;
}

/**
* eventfs_remove_rec - remove eventfs dir or file from list
* @ef: a pointer to eventfs_file to be removed.
*
* This function recursively remove eventfs_file which
* contains info of file or dir.
*/
void eventfs_remove_rec(struct eventfs_file *ef)
{
struct eventfs_file *ef_child, *n;

if (!ef)
return;

if (ef->ei) {
/* search for nested folders or files */
list_for_each_entry_safe(ef_child, n, &ef->ei->e_top_files, list) {
eventfs_remove_rec(ef_child);
}
kfree(ef->ei);
}

if (ef->created && ef->dentry) {
d_invalidate(ef->dentry);
dput(ef->dentry);
}
list_del(&ef->list);
kfree(ef->name);
kfree(ef);
}

/**
* eventfs_remove - remove eventfs dir or file from list
* @ef: a pointer to eventfs_file to be removed.
*
* This function acquire the eventfs_rwsem lock and call eventfs_remove_rec()
*/
void eventfs_remove(struct eventfs_file *ef)
{
struct rw_semaphore *eventfs_rwsem;

if (!ef)
return;

if (ef->ei)
eventfs_rwsem = (struct rw_semaphore *) ef->data;
else
eventfs_rwsem = (struct rw_semaphore *) ef->d_parent->d_inode->i_private;

eventfs_down_write(eventfs_rwsem);
eventfs_remove_rec(ef);
eventfs_up_write(eventfs_rwsem);
}

/**
* eventfs_remove_events_dir - remove eventfs dir or file from list
* @dentry: a pointer to events's dentry to be removed.
*
* This function remove events main directory
*/
void eventfs_remove_events_dir(struct dentry *dentry)
{
struct tracefs_inode *ti;
struct eventfs_inode *ei;

if (!dentry || !dentry->d_inode)
return;

ti = get_tracefs(dentry->d_inode);
if (!ti || !(ti->flags & TRACEFS_EVENT_INODE))
return;

ei = ti->private;
d_invalidate(dentry);
dput(dentry);
kfree(ei);
}
4 changes: 4 additions & 0 deletions include/linux/tracefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ int eventfs_add_top_file(const char *name, umode_t mode,
struct dentry *parent, void *data,
const struct file_operations *fops);

void eventfs_remove(struct eventfs_file *ef);

void eventfs_remove_events_dir(struct dentry *dentry);

struct dentry *tracefs_create_file(const char *name, umode_t mode,
struct dentry *parent, void *data,
const struct file_operations *fops);
Expand Down

0 comments on commit 9a36b39

Please sign in to comment.