diff mbox series

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

Message ID 1674407228-49109-4-git-send-email-akaher@vmware.com (mailing list archive)
State Changes Requested
Headers show
Series [1/8] eventfs: introducing struct tracefs_inode | expand

Commit Message

Ajay Kaher Jan. 22, 2023, 5:07 p.m. UTC
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>
---
 fs/tracefs/event_inode.c | 26 ++++++++++++++++++++++++++
 include/linux/tracefs.h  |  2 ++
 2 files changed, 28 insertions(+)
diff mbox series

Patch

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);