1c82ee6d3SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 290586523SEric Paris /* 390586523SEric Paris * Copyright (C) 2008 Red Hat, Inc., Eric Paris <eparis@redhat.com> 490586523SEric Paris */ 590586523SEric Paris 690586523SEric Paris #include <linux/dcache.h> 790586523SEric Paris #include <linux/fs.h> 85a0e3ad6STejun Heo #include <linux/gfp.h> 990586523SEric Paris #include <linux/init.h> 1090586523SEric Paris #include <linux/module.h> 117131485aSEric Paris #include <linux/mount.h> 1290586523SEric Paris #include <linux/srcu.h> 1390586523SEric Paris 1490586523SEric Paris #include <linux/fsnotify_backend.h> 1590586523SEric Paris #include "fsnotify.h" 1690586523SEric Paris 1790586523SEric Paris /* 183be25f49SEric Paris * Clear all of the marks on an inode when it is being evicted from core 193be25f49SEric Paris */ 203be25f49SEric Paris void __fsnotify_inode_delete(struct inode *inode) 213be25f49SEric Paris { 223be25f49SEric Paris fsnotify_clear_marks_by_inode(inode); 233be25f49SEric Paris } 243be25f49SEric Paris EXPORT_SYMBOL_GPL(__fsnotify_inode_delete); 253be25f49SEric Paris 26ca9c726eSAndreas Gruenbacher void __fsnotify_vfsmount_delete(struct vfsmount *mnt) 27ca9c726eSAndreas Gruenbacher { 28ca9c726eSAndreas Gruenbacher fsnotify_clear_marks_by_mount(mnt); 29ca9c726eSAndreas Gruenbacher } 30ca9c726eSAndreas Gruenbacher 31ebb3b47eSJan Kara /** 32ebb3b47eSJan Kara * fsnotify_unmount_inodes - an sb is unmounting. handle any watched inodes. 33ebb3b47eSJan Kara * @sb: superblock being unmounted. 34ebb3b47eSJan Kara * 35ebb3b47eSJan Kara * Called during unmount with no locks held, so needs to be safe against 36ebb3b47eSJan Kara * concurrent modifiers. We temporarily drop sb->s_inode_list_lock and CAN block. 37ebb3b47eSJan Kara */ 381e6cb723SAmir Goldstein static void fsnotify_unmount_inodes(struct super_block *sb) 39ebb3b47eSJan Kara { 40ebb3b47eSJan Kara struct inode *inode, *iput_inode = NULL; 41ebb3b47eSJan Kara 42ebb3b47eSJan Kara spin_lock(&sb->s_inode_list_lock); 43ebb3b47eSJan Kara list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { 44ebb3b47eSJan Kara /* 45ebb3b47eSJan Kara * We cannot __iget() an inode in state I_FREEING, 46ebb3b47eSJan Kara * I_WILL_FREE, or I_NEW which is fine because by that point 47ebb3b47eSJan Kara * the inode cannot have any associated watches. 48ebb3b47eSJan Kara */ 49ebb3b47eSJan Kara spin_lock(&inode->i_lock); 50ebb3b47eSJan Kara if (inode->i_state & (I_FREEING|I_WILL_FREE|I_NEW)) { 51ebb3b47eSJan Kara spin_unlock(&inode->i_lock); 52ebb3b47eSJan Kara continue; 53ebb3b47eSJan Kara } 54ebb3b47eSJan Kara 55ebb3b47eSJan Kara /* 56ebb3b47eSJan Kara * If i_count is zero, the inode cannot have any watches and 571751e8a6SLinus Torvalds * doing an __iget/iput with SB_ACTIVE clear would actually 58ebb3b47eSJan Kara * evict all inodes with zero i_count from icache which is 59ebb3b47eSJan Kara * unnecessarily violent and may in fact be illegal to do. 601edc8eb2SEric Sandeen * However, we should have been called /after/ evict_inodes 611edc8eb2SEric Sandeen * removed all zero refcount inodes, in any case. Test to 621edc8eb2SEric Sandeen * be sure. 63ebb3b47eSJan Kara */ 64ebb3b47eSJan Kara if (!atomic_read(&inode->i_count)) { 65ebb3b47eSJan Kara spin_unlock(&inode->i_lock); 66ebb3b47eSJan Kara continue; 67ebb3b47eSJan Kara } 68ebb3b47eSJan Kara 69ebb3b47eSJan Kara __iget(inode); 70ebb3b47eSJan Kara spin_unlock(&inode->i_lock); 71ebb3b47eSJan Kara spin_unlock(&sb->s_inode_list_lock); 72ebb3b47eSJan Kara 73ebb3b47eSJan Kara if (iput_inode) 74ebb3b47eSJan Kara iput(iput_inode); 75ebb3b47eSJan Kara 76ebb3b47eSJan Kara /* for each watch, send FS_UNMOUNT and then remove it */ 77ebb3b47eSJan Kara fsnotify(inode, FS_UNMOUNT, inode, FSNOTIFY_EVENT_INODE, NULL, 0); 78ebb3b47eSJan Kara 79ebb3b47eSJan Kara fsnotify_inode_delete(inode); 80ebb3b47eSJan Kara 81ebb3b47eSJan Kara iput_inode = inode; 82ebb3b47eSJan Kara 8304646aebSEric Sandeen cond_resched(); 84ebb3b47eSJan Kara spin_lock(&sb->s_inode_list_lock); 85ebb3b47eSJan Kara } 86ebb3b47eSJan Kara spin_unlock(&sb->s_inode_list_lock); 87ebb3b47eSJan Kara 88ebb3b47eSJan Kara if (iput_inode) 89ebb3b47eSJan Kara iput(iput_inode); 90721fb6fbSJan Kara /* Wait for outstanding inode references from connectors */ 91721fb6fbSJan Kara wait_var_event(&sb->s_fsnotify_inode_refs, 92721fb6fbSJan Kara !atomic_long_read(&sb->s_fsnotify_inode_refs)); 93ebb3b47eSJan Kara } 94ebb3b47eSJan Kara 951e6cb723SAmir Goldstein void fsnotify_sb_delete(struct super_block *sb) 961e6cb723SAmir Goldstein { 971e6cb723SAmir Goldstein fsnotify_unmount_inodes(sb); 981e6cb723SAmir Goldstein fsnotify_clear_marks_by_sb(sb); 991e6cb723SAmir Goldstein } 1001e6cb723SAmir Goldstein 1013be25f49SEric Paris /* 102c28f7e56SEric Paris * Given an inode, first check if we care what happens to our children. Inotify 103c28f7e56SEric Paris * and dnotify both tell their parents about events. If we care about any event 104c28f7e56SEric Paris * on a child we run all of our children and set a dentry flag saying that the 105c28f7e56SEric Paris * parent cares. Thus when an event happens on a child it can quickly tell if 106c28f7e56SEric Paris * if there is a need to find a parent and send the event to the parent. 107c28f7e56SEric Paris */ 108c28f7e56SEric Paris void __fsnotify_update_child_dentry_flags(struct inode *inode) 109c28f7e56SEric Paris { 110c28f7e56SEric Paris struct dentry *alias; 111c28f7e56SEric Paris int watched; 112c28f7e56SEric Paris 113c28f7e56SEric Paris if (!S_ISDIR(inode->i_mode)) 114c28f7e56SEric Paris return; 115c28f7e56SEric Paris 116c28f7e56SEric Paris /* determine if the children should tell inode about their events */ 117c28f7e56SEric Paris watched = fsnotify_inode_watches_children(inode); 118c28f7e56SEric Paris 119873feea0SNick Piggin spin_lock(&inode->i_lock); 120c28f7e56SEric Paris /* run all of the dentries associated with this inode. Since this is a 121c28f7e56SEric Paris * directory, there damn well better only be one item on this list */ 122946e51f2SAl Viro hlist_for_each_entry(alias, &inode->i_dentry, d_u.d_alias) { 123c28f7e56SEric Paris struct dentry *child; 124c28f7e56SEric Paris 125c28f7e56SEric Paris /* run all of the children of the original inode and fix their 126c28f7e56SEric Paris * d_flags to indicate parental interest (their parent is the 127c28f7e56SEric Paris * original inode) */ 1282fd6b7f5SNick Piggin spin_lock(&alias->d_lock); 129946e51f2SAl Viro list_for_each_entry(child, &alias->d_subdirs, d_child) { 130c28f7e56SEric Paris if (!child->d_inode) 131c28f7e56SEric Paris continue; 132c28f7e56SEric Paris 1332fd6b7f5SNick Piggin spin_lock_nested(&child->d_lock, DENTRY_D_LOCK_NESTED); 134c28f7e56SEric Paris if (watched) 135c28f7e56SEric Paris child->d_flags |= DCACHE_FSNOTIFY_PARENT_WATCHED; 136c28f7e56SEric Paris else 137c28f7e56SEric Paris child->d_flags &= ~DCACHE_FSNOTIFY_PARENT_WATCHED; 138c28f7e56SEric Paris spin_unlock(&child->d_lock); 139c28f7e56SEric Paris } 1402fd6b7f5SNick Piggin spin_unlock(&alias->d_lock); 141c28f7e56SEric Paris } 142873feea0SNick Piggin spin_unlock(&inode->i_lock); 143c28f7e56SEric Paris } 144c28f7e56SEric Paris 145c28f7e56SEric Paris /* Notify this dentry's parent about a child's events. */ 146*71d73410SMel Gorman int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data, 147017de65fSAmir Goldstein int data_type) 148c28f7e56SEric Paris { 149c28f7e56SEric Paris struct dentry *parent; 150c28f7e56SEric Paris struct inode *p_inode; 15152420392SEric Paris int ret = 0; 152c28f7e56SEric Paris 153c28f7e56SEric Paris if (!(dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED)) 15452420392SEric Paris return 0; 155c28f7e56SEric Paris 1564d4eb366SChristoph Hellwig parent = dget_parent(dentry); 157c28f7e56SEric Paris p_inode = parent->d_inode; 158c28f7e56SEric Paris 159b469e7e4SAmir Goldstein if (unlikely(!fsnotify_inode_watches_children(p_inode))) { 1604d4eb366SChristoph Hellwig __fsnotify_update_child_dentry_flags(p_inode); 161b469e7e4SAmir Goldstein } else if (p_inode->i_fsnotify_mask & mask & ALL_FSNOTIFY_EVENTS) { 16249d31c2fSAl Viro struct name_snapshot name; 16349d31c2fSAl Viro 164c28f7e56SEric Paris /* we are notifying a parent so come up with the new mask which 165c28f7e56SEric Paris * specifies these are events which came from a child. */ 166c28f7e56SEric Paris mask |= FS_EVENT_ON_CHILD; 167c28f7e56SEric Paris 16849d31c2fSAl Viro take_dentry_name_snapshot(&name, dentry); 169017de65fSAmir Goldstein ret = fsnotify(p_inode, mask, data, data_type, &name.name, 0); 17049d31c2fSAl Viro release_dentry_name_snapshot(&name); 171c28f7e56SEric Paris } 172c28f7e56SEric Paris 173c28f7e56SEric Paris dput(parent); 17452420392SEric Paris 17552420392SEric Paris return ret; 176c28f7e56SEric Paris } 177*71d73410SMel Gorman EXPORT_SYMBOL_GPL(__fsnotify_parent); 178c28f7e56SEric Paris 179fd657170SDan Carpenter static int send_to_group(struct inode *to_tell, 180e637835eSAl Viro __u32 mask, const void *data, 181613a807fSEric Paris int data_is, u32 cookie, 182e43e9c33SAl Viro const struct qstr *file_name, 1839385a84dSJan Kara struct fsnotify_iter_info *iter_info) 1847131485aSEric Paris { 185faa9560aSEric Paris struct fsnotify_group *group = NULL; 186007d1e83SAmir Goldstein __u32 test_mask = (mask & ALL_FSNOTIFY_EVENTS); 18792183a42SAmir Goldstein __u32 marks_mask = 0; 18892183a42SAmir Goldstein __u32 marks_ignored_mask = 0; 1893dca1a74SAmir Goldstein struct fsnotify_mark *mark; 1903dca1a74SAmir Goldstein int type; 191613a807fSEric Paris 1925b0457adSAmir Goldstein if (WARN_ON(!iter_info->report_mask)) 193faa9560aSEric Paris return 0; 1945ba08e2eSEric Paris 195ce8f76fbSEric Paris /* clear ignored on inode modification */ 196ce8f76fbSEric Paris if (mask & FS_MODIFY) { 1973dca1a74SAmir Goldstein fsnotify_foreach_obj_type(type) { 1983dca1a74SAmir Goldstein if (!fsnotify_iter_should_report_type(iter_info, type)) 1993dca1a74SAmir Goldstein continue; 2003dca1a74SAmir Goldstein mark = iter_info->marks[type]; 2013dca1a74SAmir Goldstein if (mark && 2023dca1a74SAmir Goldstein !(mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY)) 2033dca1a74SAmir Goldstein mark->ignored_mask = 0; 2043dca1a74SAmir Goldstein } 205ce8f76fbSEric Paris } 206613a807fSEric Paris 2073dca1a74SAmir Goldstein fsnotify_foreach_obj_type(type) { 2083dca1a74SAmir Goldstein if (!fsnotify_iter_should_report_type(iter_info, type)) 2093dca1a74SAmir Goldstein continue; 2103dca1a74SAmir Goldstein mark = iter_info->marks[type]; 2113dca1a74SAmir Goldstein /* does the object mark tell us to do something? */ 2123dca1a74SAmir Goldstein if (mark) { 2133dca1a74SAmir Goldstein group = mark->group; 2143dca1a74SAmir Goldstein marks_mask |= mark->mask; 2153dca1a74SAmir Goldstein marks_ignored_mask |= mark->ignored_mask; 2163dca1a74SAmir Goldstein } 217ce8f76fbSEric Paris } 218ce8f76fbSEric Paris 2193dca1a74SAmir Goldstein pr_debug("%s: group=%p to_tell=%p mask=%x marks_mask=%x marks_ignored_mask=%x" 2207053aee2SJan Kara " data=%p data_is=%d cookie=%d\n", 2213dca1a74SAmir Goldstein __func__, group, to_tell, mask, marks_mask, marks_ignored_mask, 2223dca1a74SAmir Goldstein data, data_is, cookie); 223faa9560aSEric Paris 22492183a42SAmir Goldstein if (!(test_mask & marks_mask & ~marks_ignored_mask)) 225613a807fSEric Paris return 0; 226613a807fSEric Paris 2275b0457adSAmir Goldstein return group->ops->handle_event(group, to_tell, mask, data, data_is, 2289385a84dSJan Kara file_name, cookie, iter_info); 2297131485aSEric Paris } 2307131485aSEric Paris 2313427ce71SMiklos Szeredi static struct fsnotify_mark *fsnotify_first_mark(struct fsnotify_mark_connector **connp) 2323427ce71SMiklos Szeredi { 2333427ce71SMiklos Szeredi struct fsnotify_mark_connector *conn; 2343427ce71SMiklos Szeredi struct hlist_node *node = NULL; 2353427ce71SMiklos Szeredi 2363427ce71SMiklos Szeredi conn = srcu_dereference(*connp, &fsnotify_mark_srcu); 2373427ce71SMiklos Szeredi if (conn) 2383427ce71SMiklos Szeredi node = srcu_dereference(conn->list.first, &fsnotify_mark_srcu); 2393427ce71SMiklos Szeredi 2403427ce71SMiklos Szeredi return hlist_entry_safe(node, struct fsnotify_mark, obj_list); 2413427ce71SMiklos Szeredi } 2423427ce71SMiklos Szeredi 2433427ce71SMiklos Szeredi static struct fsnotify_mark *fsnotify_next_mark(struct fsnotify_mark *mark) 2443427ce71SMiklos Szeredi { 2453427ce71SMiklos Szeredi struct hlist_node *node = NULL; 2463427ce71SMiklos Szeredi 2473427ce71SMiklos Szeredi if (mark) 2483427ce71SMiklos Szeredi node = srcu_dereference(mark->obj_list.next, 2493427ce71SMiklos Szeredi &fsnotify_mark_srcu); 2503427ce71SMiklos Szeredi 2513427ce71SMiklos Szeredi return hlist_entry_safe(node, struct fsnotify_mark, obj_list); 2523427ce71SMiklos Szeredi } 2533427ce71SMiklos Szeredi 254c28f7e56SEric Paris /* 255d9a6f30bSAmir Goldstein * iter_info is a multi head priority queue of marks. 256d9a6f30bSAmir Goldstein * Pick a subset of marks from queue heads, all with the 257d9a6f30bSAmir Goldstein * same group and set the report_mask for selected subset. 258d9a6f30bSAmir Goldstein * Returns the report_mask of the selected subset. 259d9a6f30bSAmir Goldstein */ 260d9a6f30bSAmir Goldstein static unsigned int fsnotify_iter_select_report_types( 261d9a6f30bSAmir Goldstein struct fsnotify_iter_info *iter_info) 262d9a6f30bSAmir Goldstein { 26347d9c7ccSAmir Goldstein struct fsnotify_group *max_prio_group = NULL; 26447d9c7ccSAmir Goldstein struct fsnotify_mark *mark; 26547d9c7ccSAmir Goldstein int type; 266d9a6f30bSAmir Goldstein 26747d9c7ccSAmir Goldstein /* Choose max prio group among groups of all queue heads */ 26847d9c7ccSAmir Goldstein fsnotify_foreach_obj_type(type) { 26947d9c7ccSAmir Goldstein mark = iter_info->marks[type]; 27047d9c7ccSAmir Goldstein if (mark && 27147d9c7ccSAmir Goldstein fsnotify_compare_groups(max_prio_group, mark->group) > 0) 27247d9c7ccSAmir Goldstein max_prio_group = mark->group; 273d9a6f30bSAmir Goldstein } 274d9a6f30bSAmir Goldstein 27547d9c7ccSAmir Goldstein if (!max_prio_group) 27647d9c7ccSAmir Goldstein return 0; 27747d9c7ccSAmir Goldstein 27847d9c7ccSAmir Goldstein /* Set the report mask for marks from same group as max prio group */ 279d9a6f30bSAmir Goldstein iter_info->report_mask = 0; 28047d9c7ccSAmir Goldstein fsnotify_foreach_obj_type(type) { 28147d9c7ccSAmir Goldstein mark = iter_info->marks[type]; 28247d9c7ccSAmir Goldstein if (mark && 28347d9c7ccSAmir Goldstein fsnotify_compare_groups(max_prio_group, mark->group) == 0) 28447d9c7ccSAmir Goldstein fsnotify_iter_set_report_type(iter_info, type); 28547d9c7ccSAmir Goldstein } 286d9a6f30bSAmir Goldstein 287d9a6f30bSAmir Goldstein return iter_info->report_mask; 288d9a6f30bSAmir Goldstein } 289d9a6f30bSAmir Goldstein 290d9a6f30bSAmir Goldstein /* 291d9a6f30bSAmir Goldstein * Pop from iter_info multi head queue, the marks that were iterated in the 292d9a6f30bSAmir Goldstein * current iteration step. 293d9a6f30bSAmir Goldstein */ 294d9a6f30bSAmir Goldstein static void fsnotify_iter_next(struct fsnotify_iter_info *iter_info) 295d9a6f30bSAmir Goldstein { 29647d9c7ccSAmir Goldstein int type; 297d9a6f30bSAmir Goldstein 29847d9c7ccSAmir Goldstein fsnotify_foreach_obj_type(type) { 29947d9c7ccSAmir Goldstein if (fsnotify_iter_should_report_type(iter_info, type)) 30047d9c7ccSAmir Goldstein iter_info->marks[type] = 30147d9c7ccSAmir Goldstein fsnotify_next_mark(iter_info->marks[type]); 30247d9c7ccSAmir Goldstein } 303d9a6f30bSAmir Goldstein } 304d9a6f30bSAmir Goldstein 305d9a6f30bSAmir Goldstein /* 30690586523SEric Paris * This is the main call to fsnotify. The VFS calls into hook specific functions 30790586523SEric Paris * in linux/fsnotify.h. Those functions then in turn call here. Here will call 30890586523SEric Paris * out to all of the registered fsnotify_group. Those groups can then use the 30990586523SEric Paris * notification event in whatever means they feel necessary. 31090586523SEric Paris */ 311e637835eSAl Viro int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, 31225b229dfSAl Viro const struct qstr *file_name, u32 cookie) 31390586523SEric Paris { 314aa93bdc5SAmir Goldstein const struct path *path = fsnotify_data_path(data, data_is); 3153427ce71SMiklos Szeredi struct fsnotify_iter_info iter_info = {}; 31645a9fb37SAmir Goldstein struct super_block *sb = to_tell->i_sb; 31760f7ed8cSAmir Goldstein struct mount *mnt = NULL; 3189385a84dSJan Kara int ret = 0; 319*71d73410SMel Gorman __u32 test_mask, marks_mask; 32090586523SEric Paris 321*71d73410SMel Gorman if (path) 322aa93bdc5SAmir Goldstein mnt = real_mount(path->mnt); 323613a807fSEric Paris 324613a807fSEric Paris /* 3257c49b861SDave Hansen * Optimization: srcu_read_lock() has a memory barrier which can 3267c49b861SDave Hansen * be expensive. It protects walking the *_fsnotify_marks lists. 3277c49b861SDave Hansen * However, if we do not walk the lists, we do not have to do 3287c49b861SDave Hansen * SRCU because we have no references to any objects and do not 3297c49b861SDave Hansen * need SRCU to keep them "alive". 3307c49b861SDave Hansen */ 33145a9fb37SAmir Goldstein if (!to_tell->i_fsnotify_marks && !sb->s_fsnotify_marks && 33245a9fb37SAmir Goldstein (!mnt || !mnt->mnt_fsnotify_marks)) 3337c49b861SDave Hansen return 0; 334*71d73410SMel Gorman 335*71d73410SMel Gorman /* An event "on child" is not intended for a mount/sb mark */ 336*71d73410SMel Gorman marks_mask = to_tell->i_fsnotify_mask; 337*71d73410SMel Gorman if (!(mask & FS_EVENT_ON_CHILD)) { 338*71d73410SMel Gorman marks_mask |= sb->s_fsnotify_mask; 339*71d73410SMel Gorman if (mnt) 340*71d73410SMel Gorman marks_mask |= mnt->mnt_fsnotify_mask; 341*71d73410SMel Gorman } 342*71d73410SMel Gorman 3437c49b861SDave Hansen /* 344613a807fSEric Paris * if this is a modify event we may need to clear the ignored masks 34560f7ed8cSAmir Goldstein * otherwise return if neither the inode nor the vfsmount/sb care about 346613a807fSEric Paris * this type of event. 347613a807fSEric Paris */ 348*71d73410SMel Gorman test_mask = (mask & ALL_FSNOTIFY_EVENTS); 349*71d73410SMel Gorman if (!(mask & FS_MODIFY) && !(test_mask & marks_mask)) 350613a807fSEric Paris return 0; 3513a9fb89fSEric Paris 3529385a84dSJan Kara iter_info.srcu_idx = srcu_read_lock(&fsnotify_mark_srcu); 3537131485aSEric Paris 35447d9c7ccSAmir Goldstein iter_info.marks[FSNOTIFY_OBJ_TYPE_INODE] = 3553427ce71SMiklos Szeredi fsnotify_first_mark(&to_tell->i_fsnotify_marks); 35645a9fb37SAmir Goldstein iter_info.marks[FSNOTIFY_OBJ_TYPE_SB] = 35745a9fb37SAmir Goldstein fsnotify_first_mark(&sb->s_fsnotify_marks); 3589bdda4e9SAmir Goldstein if (mnt) { 35947d9c7ccSAmir Goldstein iter_info.marks[FSNOTIFY_OBJ_TYPE_VFSMOUNT] = 3603427ce71SMiklos Szeredi fsnotify_first_mark(&mnt->mnt_fsnotify_marks); 3617131485aSEric Paris } 36275c1be48SEric Paris 3638edc6e16SJan Kara /* 36460f7ed8cSAmir Goldstein * We need to merge inode/vfsmount/sb mark lists so that e.g. inode mark 36560f7ed8cSAmir Goldstein * ignore masks are properly reflected for mount/sb mark notifications. 3668edc6e16SJan Kara * That's why this traversal is so complicated... 3678edc6e16SJan Kara */ 368d9a6f30bSAmir Goldstein while (fsnotify_iter_select_report_types(&iter_info)) { 3695b0457adSAmir Goldstein ret = send_to_group(to_tell, mask, data, data_is, cookie, 370e43e9c33SAl Viro file_name, &iter_info); 37184a5b68eSEric Paris 372ff8bcbd0SEric Paris if (ret && (mask & ALL_FSNOTIFY_PERM_EVENTS)) 373ff8bcbd0SEric Paris goto out; 374ff8bcbd0SEric Paris 375d9a6f30bSAmir Goldstein fsnotify_iter_next(&iter_info); 3767131485aSEric Paris } 377ff8bcbd0SEric Paris ret = 0; 378ff8bcbd0SEric Paris out: 3799385a84dSJan Kara srcu_read_unlock(&fsnotify_mark_srcu, iter_info.srcu_idx); 380c4ec54b4SEric Paris 38198b5c10dSJean-Christophe Dubois return ret; 38290586523SEric Paris } 38390586523SEric Paris EXPORT_SYMBOL_GPL(fsnotify); 38490586523SEric Paris 38590586523SEric Paris static __init int fsnotify_init(void) 38690586523SEric Paris { 38775c1be48SEric Paris int ret; 38875c1be48SEric Paris 3899e2ba2c3SAmir Goldstein BUILD_BUG_ON(HWEIGHT32(ALL_FSNOTIFY_BITS) != 26); 39020dee624SEric Paris 39175c1be48SEric Paris ret = init_srcu_struct(&fsnotify_mark_srcu); 39275c1be48SEric Paris if (ret) 39375c1be48SEric Paris panic("initializing fsnotify_mark_srcu"); 39475c1be48SEric Paris 3959dd813c1SJan Kara fsnotify_mark_connector_cachep = KMEM_CACHE(fsnotify_mark_connector, 3969dd813c1SJan Kara SLAB_PANIC); 3979dd813c1SJan Kara 39875c1be48SEric Paris return 0; 39990586523SEric Paris } 40075c1be48SEric Paris core_initcall(fsnotify_init); 401