[PATCH 4/8] eventfs: adding eventfs file, directory remove function

From: Ajay Kaher
Date: Sun Jan 22 2023 - 12:07:56 EST


Adding eventfs_remove(), this function will recursively remove
dir or file info from eventfs.

Signed-off-by: Ajay Kaher <akaher@xxxxxxxxxx>
Co-developed-by: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx>
Signed-off-by: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx>
Tested-by: Ching-lin Yu <chinglinyu@xxxxxxxxxx>
---
fs/tracefs/event_inode.c | 26 ++++++++++++++++++++++++++
include/linux/tracefs.h | 2 ++
2 files changed, 28 insertions(+)

diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c
index e479712..4d47da0 100644
--- a/fs/tracefs/event_inode.c
+++ b/fs/tracefs/event_inode.c
@@ -279,3 +279,29 @@ int eventfs_add_file(const char *name, umode_t mode,
list_add_tail(&ef->list, &ef_parent->ei->e_top_files);
return 0;
}
+
+/**
+ * eventfs_remove - remove eventfs dir or file from list
+ * @eventfs_file: a pointer to eventfs_file to be removed.
+ *
+ * This function recursively remove eventfs_file which
+ * contains info of file or dir.
+ */
+void eventfs_remove(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(ef_child);
+ }
+ kfree(ef->ei);
+ }
+ list_del(&ef->list);
+ kfree(ef->name);
+ kfree(ef);
+}
diff --git a/include/linux/tracefs.h b/include/linux/tracefs.h
index 7d390d2..b02cbba 100644
--- a/include/linux/tracefs.h
+++ b/include/linux/tracefs.h
@@ -55,6 +55,8 @@ 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);
+
struct dentry *tracefs_create_file(const char *name, umode_t mode,
struct dentry *parent, void *data,
const struct file_operations *fops);
--
2.7.4