Lines Matching +full:parent +full:- +full:child
1 // SPDX-License-Identifier: GPL-2.0-or-later
32 * fsnotify_unmount_inodes - an sb is unmounting. handle any watched inodes.
36 * concurrent modifiers. We temporarily drop sb->s_inode_list_lock and CAN block.
42 spin_lock(&sb->s_inode_list_lock); in fsnotify_unmount_inodes()
43 list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { in fsnotify_unmount_inodes()
49 spin_lock(&inode->i_lock); in fsnotify_unmount_inodes()
50 if (inode->i_state & (I_FREEING|I_WILL_FREE|I_NEW)) { in fsnotify_unmount_inodes()
51 spin_unlock(&inode->i_lock); in fsnotify_unmount_inodes()
64 if (!atomic_read(&inode->i_count)) { in fsnotify_unmount_inodes()
65 spin_unlock(&inode->i_lock); in fsnotify_unmount_inodes()
70 spin_unlock(&inode->i_lock); in fsnotify_unmount_inodes()
71 spin_unlock(&sb->s_inode_list_lock); in fsnotify_unmount_inodes()
83 spin_lock(&sb->s_inode_list_lock); in fsnotify_unmount_inodes()
85 spin_unlock(&sb->s_inode_list_lock); in fsnotify_unmount_inodes()
95 wait_var_event(&sb->s_fsnotify_connectors, in fsnotify_sb_delete()
96 !atomic_long_read(&sb->s_fsnotify_connectors)); in fsnotify_sb_delete()
102 * on a child we run all of our children and set a dentry flag saying that the
103 * parent cares. Thus when an event happens on a child it can quickly tell
104 * if there is a need to find a parent and send the event to the parent.
111 if (!S_ISDIR(inode->i_mode)) in __fsnotify_update_child_dentry_flags()
117 spin_lock(&inode->i_lock); in __fsnotify_update_child_dentry_flags()
120 hlist_for_each_entry(alias, &inode->i_dentry, d_u.d_alias) { in __fsnotify_update_child_dentry_flags()
121 struct dentry *child; in __fsnotify_update_child_dentry_flags() local
124 * d_flags to indicate parental interest (their parent is the in __fsnotify_update_child_dentry_flags()
126 spin_lock(&alias->d_lock); in __fsnotify_update_child_dentry_flags()
127 list_for_each_entry(child, &alias->d_subdirs, d_child) { in __fsnotify_update_child_dentry_flags()
128 if (!child->d_inode) in __fsnotify_update_child_dentry_flags()
131 spin_lock_nested(&child->d_lock, DENTRY_D_LOCK_NESTED); in __fsnotify_update_child_dentry_flags()
133 child->d_flags |= DCACHE_FSNOTIFY_PARENT_WATCHED; in __fsnotify_update_child_dentry_flags()
135 child->d_flags &= ~DCACHE_FSNOTIFY_PARENT_WATCHED; in __fsnotify_update_child_dentry_flags()
136 spin_unlock(&child->d_lock); in __fsnotify_update_child_dentry_flags()
138 spin_unlock(&alias->d_lock); in __fsnotify_update_child_dentry_flags()
140 spin_unlock(&inode->i_lock); in __fsnotify_update_child_dentry_flags()
143 /* Are inode/sb/mount interested in parent and name info with this event? */
149 /* We only send parent/name to inode/sb/mount for events on non-dir */ in fsnotify_event_needs_parent()
154 * All events that are possible on child can also may be reported with in fsnotify_event_needs_parent()
155 * parent/name info to inode/sb/mount. Otherwise, a watching parent in fsnotify_event_needs_parent()
160 /* Did either inode/sb/mount subscribe for events with parent/name? */ in fsnotify_event_needs_parent()
161 marks_mask |= fsnotify_parent_needed_mask(inode->i_fsnotify_mask); in fsnotify_event_needs_parent()
162 marks_mask |= fsnotify_parent_needed_mask(inode->i_sb->s_fsnotify_mask); in fsnotify_event_needs_parent()
164 marks_mask |= fsnotify_parent_needed_mask(mnt->mnt_fsnotify_mask); in fsnotify_event_needs_parent()
166 /* Did they subscribe for this event with parent/name info? */ in fsnotify_event_needs_parent()
171 * Notify this dentry's parent about a child's events with child name info
172 * if parent is watching or if inode/sb/mount are interested in events with
173 * parent and name info.
175 * Notify only the child without name info if parent is not watching and
176 * inode/sb/mount are not interested in events with parent and name info.
182 struct mount *mnt = path ? real_mount(path->mnt) : NULL; in __fsnotify_parent()
184 struct dentry *parent; in __fsnotify_parent() local
185 bool parent_watched = dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED; in __fsnotify_parent()
194 * Do inode/sb/mount care about parent and name info on non-dir? in __fsnotify_parent()
197 if (!inode->i_fsnotify_marks && !inode->i_sb->s_fsnotify_marks && in __fsnotify_parent()
198 (!mnt || !mnt->mnt_fsnotify_marks) && !parent_watched) in __fsnotify_parent()
201 parent = NULL; in __fsnotify_parent()
206 /* Does parent inode care about events on children? */ in __fsnotify_parent()
207 parent = dget_parent(dentry); in __fsnotify_parent()
208 p_inode = parent->d_inode; in __fsnotify_parent()
214 * Include parent/name in notification either if some notification in __fsnotify_parent()
215 * groups require parent info or the parent is interested in this event. in __fsnotify_parent()
219 /* When notifying parent, child should be passed as data */ in __fsnotify_parent()
222 /* Notify both parent and child with child name info */ in __fsnotify_parent()
234 dput(parent); in __fsnotify_parent()
248 const struct fsnotify_ops *ops = group->ops; in fsnotify_handle_inode_event()
250 if (WARN_ON_ONCE(!ops->handle_inode_event)) in fsnotify_handle_inode_event()
256 if ((inode_mark->flags & FSNOTIFY_MARK_FLAG_EXCL_UNLINK) && in fsnotify_handle_inode_event()
257 path && d_unlinked(path->dentry)) in fsnotify_handle_inode_event()
261 if (!(mask & inode_mark->mask & ALL_FSNOTIFY_EVENTS)) in fsnotify_handle_inode_event()
264 return ops->handle_inode_event(inode_mark, mask, inode, dir, name, cookie); in fsnotify_handle_inode_event()
282 * The only ->handle_inode_event() backend that supports FS_RENAME is in fsnotify_handle_event()
283 * dnotify, where it means file was renamed within same parent. in fsnotify_handle_event()
288 if (dir != moved->d_parent->d_inode) in fsnotify_handle_event()
304 * Some events can be sent on both parent dir and child marks in fsnotify_handle_event()
305 * (e.g. FS_ATTRIB). If both parent dir and child are in fsnotify_handle_event()
306 * watching, report the event once to parent dir with name (if in fsnotify_handle_event()
307 * interested) and once to child without name (if interested). in fsnotify_handle_event()
308 * The child watcher is expecting an event without a file name in fsnotify_handle_event()
332 if (!iter_info->report_mask) in send_to_group()
338 if (!(mark->flags & in send_to_group()
340 mark->ignore_mask = 0; in send_to_group()
346 group = mark->group; in send_to_group()
347 marks_mask |= mark->mask; in send_to_group()
359 if (group->ops->handle_event) { in send_to_group()
360 return group->ops->handle_event(group, mask, data, data_type, dir, in send_to_group()
375 node = srcu_dereference(conn->list.first, &fsnotify_mark_srcu); in fsnotify_first_mark()
385 node = srcu_dereference(mark->obj_list.next, in fsnotify_next_mark()
406 mark = iter_info->marks[type]; in fsnotify_iter_select_report_types()
408 fsnotify_compare_groups(max_prio_group, mark->group) > 0) in fsnotify_iter_select_report_types()
409 max_prio_group = mark->group; in fsnotify_iter_select_report_types()
416 iter_info->current_group = max_prio_group; in fsnotify_iter_select_report_types()
417 iter_info->report_mask = 0; in fsnotify_iter_select_report_types()
419 mark = iter_info->marks[type]; in fsnotify_iter_select_report_types()
420 if (mark && mark->group == iter_info->current_group) { in fsnotify_iter_select_report_types()
424 * which is an event possible on child. in fsnotify_iter_select_report_types()
428 !(mark->mask & FS_EVENT_ON_CHILD) && in fsnotify_iter_select_report_types()
454 mark = iter_info->marks[type]; in fsnotify_iter_next()
455 if (mark && mark->group == iter_info->current_group) in fsnotify_iter_next()
456 iter_info->marks[type] = in fsnotify_iter_next()
457 fsnotify_next_mark(iter_info->marks[type]); in fsnotify_iter_next()
462 * fsnotify - This is the main call to fsnotify.
472 * @dir: optional directory associated with event -
476 * @inode: optional inode associated with event -
477 * If @dir and @inode are both non-NULL, event may be
495 mnt = real_mount(path->mnt); in fsnotify()
498 /* Dirent event - report on TYPE_INODE to dir */ in fsnotify()
503 inode2 = moved->d_parent->d_inode; in fsnotify()
508 * Event on child - report on TYPE_PARENT to dir if it is in fsnotify()
509 * watching children and on TYPE_INODE to child. in fsnotify()
522 if (!sb->s_fsnotify_marks && in fsnotify()
523 (!mnt || !mnt->mnt_fsnotify_marks) && in fsnotify()
524 (!inode || !inode->i_fsnotify_marks) && in fsnotify()
525 (!inode2 || !inode2->i_fsnotify_marks)) in fsnotify()
528 marks_mask = sb->s_fsnotify_mask; in fsnotify()
530 marks_mask |= mnt->mnt_fsnotify_mask; in fsnotify()
532 marks_mask |= inode->i_fsnotify_mask; in fsnotify()
534 marks_mask |= inode2->i_fsnotify_mask; in fsnotify()
550 fsnotify_first_mark(&sb->s_fsnotify_marks); in fsnotify()
553 fsnotify_first_mark(&mnt->mnt_fsnotify_marks); in fsnotify()
557 fsnotify_first_mark(&inode->i_fsnotify_marks); in fsnotify()
561 fsnotify_first_mark(&inode2->i_fsnotify_marks); in fsnotify()