1 // SPDX-License-Identifier: GPL-2.0-only
3 * event_inode.c - part of tracefs, a pseudo file system for activating tracing
5 * Copyright (C) 2020-23 VMware Inc, author: Steven Rostedt (VMware) <rostedt@goodmis.org>
6 * Copyright (C) 2020-23 VMware Inc, author: Ajay Kaher <akaher@vmware.com>
8 * eventfs is used to dynamically create inodes and dentries based on the
9 * meta data provided by the tracing system.
11 * eventfs stores the meta-data of files/dirs and holds off on creating
12 * inodes/dentries of the files. When accessed, the eventfs will create the
13 * inodes/dentries in a just-in-time (JIT) manner. The eventfs will clean up
14 * and delete the inodes/dentries when they are no longer referenced.
16 #include <linux/fsnotify.h>
18 #include <linux/namei.h>
19 #include <linux/workqueue.h>
20 #include <linux/security.h>
21 #include <linux/tracefs.h>
22 #include <linux/kref.h>
23 #include <linux/delay.h>
26 struct eventfs_inode {
27 struct list_head e_top_files;
31 * struct eventfs_file - hold the properties of the eventfs files and
33 * @name: the name of the file or directory to create
34 * @d_parent: holds parent's dentry
35 * @dentry: once accessed holds dentry
36 * @list: file or directory to be added to parent directory
37 * @ei: list of files and directories within directory
38 * @fop: file_operations for file or directory
39 * @iop: inode_operations for file or directory
40 * @data: something that the caller will want to get to later on
41 * @is_freed: Flag set if the eventfs is on its way to be freed
42 * @mode: the permission that the file or directory should have
43 * @uid: saved uid if changed
44 * @gid: saved gid if changed
48 struct dentry *d_parent;
49 struct dentry *dentry;
50 struct list_head list;
51 struct eventfs_inode *ei;
52 const struct file_operations *fop;
53 const struct inode_operations *iop;
55 * Union - used for deletion
56 * @llist: for calling dput() if needed after RCU
57 * @rcu: eventfs_file to delete in RCU
60 struct llist_node llist;
64 unsigned int is_freed:1;
70 static DEFINE_MUTEX(eventfs_mutex);
71 DEFINE_STATIC_SRCU(eventfs_srcu);
73 /* Mode is unsigned short, use the upper bits for flags */
75 EVENTFS_SAVE_MODE = BIT(16),
76 EVENTFS_SAVE_UID = BIT(17),
77 EVENTFS_SAVE_GID = BIT(18),
80 #define EVENTFS_MODE_MASK (EVENTFS_SAVE_MODE - 1)
82 static struct dentry *eventfs_root_lookup(struct inode *dir,
83 struct dentry *dentry,
85 static int dcache_dir_open_wrapper(struct inode *inode, struct file *file);
86 static int dcache_readdir_wrapper(struct file *file, struct dir_context *ctx);
87 static int eventfs_release(struct inode *inode, struct file *file);
89 static void update_attr(struct eventfs_file *ef, struct iattr *iattr)
91 unsigned int ia_valid = iattr->ia_valid;
93 if (ia_valid & ATTR_MODE) {
94 ef->mode = (ef->mode & ~EVENTFS_MODE_MASK) |
95 (iattr->ia_mode & EVENTFS_MODE_MASK) |
98 if (ia_valid & ATTR_UID) {
99 ef->mode |= EVENTFS_SAVE_UID;
100 ef->uid = iattr->ia_uid;
102 if (ia_valid & ATTR_GID) {
103 ef->mode |= EVENTFS_SAVE_GID;
104 ef->gid = iattr->ia_gid;
108 static int eventfs_set_attr(struct mnt_idmap *idmap, struct dentry *dentry,
111 struct eventfs_file *ef;
114 mutex_lock(&eventfs_mutex);
115 ef = dentry->d_fsdata;
116 if (ef && ef->is_freed) {
117 /* Do not allow changes if the event is about to be removed. */
118 mutex_unlock(&eventfs_mutex);
122 ret = simple_setattr(idmap, dentry, iattr);
124 update_attr(ef, iattr);
125 mutex_unlock(&eventfs_mutex);
129 static const struct inode_operations eventfs_root_dir_inode_operations = {
130 .lookup = eventfs_root_lookup,
131 .setattr = eventfs_set_attr,
134 static const struct inode_operations eventfs_file_inode_operations = {
135 .setattr = eventfs_set_attr,
138 static const struct file_operations eventfs_file_operations = {
139 .open = dcache_dir_open_wrapper,
140 .read = generic_read_dir,
141 .iterate_shared = dcache_readdir_wrapper,
142 .llseek = generic_file_llseek,
143 .release = eventfs_release,
146 static void update_inode_attr(struct inode *inode, struct eventfs_file *ef)
148 inode->i_mode = ef->mode & EVENTFS_MODE_MASK;
150 if (ef->mode & EVENTFS_SAVE_UID)
151 inode->i_uid = ef->uid;
153 if (ef->mode & EVENTFS_SAVE_GID)
154 inode->i_gid = ef->gid;
158 * create_file - create a file in the tracefs filesystem
159 * @ef: the eventfs_file
160 * @parent: parent dentry for this file.
161 * @data: something that the caller will want to get to later on.
162 * @fop: struct file_operations that should be used for this file.
164 * This is the basic "create a file" function for tracefs. It allows for a
165 * wide range of flexibility in creating a file.
167 * This function will return a pointer to a dentry if it succeeds. This
168 * pointer must be passed to the tracefs_remove() function when the file is
169 * to be removed (no automatic cleanup happens if your module is unloaded,
170 * you are responsible here.) If an error occurs, %NULL will be returned.
172 * If tracefs is not enabled in the kernel, the value -%ENODEV will be
175 static struct dentry *create_file(struct eventfs_file *ef,
176 struct dentry *parent, void *data,
177 const struct file_operations *fop)
179 struct tracefs_inode *ti;
180 struct dentry *dentry;
183 if (!(ef->mode & S_IFMT))
186 if (WARN_ON_ONCE(!S_ISREG(ef->mode)))
189 dentry = eventfs_start_creating(ef->name, parent);
194 inode = tracefs_get_inode(dentry->d_sb);
195 if (unlikely(!inode))
196 return eventfs_failed_creating(dentry);
198 /* If the user updated the directory's attributes, use them */
199 update_inode_attr(inode, ef);
201 inode->i_op = &eventfs_file_inode_operations;
203 inode->i_private = data;
205 ti = get_tracefs(inode);
206 ti->flags |= TRACEFS_EVENT_INODE;
207 d_instantiate(dentry, inode);
208 fsnotify_create(dentry->d_parent->d_inode, dentry);
209 return eventfs_end_creating(dentry);
213 * create_dir - create a dir in the tracefs filesystem
214 * @ei: the eventfs_inode that represents the directory to create
215 * @parent: parent dentry for this file.
216 * @data: something that the caller will want to get to later on.
218 * This is the basic "create a dir" function for eventfs. It allows for a
219 * wide range of flexibility in creating a dir.
221 * This function will return a pointer to a dentry if it succeeds. This
222 * pointer must be passed to the tracefs_remove() function when the file is
223 * to be removed (no automatic cleanup happens if your module is unloaded,
224 * you are responsible here.) If an error occurs, %NULL will be returned.
226 * If tracefs is not enabled in the kernel, the value -%ENODEV will be
229 static struct dentry *create_dir(struct eventfs_file *ef,
230 struct dentry *parent, void *data)
232 struct tracefs_inode *ti;
233 struct dentry *dentry;
236 dentry = eventfs_start_creating(ef->name, parent);
240 inode = tracefs_get_inode(dentry->d_sb);
241 if (unlikely(!inode))
242 return eventfs_failed_creating(dentry);
244 update_inode_attr(inode, ef);
246 inode->i_op = &eventfs_root_dir_inode_operations;
247 inode->i_fop = &eventfs_file_operations;
248 inode->i_private = data;
250 ti = get_tracefs(inode);
251 ti->flags |= TRACEFS_EVENT_INODE;
254 d_instantiate(dentry, inode);
255 inc_nlink(dentry->d_parent->d_inode);
256 fsnotify_mkdir(dentry->d_parent->d_inode, dentry);
257 return eventfs_end_creating(dentry);
260 static void free_ef(struct eventfs_file *ef)
268 * eventfs_set_ef_status_free - set the ef->status to free
269 * @ti: the tracefs_inode of the dentry
270 * @dentry: dentry who's status to be freed
272 * eventfs_set_ef_status_free will be called if no more
275 void eventfs_set_ef_status_free(struct tracefs_inode *ti, struct dentry *dentry)
277 struct eventfs_inode *ei;
278 struct eventfs_file *ef;
280 /* The top level events directory may be freed by this */
281 if (unlikely(ti->flags & TRACEFS_EVENT_TOP_INODE)) {
282 mutex_lock(&eventfs_mutex);
285 /* Nothing should access this, but just in case! */
287 mutex_unlock(&eventfs_mutex);
289 ef = dentry->d_fsdata;
295 mutex_lock(&eventfs_mutex);
297 ef = dentry->d_fsdata;
307 dentry->d_fsdata = NULL;
309 mutex_unlock(&eventfs_mutex);
313 * eventfs_post_create_dir - post create dir routine
314 * @ef: eventfs_file of recently created dir
316 * Map the meta-data of files within an eventfs dir to their parent dentry
318 static void eventfs_post_create_dir(struct eventfs_file *ef)
320 struct eventfs_file *ef_child;
321 struct tracefs_inode *ti;
323 /* srcu lock already held */
324 /* fill parent-child relation */
325 list_for_each_entry_srcu(ef_child, &ef->ei->e_top_files, list,
326 srcu_read_lock_held(&eventfs_srcu)) {
327 ef_child->d_parent = ef->dentry;
330 ti = get_tracefs(ef->dentry->d_inode);
331 ti->private = ef->ei;
335 * create_dentry - helper function to create dentry
336 * @ef: eventfs_file of file or directory to create
337 * @parent: parent dentry
338 * @lookup: true if called from lookup routine
340 * Used to create a dentry for file/dir, executes post dentry creation routine
342 static struct dentry *
343 create_dentry(struct eventfs_file *ef, struct dentry *parent, bool lookup)
345 bool invalidate = false;
346 struct dentry *dentry;
348 mutex_lock(&eventfs_mutex);
350 mutex_unlock(&eventfs_mutex);
355 /* On dir open, up the ref count */
358 mutex_unlock(&eventfs_mutex);
361 mutex_unlock(&eventfs_mutex);
364 inode_lock(parent->d_inode);
367 dentry = create_dir(ef, parent, ef->data);
369 dentry = create_file(ef, parent, ef->data, ef->fop);
372 inode_unlock(parent->d_inode);
374 mutex_lock(&eventfs_mutex);
375 if (IS_ERR_OR_NULL(dentry)) {
376 /* If the ef was already updated get it */
378 if (dentry && !lookup)
380 mutex_unlock(&eventfs_mutex);
384 if (!ef->dentry && !ef->is_freed) {
387 eventfs_post_create_dir(ef);
388 dentry->d_fsdata = ef;
390 /* A race here, should try again (unless freed) */
394 * Should never happen unless we get here due to being freed.
395 * Otherwise it means two dentries exist with the same name.
397 WARN_ON_ONCE(!ef->is_freed);
399 mutex_unlock(&eventfs_mutex);
401 d_invalidate(dentry);
403 if (lookup || invalidate)
406 return invalidate ? NULL : dentry;
409 static bool match_event_file(struct eventfs_file *ef, const char *name)
413 mutex_lock(&eventfs_mutex);
414 ret = !ef->is_freed && strcmp(ef->name, name) == 0;
415 mutex_unlock(&eventfs_mutex);
421 * eventfs_root_lookup - lookup routine to create file/dir
422 * @dir: in which a lookup is being done
423 * @dentry: file/dir dentry
424 * @flags: to pass as flags parameter to simple lookup
426 * Used to create a dynamic file/dir within @dir. Use the eventfs_inode
427 * list of meta data to find the information needed to create the file/dir.
429 static struct dentry *eventfs_root_lookup(struct inode *dir,
430 struct dentry *dentry,
433 struct tracefs_inode *ti;
434 struct eventfs_inode *ei;
435 struct eventfs_file *ef;
436 struct dentry *ret = NULL;
439 ti = get_tracefs(dir);
440 if (!(ti->flags & TRACEFS_EVENT_INODE))
444 idx = srcu_read_lock(&eventfs_srcu);
445 list_for_each_entry_srcu(ef, &ei->e_top_files, list,
446 srcu_read_lock_held(&eventfs_srcu)) {
447 if (!match_event_file(ef, dentry->d_name.name))
449 ret = simple_lookup(dir, dentry, flags);
450 create_dentry(ef, ef->d_parent, true);
453 srcu_read_unlock(&eventfs_srcu, idx);
459 struct dentry **dentries;
463 * eventfs_release - called to release eventfs file/dir
464 * @inode: inode to be released
465 * @file: file to be released (not used)
467 static int eventfs_release(struct inode *inode, struct file *file)
469 struct tracefs_inode *ti;
470 struct dentry_list *dlist = file->private_data;
474 ti = get_tracefs(inode);
475 if (!(ti->flags & TRACEFS_EVENT_INODE))
478 if (WARN_ON_ONCE(!dlist))
481 for (i = 0; dlist->dentries && dlist->dentries[i]; i++) {
482 dput(dlist->dentries[i]);
485 cursor = dlist->cursor;
486 kfree(dlist->dentries);
488 file->private_data = cursor;
489 return dcache_dir_close(inode, file);
493 * dcache_dir_open_wrapper - eventfs open wrapper
495 * @file: dir to be opened (to create its child)
497 * Used to dynamically create the file/dir within @file. @file is really a
498 * directory and all the files/dirs of the children within @file will be
499 * created. If any of the files/dirs have already been created, their
500 * reference count will be incremented.
502 static int dcache_dir_open_wrapper(struct inode *inode, struct file *file)
504 struct tracefs_inode *ti;
505 struct eventfs_inode *ei;
506 struct eventfs_file *ef;
507 struct dentry_list *dlist;
508 struct dentry **dentries = NULL;
509 struct dentry *dentry = file_dentry(file);
511 struct inode *f_inode = file_inode(file);
516 ti = get_tracefs(f_inode);
517 if (!(ti->flags & TRACEFS_EVENT_INODE))
520 if (WARN_ON_ONCE(file->private_data))
523 dlist = kmalloc(sizeof(*dlist), GFP_KERNEL);
528 idx = srcu_read_lock(&eventfs_srcu);
529 list_for_each_entry_srcu(ef, &ei->e_top_files, list,
530 srcu_read_lock_held(&eventfs_srcu)) {
531 d = create_dentry(ef, dentry, false);
536 tmp = krealloc(dentries, sizeof(d) * (cnt + 2), GFP_KERNEL);
545 srcu_read_unlock(&eventfs_srcu, idx);
546 ret = dcache_dir_open(inode, file);
549 * dcache_dir_open() sets file->private_data to a dentry cursor.
550 * Need to save that but also save all the dentries that were
551 * opened by this function.
553 dlist->cursor = file->private_data;
554 dlist->dentries = dentries;
555 file->private_data = dlist;
560 * This just sets the file->private_data back to the cursor and back.
562 static int dcache_readdir_wrapper(struct file *file, struct dir_context *ctx)
564 struct dentry_list *dlist = file->private_data;
567 file->private_data = dlist->cursor;
568 ret = dcache_readdir(file, ctx);
569 dlist->cursor = file->private_data;
570 file->private_data = dlist;
575 * eventfs_prepare_ef - helper function to prepare eventfs_file
576 * @name: the name of the file/directory to create.
577 * @mode: the permission that the file should have.
578 * @fop: struct file_operations that should be used for this file/directory.
579 * @iop: struct inode_operations that should be used for this file/directory.
580 * @data: something that the caller will want to get to later on. The
581 * inode.i_private pointer will point to this value on the open() call.
583 * This function allocates and fills the eventfs_file structure.
585 static struct eventfs_file *eventfs_prepare_ef(const char *name, umode_t mode,
586 const struct file_operations *fop,
587 const struct inode_operations *iop,
590 struct eventfs_file *ef;
592 ef = kzalloc(sizeof(*ef), GFP_KERNEL);
594 return ERR_PTR(-ENOMEM);
596 ef->name = kstrdup(name, GFP_KERNEL);
599 return ERR_PTR(-ENOMEM);
603 ef->ei = kzalloc(sizeof(*ef->ei), GFP_KERNEL);
607 return ERR_PTR(-ENOMEM);
609 INIT_LIST_HEAD(&ef->ei->e_top_files);
610 ef->mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
623 * eventfs_create_events_dir - create the trace event structure
624 * @name: the name of the directory to create.
625 * @parent: parent dentry for this file. This should be a directory dentry
626 * if set. If this parameter is NULL, then the directory will be
627 * created in the root of the tracefs filesystem.
629 * This function creates the top of the trace event directory.
631 struct dentry *eventfs_create_events_dir(const char *name,
632 struct dentry *parent)
634 struct dentry *dentry = tracefs_start_creating(name, parent);
635 struct eventfs_inode *ei;
636 struct tracefs_inode *ti;
639 if (security_locked_down(LOCKDOWN_TRACEFS))
645 ei = kzalloc(sizeof(*ei), GFP_KERNEL);
647 return ERR_PTR(-ENOMEM);
648 inode = tracefs_get_inode(dentry->d_sb);
649 if (unlikely(!inode)) {
651 tracefs_failed_creating(dentry);
652 return ERR_PTR(-ENOMEM);
655 INIT_LIST_HEAD(&ei->e_top_files);
657 ti = get_tracefs(inode);
658 ti->flags |= TRACEFS_EVENT_INODE | TRACEFS_EVENT_TOP_INODE;
661 inode->i_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
662 inode->i_op = &eventfs_root_dir_inode_operations;
663 inode->i_fop = &eventfs_file_operations;
665 /* directory inodes start off with i_nlink == 2 (for "." entry) */
667 d_instantiate(dentry, inode);
668 inc_nlink(dentry->d_parent->d_inode);
669 fsnotify_mkdir(dentry->d_parent->d_inode, dentry);
670 return tracefs_end_creating(dentry);
674 * eventfs_add_subsystem_dir - add eventfs subsystem_dir to list to create later
675 * @name: the name of the file to create.
676 * @parent: parent dentry for this dir.
678 * This function adds eventfs subsystem dir to list.
679 * And all these dirs are created on the fly when they are looked up,
680 * and the dentry and inodes will be removed when they are done.
682 struct eventfs_file *eventfs_add_subsystem_dir(const char *name,
683 struct dentry *parent)
685 struct tracefs_inode *ti_parent;
686 struct eventfs_inode *ei_parent;
687 struct eventfs_file *ef;
689 if (security_locked_down(LOCKDOWN_TRACEFS))
693 return ERR_PTR(-EINVAL);
695 ti_parent = get_tracefs(parent->d_inode);
696 ei_parent = ti_parent->private;
698 ef = eventfs_prepare_ef(name, S_IFDIR, NULL, NULL, NULL);
702 mutex_lock(&eventfs_mutex);
703 list_add_tail(&ef->list, &ei_parent->e_top_files);
704 ef->d_parent = parent;
705 mutex_unlock(&eventfs_mutex);
710 * eventfs_add_dir - add eventfs dir to list to create later
711 * @name: the name of the file to create.
712 * @ef_parent: parent eventfs_file for this dir.
714 * This function adds eventfs dir to list.
715 * And all these dirs are created on the fly when they are looked up,
716 * and the dentry and inodes will be removed when they are done.
718 struct eventfs_file *eventfs_add_dir(const char *name,
719 struct eventfs_file *ef_parent)
721 struct eventfs_file *ef;
723 if (security_locked_down(LOCKDOWN_TRACEFS))
727 return ERR_PTR(-EINVAL);
729 ef = eventfs_prepare_ef(name, S_IFDIR, NULL, NULL, NULL);
733 mutex_lock(&eventfs_mutex);
734 list_add_tail(&ef->list, &ef_parent->ei->e_top_files);
735 ef->d_parent = ef_parent->dentry;
736 mutex_unlock(&eventfs_mutex);
741 * eventfs_add_events_file - add the data needed to create a file for later reference
742 * @name: the name of the file to create.
743 * @mode: the permission that the file should have.
744 * @parent: parent dentry for this file.
745 * @data: something that the caller will want to get to later on.
746 * @fop: struct file_operations that should be used for this file.
748 * This function is used to add the information needed to create a
749 * dentry/inode within the top level events directory. The file created
750 * will have the @mode permissions. The @data will be used to fill the
751 * inode.i_private when the open() call is done. The dentry and inodes are
752 * all created when they are referenced, and removed when they are no
755 int eventfs_add_events_file(const char *name, umode_t mode,
756 struct dentry *parent, void *data,
757 const struct file_operations *fop)
759 struct tracefs_inode *ti;
760 struct eventfs_inode *ei;
761 struct eventfs_file *ef;
763 if (security_locked_down(LOCKDOWN_TRACEFS))
769 if (!(mode & S_IFMT))
772 if (!parent->d_inode)
775 ti = get_tracefs(parent->d_inode);
776 if (!(ti->flags & TRACEFS_EVENT_INODE))
780 ef = eventfs_prepare_ef(name, mode, fop, NULL, data);
785 mutex_lock(&eventfs_mutex);
786 list_add_tail(&ef->list, &ei->e_top_files);
787 ef->d_parent = parent;
788 mutex_unlock(&eventfs_mutex);
793 * eventfs_add_file - add eventfs file to list to create later
794 * @name: the name of the file to create.
795 * @mode: the permission that the file should have.
796 * @ef_parent: parent eventfs_file for this file.
797 * @data: something that the caller will want to get to later on.
798 * @fop: struct file_operations that should be used for this file.
800 * This function is used to add the information needed to create a
801 * file within a subdirectory of the events directory. The file created
802 * will have the @mode permissions. The @data will be used to fill the
803 * inode.i_private when the open() call is done. The dentry and inodes are
804 * all created when they are referenced, and removed when they are no
807 int eventfs_add_file(const char *name, umode_t mode,
808 struct eventfs_file *ef_parent,
810 const struct file_operations *fop)
812 struct eventfs_file *ef;
814 if (security_locked_down(LOCKDOWN_TRACEFS))
820 if (!(mode & S_IFMT))
823 ef = eventfs_prepare_ef(name, mode, fop, NULL, data);
827 mutex_lock(&eventfs_mutex);
828 list_add_tail(&ef->list, &ef_parent->ei->e_top_files);
829 ef->d_parent = ef_parent->dentry;
830 mutex_unlock(&eventfs_mutex);
834 static LLIST_HEAD(free_list);
836 static void eventfs_workfn(struct work_struct *work)
838 struct eventfs_file *ef, *tmp;
839 struct llist_node *llnode;
841 llnode = llist_del_all(&free_list);
842 llist_for_each_entry_safe(ef, tmp, llnode, llist) {
843 /* This should only get here if it had a dentry */
844 if (!WARN_ON_ONCE(!ef->dentry))
849 static DECLARE_WORK(eventfs_work, eventfs_workfn);
851 static void free_rcu_ef(struct rcu_head *head)
853 struct eventfs_file *ef = container_of(head, struct eventfs_file, rcu);
856 /* Do not free the ef until all references of dentry are gone */
857 if (llist_add(&ef->llist, &free_list))
858 queue_work(system_unbound_wq, &eventfs_work);
865 static void unhook_dentry(struct dentry *dentry)
870 * Need to add a reference to the dentry that is expected by
871 * simple_recursive_removal(), which will include a dput().
876 * Also add a reference for the dput() in eventfs_workfn().
877 * That is required as that dput() will free the ei after
878 * the SRCU grace period is over.
884 * eventfs_remove_rec - remove eventfs dir or file from list
885 * @ef: eventfs_file to be removed.
886 * @level: to check recursion depth
888 * The helper function eventfs_remove_rec() is used to clean up and free the
889 * associated data from eventfs for both of the added functions.
891 static void eventfs_remove_rec(struct eventfs_file *ef, int level)
893 struct eventfs_file *ef_child;
898 * Check recursion depth. It should never be greater than 3:
901 * 2 - events/group/event/
902 * 3 - events/group/event/file
904 if (WARN_ON_ONCE(level > 3))
908 /* search for nested folders or files */
909 list_for_each_entry_srcu(ef_child, &ef->ei->e_top_files, list,
910 lockdep_is_held(&eventfs_mutex)) {
911 eventfs_remove_rec(ef_child, level + 1);
917 unhook_dentry(ef->dentry);
919 list_del_rcu(&ef->list);
920 call_srcu(&eventfs_srcu, &ef->rcu, free_rcu_ef);
924 * eventfs_remove - remove eventfs dir or file from list
925 * @ef: eventfs_file to be removed.
927 * This function acquire the eventfs_mutex lock and call eventfs_remove_rec()
929 void eventfs_remove(struct eventfs_file *ef)
931 struct dentry *dentry;
936 mutex_lock(&eventfs_mutex);
938 eventfs_remove_rec(ef, 0);
939 mutex_unlock(&eventfs_mutex);
942 * If any of the ei children has a dentry, then the ei itself
943 * must have a dentry.
946 simple_recursive_removal(dentry, NULL);
950 * eventfs_remove_events_dir - remove eventfs dir or file from list
951 * @dentry: events's dentry to be removed.
953 * This function remove events main directory
955 void eventfs_remove_events_dir(struct dentry *dentry)
957 struct eventfs_file *ef_child;
958 struct eventfs_inode *ei;
959 struct tracefs_inode *ti;
961 if (!dentry || !dentry->d_inode)
964 ti = get_tracefs(dentry->d_inode);
965 if (!ti || !(ti->flags & TRACEFS_EVENT_INODE))
968 mutex_lock(&eventfs_mutex);
970 list_for_each_entry_srcu(ef_child, &ei->e_top_files, list,
971 lockdep_is_held(&eventfs_mutex)) {
972 eventfs_remove_rec(ef_child, 0);
974 mutex_unlock(&eventfs_mutex);