Lines Matching refs:ei

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
39 struct eventfs_inode ei;
43 static struct eventfs_root_inode *get_root_inode(struct eventfs_inode *ei)
45 WARN_ON_ONCE(!ei->is_events);
46 return container_of(ei, struct eventfs_root_inode, ei);
50 static int eventfs_dir_ino(struct eventfs_inode *ei)
52 if (!ei->ino)
53 ei->ino = get_next_ino();
55 return ei->ino;
59 * The eventfs_inode (ei) itself is protected by SRCU. It is released from
62 * the ei is freed.
86 struct eventfs_inode *ei = container_of(ref, struct eventfs_inode, kref);
89 WARN_ON_ONCE(!ei->is_freed);
91 kfree(ei->entry_attrs);
92 kfree_const(ei->name);
93 if (ei->is_events) {
94 rei = get_root_inode(ei);
95 kfree_rcu(rei, ei.rcu);
97 kfree_rcu(ei, rcu);
101 static inline void put_ei(struct eventfs_inode *ei)
103 if (ei)
104 kref_put(&ei->kref, release_ei);
107 static inline void free_ei(struct eventfs_inode *ei)
109 if (ei) {
110 ei->is_freed = 1;
111 put_ei(ei);
115 static inline struct eventfs_inode *get_ei(struct eventfs_inode *ei)
117 if (ei)
118 kref_get(&ei->kref);
119 return ei;
150 struct eventfs_inode *ei;
155 ei = dentry->d_fsdata;
156 if (ei->is_freed) {
164 if (!ei->entry_attrs) {
165 ei->entry_attrs = kcalloc(ei->nr_entries, sizeof(*ei->entry_attrs),
167 if (!ei->entry_attrs) {
179 * If this is a dir, then update the ei cache, only the file
180 * mode is saved in the ei->m_children, and the ownership is
190 if (ei->is_events) {
193 ei->attr.mode |= EVENTFS_SAVE_UID;
195 ei->attr.mode |= EVENTFS_SAVE_GID;
197 update_attr(&ei->attr, iattr);
203 for (int i = 0; i < ei->nr_entries; i++) {
204 entry = &ei->entries[i];
206 update_attr(&ei->entry_attrs[i], iattr);
216 static void update_top_events_attr(struct eventfs_inode *ei, struct super_block *sb)
221 if (!ei || !(ei->attr.mode & EVENTFS_TOPLEVEL))
226 ei->attr.uid = root->i_uid;
227 ei->attr.gid = root->i_gid;
233 struct eventfs_inode *ei = ti->private;
236 if (!ei || !ei->is_events || !(ei->attr.mode & EVENTFS_TOPLEVEL))
239 update_top_events_attr(ei, inode->i_sb);
241 if (!(ei->attr.mode & EVENTFS_SAVE_UID))
242 inode->i_uid = ei->attr.uid;
244 if (!(ei->attr.mode & EVENTFS_SAVE_GID))
245 inode->i_gid = ei->attr.gid;
288 struct eventfs_inode *ei;
294 ei = dentry->d_fsdata;
297 * If the ei is being freed, the ownership of the children
300 if (ei->is_freed) {
301 ei = NULL;
305 } while (!ei->is_events);
307 update_top_events_attr(ei, dentry->d_sb);
309 return ei;
383 // Files have their parent's ei as their fsdata
394 * @ei: the eventfs_inode that represents the directory to create
400 struct eventfs_inode *pei, struct eventfs_inode *ei)
410 update_inode_attr(dentry, inode, &ei->attr,
417 inode->i_ino = eventfs_dir_ino(ei);
421 /* Only directories have ti->private set to an ei, not files */
422 ti->private = ei;
424 dentry->d_fsdata = get_ei(ei);
430 static inline struct eventfs_inode *init_ei(struct eventfs_inode *ei, const char *name)
432 ei->name = kstrdup_const(name, GFP_KERNEL);
433 if (!ei->name)
435 kref_init(&ei->kref);
436 return ei;
441 struct eventfs_inode *ei = kzalloc(sizeof(*ei), GFP_KERNEL);
444 if (!ei)
447 result = init_ei(ei, name);
449 kfree(ei);
457 struct eventfs_inode *ei;
462 rei->ei.is_events = 1;
463 ei = init_ei(&rei->ei, name);
464 if (!ei)
467 return ei;
484 * @ei: the eventfs_inode that the file will be created under
485 * @idx: the index into the entry_attrs[] of the @ei
491 * eventfs_inode @ei. It uses the entry attributes specified by @idx,
500 struct eventfs_inode *ei, int idx,
506 if (ei->entry_attrs)
507 attr = &ei->entry_attrs[idx];
509 return lookup_file(ei, dentry, mode, attr, data, fops);
518 * Used to create dynamic file/dir with-in @dir, search with-in @ei
528 struct eventfs_inode *ei;
538 ei = ti->private;
539 if (!ei || ei->is_freed)
542 list_for_each_entry(ei_child, &ei->children, list) {
548 result = lookup_dir_entry(dentry, ei, ei_child);
552 for (int i = 0; i < ei->nr_entries; i++) {
556 const struct eventfs_entry *entry = &ei->entries[i];
561 data = ei->data;
565 result = lookup_file_dentry(dentry, ei, i, mode, data, fops);
583 struct eventfs_inode *ei;
603 ei = READ_ONCE(ti->private);
604 if (ei && ei->is_freed)
605 ei = NULL;
608 if (!ei)
618 for (i = c; i < ei->nr_entries; i++, ctx->pos++) {
619 void *cdata = ei->data;
621 entry = &ei->entries[i];
625 /* If ei->is_freed then just bail here, nothing more to do */
626 if (ei->is_freed) {
642 c -= min((unsigned int)c, (unsigned int)ei->nr_entries);
644 list_for_each_entry_srcu(ei_child, &ei->children, list,
715 struct eventfs_inode *ei;
720 ei = alloc_ei(name);
721 if (!ei)
724 ei->entries = entries;
725 ei->nr_entries = size;
726 ei->data = data;
727 INIT_LIST_HEAD(&ei->children);
728 INIT_LIST_HEAD(&ei->list);
732 list_add_tail(&ei->list, &parent->children);
736 if (list_empty(&ei->list)) {
737 free_ei(ei);
738 ei = NULL;
740 return ei;
761 struct eventfs_inode *ei;
773 ei = alloc_root_ei(name);
774 if (!ei)
782 rei = get_root_inode(ei);
785 ei->entries = entries;
786 ei->nr_entries = size;
787 ei->data = data;
799 ei->attr.mode = EVENTFS_TOPLEVEL;
802 ei->attr.uid = uid;
803 ei->attr.gid = gid;
805 INIT_LIST_HEAD(&ei->children);
806 INIT_LIST_HEAD(&ei->list);
810 ti->private = ei;
818 dentry->d_fsdata = get_ei(ei);
835 return ei;
838 free_ei(ei);
845 * @ei: eventfs_inode to be removed.
851 static void eventfs_remove_rec(struct eventfs_inode *ei, int level)
866 list_for_each_entry(ei_child, &ei->children, list)
869 list_del(&ei->list);
870 free_ei(ei);
875 * @ei: eventfs_inode to be removed.
879 void eventfs_remove_dir(struct eventfs_inode *ei)
881 if (!ei)
885 eventfs_remove_rec(ei, 0);
891 * @ei: the event_inode returned by eventfs_create_events_dir().
895 void eventfs_remove_events_dir(struct eventfs_inode *ei)
900 rei = get_root_inode(ei);
906 eventfs_remove_dir(ei);
912 * sticks around while the other ei->dentry are created