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 | 78 ++++++++++++++++++++++++++++++++++++++++
include/linux/tracefs.h | 4 +++
2 files changed, 82 insertions(+)
diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c
index 93134ae40..9ab675edf 100644
--- a/fs/tracefs/event_inode.c
+++ b/fs/tracefs/event_inode.c
@@ -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);
+}
diff --git a/include/linux/tracefs.h b/include/linux/tracefs.h
index 1e1780a61..ea10ccc87 100644
--- a/include/linux/tracefs.h
+++ b/include/linux/tracefs.h
@@ -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);
--
2.39.0
Hi Ajay,
kernel test robot noticed the following build warnings:
[auto build test WARNING on shuah-kselftest/next]
[also build test WARNING on shuah-kselftest/fixes linus/master rostedt-trace/for-next v6.3 next-20230428]
[cannot apply to rostedt-trace/for-next-urgent]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Ajay-Kaher/eventfs-introducing-struct-tracefs_inode/20230502-192949
base: https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git next
patch link: https://lore.kernel.org/r/1683026600-13485-5-git-send-email-akaher%40vmware.com
patch subject: [PATCH v2 4/9] eventfs: adding eventfs file, directory remove function
config: i386-randconfig-s002 (https://download.01.org/0day-ci/archive/20230503/202305030611.Kas747Ev-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-12) 11.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.4-39-gce1a6720-dirty
# https://github.com/intel-lab-lkp/linux/commit/9a36b39da0c3fbfe15a3c3a0ed71b52013bac292
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Ajay-Kaher/eventfs-introducing-struct-tracefs_inode/20230502-192949
git checkout 9a36b39da0c3fbfe15a3c3a0ed71b52013bac292
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=i386 olddefconfig
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=i386 SHELL=/bin/bash fs/tracefs/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202305030611.Kas747Ev-lkp@intel.com/
sparse warnings: (new ones prefixed by >>)
>> fs/tracefs/event_inode.c:379:6: sparse: sparse: symbol 'eventfs_remove_rec' was not declared. Should it be static?
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
Hi Ajay,
kernel test robot noticed the following build warnings:
[auto build test WARNING on shuah-kselftest/next]
[also build test WARNING on shuah-kselftest/fixes linus/master v6.3 next-20230428]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Ajay-Kaher/eventfs-introducing-struct-tracefs_inode/20230502-192949
base: https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git next
patch link: https://lore.kernel.org/r/1683026600-13485-5-git-send-email-akaher%40vmware.com
patch subject: [PATCH v2 4/9] eventfs: adding eventfs file, directory remove function
config: i386-randconfig-a011-20230501 (https://download.01.org/0day-ci/archive/20230502/202305022354.fzV9RKTT-lkp@intel.com/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/9a36b39da0c3fbfe15a3c3a0ed71b52013bac292
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Ajay-Kaher/eventfs-introducing-struct-tracefs_inode/20230502-192949
git checkout 9a36b39da0c3fbfe15a3c3a0ed71b52013bac292
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash fs/tracefs/ kernel/trace/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202305022354.fzV9RKTT-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> fs/tracefs/event_inode.c:379:6: warning: no previous prototype for function 'eventfs_remove_rec' [-Wmissing-prototypes]
void eventfs_remove_rec(struct eventfs_file *ef)
^
fs/tracefs/event_inode.c:379:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
void eventfs_remove_rec(struct eventfs_file *ef)
^
static
fs/tracefs/event_inode.c:31:29: warning: unused function 'eventfs_dentry_to_rwsem' [-Wunused-function]
static struct rw_semaphore *eventfs_dentry_to_rwsem(struct dentry *dentry)
^
fs/tracefs/event_inode.c:47:13: warning: unused function 'eventfs_down_read' [-Wunused-function]
static void eventfs_down_read(struct rw_semaphore *eventfs_rwsem)
^
fs/tracefs/event_inode.c:58:13: warning: unused function 'eventfs_up_read' [-Wunused-function]
static void eventfs_up_read(struct rw_semaphore *eventfs_rwsem)
^
4 warnings generated.
vim +/eventfs_remove_rec +379 fs/tracefs/event_inode.c
371
372 /**
373 * eventfs_remove_rec - remove eventfs dir or file from list
374 * @ef: a pointer to eventfs_file to be removed.
375 *
376 * This function recursively remove eventfs_file which
377 * contains info of file or dir.
378 */
> 379 void eventfs_remove_rec(struct eventfs_file *ef)
380 {
381 struct eventfs_file *ef_child, *n;
382
383 if (!ef)
384 return;
385
386 if (ef->ei) {
387 /* search for nested folders or files */
388 list_for_each_entry_safe(ef_child, n, &ef->ei->e_top_files, list) {
389 eventfs_remove_rec(ef_child);
390 }
391 kfree(ef->ei);
392 }
393
394 if (ef->created && ef->dentry) {
395 d_invalidate(ef->dentry);
396 dput(ef->dentry);
397 }
398 list_del(&ef->list);
399 kfree(ef->name);
400 kfree(ef);
401 }
402
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
Hi Ajay,
kernel test robot noticed the following build warnings:
[auto build test WARNING on shuah-kselftest/next]
[also build test WARNING on shuah-kselftest/fixes linus/master rostedt-trace/for-next v6.3 next-20230428]
[cannot apply to rostedt-trace/for-next-urgent]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Ajay-Kaher/eventfs-introducing-struct-tracefs_inode/20230502-192949
base: https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git next
patch link: https://lore.kernel.org/r/1683026600-13485-5-git-send-email-akaher%40vmware.com
patch subject: [PATCH v2 4/9] eventfs: adding eventfs file, directory remove function
config: arc-allyesconfig (https://download.01.org/0day-ci/archive/20230502/202305022234.nOgIYubz-lkp@intel.com/config)
compiler: arceb-elf-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/9a36b39da0c3fbfe15a3c3a0ed71b52013bac292
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Ajay-Kaher/eventfs-introducing-struct-tracefs_inode/20230502-192949
git checkout 9a36b39da0c3fbfe15a3c3a0ed71b52013bac292
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arc olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arc SHELL=/bin/bash fs/tracefs/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202305022234.nOgIYubz-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> fs/tracefs/event_inode.c:379:6: warning: no previous prototype for 'eventfs_remove_rec' [-Wmissing-prototypes]
379 | void eventfs_remove_rec(struct eventfs_file *ef)
| ^~~~~~~~~~~~~~~~~~
fs/tracefs/event_inode.c:58:13: warning: 'eventfs_up_read' defined but not used [-Wunused-function]
58 | static void eventfs_up_read(struct rw_semaphore *eventfs_rwsem)
| ^~~~~~~~~~~~~~~
fs/tracefs/event_inode.c:47:13: warning: 'eventfs_down_read' defined but not used [-Wunused-function]
47 | static void eventfs_down_read(struct rw_semaphore *eventfs_rwsem)
| ^~~~~~~~~~~~~~~~~
fs/tracefs/event_inode.c:31:29: warning: 'eventfs_dentry_to_rwsem' defined but not used [-Wunused-function]
31 | static struct rw_semaphore *eventfs_dentry_to_rwsem(struct dentry *dentry)
| ^~~~~~~~~~~~~~~~~~~~~~~
vim +/eventfs_remove_rec +379 fs/tracefs/event_inode.c
371
372 /**
373 * eventfs_remove_rec - remove eventfs dir or file from list
374 * @ef: a pointer to eventfs_file to be removed.
375 *
376 * This function recursively remove eventfs_file which
377 * contains info of file or dir.
378 */
> 379 void eventfs_remove_rec(struct eventfs_file *ef)
380 {
381 struct eventfs_file *ef_child, *n;
382
383 if (!ef)
384 return;
385
386 if (ef->ei) {
387 /* search for nested folders or files */
388 list_for_each_entry_safe(ef_child, n, &ef->ei->e_top_files, list) {
389 eventfs_remove_rec(ef_child);
390 }
391 kfree(ef->ei);
392 }
393
394 if (ef->created && ef->dentry) {
395 d_invalidate(ef->dentry);
396 dput(ef->dentry);
397 }
398 list_del(&ef->list);
399 kfree(ef->name);
400 kfree(ef);
401 }
402
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
© 2016 - 2026 Red Hat, Inc.