[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1674407228-49109-4-git-send-email-akaher@vmware.com>
Date: Sun, 22 Jan 2023 22:37:03 +0530
From: Ajay Kaher <akaher@...are.com>
To: rostedt@...dmis.org, mhiramat@...nel.org
Cc: linux-kernel@...r.kernel.org, linux-trace-kernel@...r.kernel.org,
chinglinyu@...gle.com, namit@...are.com, srivatsab@...are.com,
srivatsa@...il.mit.edu, amakhalov@...are.com,
vsirnapalli@...are.com, tkundu@...are.com, er.ajay.kaher@...il.com,
Ajay Kaher <akaher@...are.com>
Subject: [PATCH 4/8] eventfs: adding eventfs file, directory remove function
Adding eventfs_remove(), this function will recursively remove
dir or file info from eventfs.
Signed-off-by: Ajay Kaher <akaher@...are.com>
Co-developed-by: Steven Rostedt (VMware) <rostedt@...dmis.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@...dmis.org>
Tested-by: Ching-lin Yu <chinglinyu@...gle.com>
---
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
Powered by blists - more mailing lists