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 <rostedt@goodmis.org>
6 * Copyright (C) 2020-23 VMware Inc, author: Ajay Kaher <akaher@vmware.com>
7 * Copyright (C) 2023 Google, author: Steven Rostedt <rostedt@goodmis.org>
9 * eventfs is used to dynamically create inodes and dentries based on the
10 * meta data provided by the tracing system.
12 * eventfs stores the meta-data of files/dirs and holds off on creating
13 * inodes/dentries of the files. When accessed, the eventfs will create the
14 * inodes/dentries in a just-in-time (JIT) manner. The eventfs will clean up
15 * and delete the inodes/dentries when they are no longer referenced.
17 #include <linux/fsnotify.h>
19 #include <linux/namei.h>
20 #include <linux/workqueue.h>
21 #include <linux/security.h>
22 #include <linux/tracefs.h>
23 #include <linux/kref.h>
24 #include <linux/delay.h>
28 * eventfs_mutex protects the eventfs_inode (ei) dentry. Any access
29 * to the ei->dentry must be done under this mutex and after checking
30 * if ei->is_freed is not set. When ei->is_freed is set, the dentry
31 * is on its way to being freed after the last dput() is made on it.
33 static DEFINE_MUTEX(eventfs_mutex);
35 /* Choose something "unique" ;-) */
36 #define EVENTFS_FILE_INODE_INO 0x12c4e37
38 struct eventfs_root_inode {
39 struct eventfs_inode ei;
40 struct inode *parent_inode;
41 struct dentry *events_dir;
44 static struct eventfs_root_inode *get_root_inode(struct eventfs_inode *ei)
46 WARN_ON_ONCE(!ei->is_events);
47 return container_of(ei, struct eventfs_root_inode, ei);
50 /* Just try to make something consistent and unique */
51 static int eventfs_dir_ino(struct eventfs_inode *ei)
54 ei->ino = get_next_ino();
60 * The eventfs_inode (ei) itself is protected by SRCU. It is released from
61 * its parent's list and will have is_freed set (under eventfs_mutex).
62 * After the SRCU grace period is over and the last dput() is called
65 DEFINE_STATIC_SRCU(eventfs_srcu);
67 /* Mode is unsigned short, use the upper bits for flags */
69 EVENTFS_SAVE_MODE = BIT(16),
70 EVENTFS_SAVE_UID = BIT(17),
71 EVENTFS_SAVE_GID = BIT(18),
74 #define EVENTFS_MODE_MASK (EVENTFS_SAVE_MODE - 1)
76 static void free_ei_rcu(struct rcu_head *rcu)
78 struct eventfs_inode *ei = container_of(rcu, struct eventfs_inode, rcu);
79 struct eventfs_root_inode *rei;
81 kfree(ei->entry_attrs);
82 kfree_const(ei->name);
84 rei = get_root_inode(ei);
92 * eventfs_inode reference count management.
94 * NOTE! We count only references from dentries, in the
95 * form 'dentry->d_fsdata'. There are also references from
96 * directory inodes ('ti->private'), but the dentry reference
97 * count is always a superset of the inode reference count.
99 static void release_ei(struct kref *ref)
101 struct eventfs_inode *ei = container_of(ref, struct eventfs_inode, kref);
102 const struct eventfs_entry *entry;
104 WARN_ON_ONCE(!ei->is_freed);
106 for (int i = 0; i < ei->nr_entries; i++) {
107 entry = &ei->entries[i];
109 entry->release(entry->name, ei->data);
112 call_rcu(&ei->rcu, free_ei_rcu);
115 static inline void put_ei(struct eventfs_inode *ei)
118 kref_put(&ei->kref, release_ei);
121 static inline void free_ei(struct eventfs_inode *ei)
130 * Called when creation of an ei fails, do not call release() functions.
132 static inline void cleanup_ei(struct eventfs_inode *ei)
135 /* Set nr_entries to 0 to prevent release() function being called */
141 static inline struct eventfs_inode *get_ei(struct eventfs_inode *ei)
148 static struct dentry *eventfs_root_lookup(struct inode *dir,
149 struct dentry *dentry,
151 static int eventfs_iterate(struct file *file, struct dir_context *ctx);
153 static void update_attr(struct eventfs_attr *attr, struct iattr *iattr)
155 unsigned int ia_valid = iattr->ia_valid;
157 if (ia_valid & ATTR_MODE) {
158 attr->mode = (attr->mode & ~EVENTFS_MODE_MASK) |
159 (iattr->ia_mode & EVENTFS_MODE_MASK) |
162 if (ia_valid & ATTR_UID) {
163 attr->mode |= EVENTFS_SAVE_UID;
164 attr->uid = iattr->ia_uid;
166 if (ia_valid & ATTR_GID) {
167 attr->mode |= EVENTFS_SAVE_GID;
168 attr->gid = iattr->ia_gid;
172 static int eventfs_set_attr(struct mnt_idmap *idmap, struct dentry *dentry,
175 const struct eventfs_entry *entry;
176 struct eventfs_inode *ei;
180 mutex_lock(&eventfs_mutex);
181 ei = dentry->d_fsdata;
183 /* Do not allow changes if the event is about to be removed. */
184 mutex_unlock(&eventfs_mutex);
188 /* Preallocate the children mode array if necessary */
189 if (!(dentry->d_inode->i_mode & S_IFDIR)) {
190 if (!ei->entry_attrs) {
191 ei->entry_attrs = kcalloc(ei->nr_entries, sizeof(*ei->entry_attrs),
193 if (!ei->entry_attrs) {
200 ret = simple_setattr(idmap, dentry, iattr);
205 * If this is a dir, then update the ei cache, only the file
206 * mode is saved in the ei->m_children, and the ownership is
207 * determined by the parent directory.
209 if (dentry->d_inode->i_mode & S_IFDIR) {
210 update_attr(&ei->attr, iattr);
213 name = dentry->d_name.name;
215 for (int i = 0; i < ei->nr_entries; i++) {
216 entry = &ei->entries[i];
217 if (strcmp(name, entry->name) == 0) {
218 update_attr(&ei->entry_attrs[i], iattr);
224 mutex_unlock(&eventfs_mutex);
228 static void update_events_attr(struct eventfs_inode *ei, struct super_block *sb)
230 struct eventfs_root_inode *rei;
231 struct inode *parent;
233 rei = get_root_inode(ei);
235 /* Use the parent inode permissions unless root set its permissions */
236 parent = rei->parent_inode;
238 if (rei->ei.attr.mode & EVENTFS_SAVE_UID)
239 ei->attr.uid = rei->ei.attr.uid;
241 ei->attr.uid = parent->i_uid;
243 if (rei->ei.attr.mode & EVENTFS_SAVE_GID)
244 ei->attr.gid = rei->ei.attr.gid;
246 ei->attr.gid = parent->i_gid;
249 static void set_top_events_ownership(struct inode *inode)
251 struct tracefs_inode *ti = get_tracefs(inode);
252 struct eventfs_inode *ei = ti->private;
254 /* The top events directory doesn't get automatically updated */
255 if (!ei || !ei->is_events)
258 update_events_attr(ei, inode->i_sb);
260 if (!(ei->attr.mode & EVENTFS_SAVE_UID))
261 inode->i_uid = ei->attr.uid;
263 if (!(ei->attr.mode & EVENTFS_SAVE_GID))
264 inode->i_gid = ei->attr.gid;
267 static int eventfs_get_attr(struct mnt_idmap *idmap,
268 const struct path *path, struct kstat *stat,
269 u32 request_mask, unsigned int flags)
271 struct dentry *dentry = path->dentry;
272 struct inode *inode = d_backing_inode(dentry);
274 set_top_events_ownership(inode);
276 generic_fillattr(idmap, request_mask, inode, stat);
280 static int eventfs_permission(struct mnt_idmap *idmap,
281 struct inode *inode, int mask)
283 set_top_events_ownership(inode);
284 return generic_permission(idmap, inode, mask);
287 static const struct inode_operations eventfs_dir_inode_operations = {
288 .lookup = eventfs_root_lookup,
289 .setattr = eventfs_set_attr,
290 .getattr = eventfs_get_attr,
291 .permission = eventfs_permission,
294 static const struct inode_operations eventfs_file_inode_operations = {
295 .setattr = eventfs_set_attr,
298 static const struct file_operations eventfs_file_operations = {
299 .read = generic_read_dir,
300 .iterate_shared = eventfs_iterate,
301 .llseek = generic_file_llseek,
305 * On a remount of tracefs, if UID or GID options are set, then
306 * the mount point inode permissions should be used.
307 * Reset the saved permission flags appropriately.
309 void eventfs_remount(struct tracefs_inode *ti, bool update_uid, bool update_gid)
311 struct eventfs_inode *ei = ti->private;
317 ei->attr.mode &= ~EVENTFS_SAVE_UID;
320 ei->attr.mode &= ~EVENTFS_SAVE_GID;
322 if (!ei->entry_attrs)
325 for (int i = 0; i < ei->nr_entries; i++) {
327 ei->entry_attrs[i].mode &= ~EVENTFS_SAVE_UID;
329 ei->entry_attrs[i].mode &= ~EVENTFS_SAVE_GID;
333 /* Return the evenfs_inode of the "events" directory */
334 static struct eventfs_inode *eventfs_find_events(struct dentry *dentry)
336 struct eventfs_inode *ei;
339 // The parent is stable because we do not do renames
340 dentry = dentry->d_parent;
341 // ... and directories always have d_fsdata
342 ei = dentry->d_fsdata;
345 * If the ei is being freed, the ownership of the children
352 // Walk upwards until you find the events inode
353 } while (!ei->is_events);
355 update_events_attr(ei, dentry->d_sb);
360 static void update_inode_attr(struct dentry *dentry, struct inode *inode,
361 struct eventfs_attr *attr, umode_t mode)
363 struct eventfs_inode *events_ei = eventfs_find_events(dentry);
368 inode->i_mode = mode;
369 inode->i_uid = events_ei->attr.uid;
370 inode->i_gid = events_ei->attr.gid;
375 if (attr->mode & EVENTFS_SAVE_MODE)
376 inode->i_mode = attr->mode & EVENTFS_MODE_MASK;
378 if (attr->mode & EVENTFS_SAVE_UID)
379 inode->i_uid = attr->uid;
381 if (attr->mode & EVENTFS_SAVE_GID)
382 inode->i_gid = attr->gid;
386 * lookup_file - look up a file in the tracefs filesystem
387 * @parent_ei: Pointer to the eventfs_inode that represents parent of the file
388 * @dentry: the dentry to look up
389 * @mode: the permission that the file should have.
390 * @attr: saved attributes changed by user
391 * @data: something that the caller will want to get to later on.
392 * @fop: struct file_operations that should be used for this file.
394 * This function creates a dentry that represents a file in the eventsfs_inode
395 * directory. The inode.i_private pointer will point to @data in the open()
398 static struct dentry *lookup_file(struct eventfs_inode *parent_ei,
399 struct dentry *dentry,
401 struct eventfs_attr *attr,
403 const struct file_operations *fop)
405 struct tracefs_inode *ti;
408 if (!(mode & S_IFMT))
411 if (WARN_ON_ONCE(!S_ISREG(mode)))
412 return ERR_PTR(-EIO);
414 inode = tracefs_get_inode(dentry->d_sb);
415 if (unlikely(!inode))
416 return ERR_PTR(-ENOMEM);
418 /* If the user updated the directory's attributes, use them */
419 update_inode_attr(dentry, inode, attr, mode);
421 inode->i_op = &eventfs_file_inode_operations;
423 inode->i_private = data;
425 /* All files will have the same inode number */
426 inode->i_ino = EVENTFS_FILE_INODE_INO;
428 ti = get_tracefs(inode);
429 ti->flags |= TRACEFS_EVENT_INODE;
431 // Files have their parent's ei as their fsdata
432 dentry->d_fsdata = get_ei(parent_ei);
434 d_add(dentry, inode);
439 * lookup_dir_entry - look up a dir in the tracefs filesystem
440 * @dentry: the directory to look up
441 * @pei: Pointer to the parent eventfs_inode if available
442 * @ei: the eventfs_inode that represents the directory to create
444 * This function will look up a dentry for a directory represented by
447 static struct dentry *lookup_dir_entry(struct dentry *dentry,
448 struct eventfs_inode *pei, struct eventfs_inode *ei)
450 struct tracefs_inode *ti;
453 inode = tracefs_get_inode(dentry->d_sb);
454 if (unlikely(!inode))
455 return ERR_PTR(-ENOMEM);
457 /* If the user updated the directory's attributes, use them */
458 update_inode_attr(dentry, inode, &ei->attr,
459 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO);
461 inode->i_op = &eventfs_dir_inode_operations;
462 inode->i_fop = &eventfs_file_operations;
464 /* All directories will have the same inode number */
465 inode->i_ino = eventfs_dir_ino(ei);
467 ti = get_tracefs(inode);
468 ti->flags |= TRACEFS_EVENT_INODE;
469 /* Only directories have ti->private set to an ei, not files */
472 dentry->d_fsdata = get_ei(ei);
474 d_add(dentry, inode);
478 static inline struct eventfs_inode *init_ei(struct eventfs_inode *ei, const char *name)
480 ei->name = kstrdup_const(name, GFP_KERNEL);
483 kref_init(&ei->kref);
487 static inline struct eventfs_inode *alloc_ei(const char *name)
489 struct eventfs_inode *ei = kzalloc(sizeof(*ei), GFP_KERNEL);
490 struct eventfs_inode *result;
495 result = init_ei(ei, name);
502 static inline struct eventfs_inode *alloc_root_ei(const char *name)
504 struct eventfs_root_inode *rei = kzalloc(sizeof(*rei), GFP_KERNEL);
505 struct eventfs_inode *ei;
510 rei->ei.is_events = 1;
511 ei = init_ei(&rei->ei, name);
519 * eventfs_d_release - dentry is going away
520 * @dentry: dentry which has the reference to remove.
522 * Remove the association between a dentry from an eventfs_inode.
524 void eventfs_d_release(struct dentry *dentry)
526 put_ei(dentry->d_fsdata);
530 * lookup_file_dentry - create a dentry for a file of an eventfs_inode
531 * @dentry: The parent dentry under which the new file's dentry will be created
532 * @ei: the eventfs_inode that the file will be created under
533 * @idx: the index into the entry_attrs[] of the @ei
534 * @mode: The mode of the file.
535 * @data: The data to use to set the inode of the file with on open()
536 * @fops: The fops of the file to be created.
538 * This function creates a dentry for a file associated with an
539 * eventfs_inode @ei. It uses the entry attributes specified by @idx,
540 * if available. The file will have the specified @mode and its inode will be
541 * set up with @data upon open. The file operations will be set to @fops.
543 * Return: Returns a pointer to the newly created file's dentry or an error
546 static struct dentry *
547 lookup_file_dentry(struct dentry *dentry,
548 struct eventfs_inode *ei, int idx,
549 umode_t mode, void *data,
550 const struct file_operations *fops)
552 struct eventfs_attr *attr = NULL;
555 attr = &ei->entry_attrs[idx];
557 return lookup_file(ei, dentry, mode, attr, data, fops);
561 * eventfs_root_lookup - lookup routine to create file/dir
562 * @dir: in which a lookup is being done
563 * @dentry: file/dir dentry
564 * @flags: Just passed to simple_lookup()
566 * Used to create dynamic file/dir with-in @dir, search with-in @ei
567 * list, if @dentry found go ahead and create the file/dir
570 static struct dentry *eventfs_root_lookup(struct inode *dir,
571 struct dentry *dentry,
574 struct eventfs_inode *ei_child;
575 struct tracefs_inode *ti;
576 struct eventfs_inode *ei;
577 const char *name = dentry->d_name.name;
578 struct dentry *result = NULL;
580 ti = get_tracefs(dir);
581 if (WARN_ON_ONCE(!(ti->flags & TRACEFS_EVENT_INODE)))
582 return ERR_PTR(-EIO);
584 mutex_lock(&eventfs_mutex);
587 if (!ei || ei->is_freed)
590 list_for_each_entry(ei_child, &ei->children, list) {
591 if (strcmp(ei_child->name, name) != 0)
593 /* A child is freed and removed from the list at the same time */
594 if (WARN_ON_ONCE(ei_child->is_freed))
596 result = lookup_dir_entry(dentry, ei, ei_child);
600 for (int i = 0; i < ei->nr_entries; i++) {
603 const struct file_operations *fops;
604 const struct eventfs_entry *entry = &ei->entries[i];
606 if (strcmp(name, entry->name) != 0)
610 if (entry->callback(name, &mode, &data, &fops) <= 0)
613 result = lookup_file_dentry(dentry, ei, i, mode, data, fops);
617 mutex_unlock(&eventfs_mutex);
622 * Walk the children of a eventfs_inode to fill in getdents().
624 static int eventfs_iterate(struct file *file, struct dir_context *ctx)
626 const struct file_operations *fops;
627 struct inode *f_inode = file_inode(file);
628 const struct eventfs_entry *entry;
629 struct eventfs_inode *ei_child;
630 struct tracefs_inode *ti;
631 struct eventfs_inode *ei;
639 if (!dir_emit_dots(file, ctx))
642 ti = get_tracefs(f_inode);
643 if (!(ti->flags & TRACEFS_EVENT_INODE))
648 idx = srcu_read_lock(&eventfs_srcu);
650 mutex_lock(&eventfs_mutex);
651 ei = READ_ONCE(ti->private);
652 if (ei && ei->is_freed)
654 mutex_unlock(&eventfs_mutex);
660 * Need to create the dentries and inodes to have a consistent
665 /* Start at 'c' to jump over already read entries */
666 for (i = c; i < ei->nr_entries; i++, ctx->pos++) {
667 void *cdata = ei->data;
669 entry = &ei->entries[i];
672 mutex_lock(&eventfs_mutex);
673 /* If ei->is_freed then just bail here, nothing more to do */
675 mutex_unlock(&eventfs_mutex);
678 r = entry->callback(name, &mode, &cdata, &fops);
679 mutex_unlock(&eventfs_mutex);
683 ino = EVENTFS_FILE_INODE_INO;
685 if (!dir_emit(ctx, name, strlen(name), ino, DT_REG))
689 /* Subtract the skipped entries above */
690 c -= min((unsigned int)c, (unsigned int)ei->nr_entries);
692 list_for_each_entry_srcu(ei_child, &ei->children, list,
693 srcu_read_lock_held(&eventfs_srcu)) {
702 if (ei_child->is_freed)
705 name = ei_child->name;
707 ino = eventfs_dir_ino(ei_child);
709 if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR))
714 srcu_read_unlock(&eventfs_srcu, idx);
719 /* Incremented ctx->pos without adding something, reset it */
725 * eventfs_create_dir - Create the eventfs_inode for this directory
726 * @name: The name of the directory to create.
727 * @parent: The eventfs_inode of the parent directory.
728 * @entries: A list of entries that represent the files under this directory
729 * @size: The number of @entries
730 * @data: The default data to pass to the files (an entry may override it).
732 * This function creates the descriptor to represent a directory in the
733 * eventfs. This descriptor is an eventfs_inode, and it is returned to be
734 * used to create other children underneath.
736 * The @entries is an array of eventfs_entry structures which has:
738 * eventfs_callback callback;
740 * The name is the name of the file, and the callback is a pointer to a function
741 * that will be called when the file is reference (either by lookup or by
742 * reading a directory). The callback is of the prototype:
744 * int callback(const char *name, umode_t *mode, void **data,
745 * const struct file_operations **fops);
747 * When a file needs to be created, this callback will be called with
748 * name = the name of the file being created (so that the same callback
749 * may be used for multiple files).
750 * mode = a place to set the file's mode
751 * data = A pointer to @data, and the callback may replace it, which will
752 * cause the file created to pass the new data to the open() call.
753 * fops = the fops to use for the created file.
755 * NB. @callback is called while holding internal locks of the eventfs
756 * system. The callback must not call any code that might also call into
757 * the tracefs or eventfs system or it will risk creating a deadlock.
759 struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode *parent,
760 const struct eventfs_entry *entries,
761 int size, void *data)
763 struct eventfs_inode *ei;
766 return ERR_PTR(-EINVAL);
770 return ERR_PTR(-ENOMEM);
772 ei->entries = entries;
773 ei->nr_entries = size;
775 INIT_LIST_HEAD(&ei->children);
776 INIT_LIST_HEAD(&ei->list);
778 mutex_lock(&eventfs_mutex);
779 if (!parent->is_freed)
780 list_add_tail(&ei->list, &parent->children);
781 mutex_unlock(&eventfs_mutex);
783 /* Was the parent freed? */
784 if (list_empty(&ei->list)) {
792 * eventfs_create_events_dir - create the top level events directory
793 * @name: The name of the top level directory to create.
794 * @parent: Parent dentry for this file in the tracefs directory.
795 * @entries: A list of entries that represent the files under this directory
796 * @size: The number of @entries
797 * @data: The default data to pass to the files (an entry may override it).
799 * This function creates the top of the trace event directory.
801 * See eventfs_create_dir() for use of @entries.
803 struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry *parent,
804 const struct eventfs_entry *entries,
805 int size, void *data)
807 struct dentry *dentry = tracefs_start_creating(name, parent);
808 struct eventfs_root_inode *rei;
809 struct eventfs_inode *ei;
810 struct tracefs_inode *ti;
815 if (security_locked_down(LOCKDOWN_TRACEFS))
819 return ERR_CAST(dentry);
821 ei = alloc_root_ei(name);
825 inode = tracefs_get_inode(dentry->d_sb);
826 if (unlikely(!inode))
829 // Note: we have a ref to the dentry from tracefs_start_creating()
830 rei = get_root_inode(ei);
831 rei->events_dir = dentry;
832 rei->parent_inode = d_inode(dentry->d_sb->s_root);
834 ei->entries = entries;
835 ei->nr_entries = size;
838 /* Save the ownership of this directory */
839 uid = d_inode(dentry->d_parent)->i_uid;
840 gid = d_inode(dentry->d_parent)->i_gid;
846 * When the "events" directory is created, it takes on the
847 * permissions of its parent. But can be reset on remount.
849 ei->attr.mode |= EVENTFS_SAVE_UID | EVENTFS_SAVE_GID;
851 INIT_LIST_HEAD(&ei->children);
852 INIT_LIST_HEAD(&ei->list);
854 ti = get_tracefs(inode);
855 ti->flags |= TRACEFS_EVENT_INODE;
858 inode->i_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
861 inode->i_op = &eventfs_dir_inode_operations;
862 inode->i_fop = &eventfs_file_operations;
864 dentry->d_fsdata = get_ei(ei);
867 * Keep all eventfs directories with i_nlink == 1.
868 * Due to the dynamic nature of the dentry creations and not
869 * wanting to add a pointer to the parent eventfs_inode in the
870 * eventfs_inode structure, keeping the i_nlink in sync with the
871 * number of directories would cause too much complexity for
872 * something not worth much. Keeping directory links at 1
873 * tells userspace not to trust the link number.
875 d_instantiate(dentry, inode);
876 /* The dentry of the "events" parent does keep track though */
877 inc_nlink(dentry->d_parent->d_inode);
878 fsnotify_mkdir(dentry->d_parent->d_inode, dentry);
879 tracefs_end_creating(dentry);
885 tracefs_failed_creating(dentry);
886 return ERR_PTR(-ENOMEM);
890 * eventfs_remove_rec - remove eventfs dir or file from list
891 * @ei: eventfs_inode to be removed.
892 * @level: prevent recursion from going more than 3 levels deep.
894 * This function recursively removes eventfs_inodes which
895 * contains info of files and/or directories.
897 static void eventfs_remove_rec(struct eventfs_inode *ei, int level)
899 struct eventfs_inode *ei_child;
902 * Check recursion depth. It should never be greater than 3:
905 * 2 - events/group/event/
906 * 3 - events/group/event/file
908 if (WARN_ON_ONCE(level > 3))
911 /* search for nested folders or files */
912 list_for_each_entry(ei_child, &ei->children, list)
913 eventfs_remove_rec(ei_child, level + 1);
920 * eventfs_remove_dir - remove eventfs dir or file from list
921 * @ei: eventfs_inode to be removed.
923 * This function acquire the eventfs_mutex lock and call eventfs_remove_rec()
925 void eventfs_remove_dir(struct eventfs_inode *ei)
930 mutex_lock(&eventfs_mutex);
931 eventfs_remove_rec(ei, 0);
932 mutex_unlock(&eventfs_mutex);
936 * eventfs_remove_events_dir - remove the top level eventfs directory
937 * @ei: the event_inode returned by eventfs_create_events_dir().
939 * This function removes the events main directory
941 void eventfs_remove_events_dir(struct eventfs_inode *ei)
943 struct eventfs_root_inode *rei;
944 struct dentry *dentry;
946 rei = get_root_inode(ei);
947 dentry = rei->events_dir;
951 rei->events_dir = NULL;
952 eventfs_remove_dir(ei);
955 * Matches the dget() done by tracefs_start_creating()
956 * in eventfs_create_events_dir() when it the dentry was
957 * created. In other words, it's a normal dentry that
958 * sticks around while the other ei->dentry are created
959 * and destroyed dynamically.
961 d_invalidate(dentry);