190586523SEric Paris /* 290586523SEric Paris * Copyright (C) 2008 Red Hat, Inc., Eric Paris <eparis@redhat.com> 390586523SEric Paris * 490586523SEric Paris * This program is free software; you can redistribute it and/or modify 590586523SEric Paris * it under the terms of the GNU General Public License as published by 690586523SEric Paris * the Free Software Foundation; either version 2, or (at your option) 790586523SEric Paris * any later version. 890586523SEric Paris * 990586523SEric Paris * This program is distributed in the hope that it will be useful, 1090586523SEric Paris * but WITHOUT ANY WARRANTY; without even the implied warranty of 1190586523SEric Paris * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1290586523SEric Paris * GNU General Public License for more details. 1390586523SEric Paris * 1490586523SEric Paris * You should have received a copy of the GNU General Public License 1590586523SEric Paris * along with this program; see the file COPYING. If not, write to 1690586523SEric Paris * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 1790586523SEric Paris */ 1890586523SEric Paris 1990586523SEric Paris #include <linux/dcache.h> 2090586523SEric Paris #include <linux/fs.h> 215a0e3ad6STejun Heo #include <linux/gfp.h> 2290586523SEric Paris #include <linux/init.h> 2390586523SEric Paris #include <linux/module.h> 247131485aSEric Paris #include <linux/mount.h> 2590586523SEric Paris #include <linux/srcu.h> 2690586523SEric Paris 2790586523SEric Paris #include <linux/fsnotify_backend.h> 2890586523SEric Paris #include "fsnotify.h" 2990586523SEric Paris 3090586523SEric Paris /* 313be25f49SEric Paris * Clear all of the marks on an inode when it is being evicted from core 323be25f49SEric Paris */ 333be25f49SEric Paris void __fsnotify_inode_delete(struct inode *inode) 343be25f49SEric Paris { 353be25f49SEric Paris fsnotify_clear_marks_by_inode(inode); 363be25f49SEric Paris } 373be25f49SEric Paris EXPORT_SYMBOL_GPL(__fsnotify_inode_delete); 383be25f49SEric Paris 39ca9c726eSAndreas Gruenbacher void __fsnotify_vfsmount_delete(struct vfsmount *mnt) 40ca9c726eSAndreas Gruenbacher { 41ca9c726eSAndreas Gruenbacher fsnotify_clear_marks_by_mount(mnt); 42ca9c726eSAndreas Gruenbacher } 43ca9c726eSAndreas Gruenbacher 44ebb3b47eSJan Kara /** 45ebb3b47eSJan Kara * fsnotify_unmount_inodes - an sb is unmounting. handle any watched inodes. 46ebb3b47eSJan Kara * @sb: superblock being unmounted. 47ebb3b47eSJan Kara * 48ebb3b47eSJan Kara * Called during unmount with no locks held, so needs to be safe against 49ebb3b47eSJan Kara * concurrent modifiers. We temporarily drop sb->s_inode_list_lock and CAN block. 50ebb3b47eSJan Kara */ 511e6cb723SAmir Goldstein static void fsnotify_unmount_inodes(struct super_block *sb) 52ebb3b47eSJan Kara { 53ebb3b47eSJan Kara struct inode *inode, *iput_inode = NULL; 54ebb3b47eSJan Kara 55ebb3b47eSJan Kara spin_lock(&sb->s_inode_list_lock); 56ebb3b47eSJan Kara list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { 57ebb3b47eSJan Kara /* 58ebb3b47eSJan Kara * We cannot __iget() an inode in state I_FREEING, 59ebb3b47eSJan Kara * I_WILL_FREE, or I_NEW which is fine because by that point 60ebb3b47eSJan Kara * the inode cannot have any associated watches. 61ebb3b47eSJan Kara */ 62ebb3b47eSJan Kara spin_lock(&inode->i_lock); 63ebb3b47eSJan Kara if (inode->i_state & (I_FREEING|I_WILL_FREE|I_NEW)) { 64ebb3b47eSJan Kara spin_unlock(&inode->i_lock); 65ebb3b47eSJan Kara continue; 66ebb3b47eSJan Kara } 67ebb3b47eSJan Kara 68ebb3b47eSJan Kara /* 69ebb3b47eSJan Kara * If i_count is zero, the inode cannot have any watches and 701751e8a6SLinus Torvalds * doing an __iget/iput with SB_ACTIVE clear would actually 71ebb3b47eSJan Kara * evict all inodes with zero i_count from icache which is 72ebb3b47eSJan Kara * unnecessarily violent and may in fact be illegal to do. 73ebb3b47eSJan Kara */ 74ebb3b47eSJan Kara if (!atomic_read(&inode->i_count)) { 75ebb3b47eSJan Kara spin_unlock(&inode->i_lock); 76ebb3b47eSJan Kara continue; 77ebb3b47eSJan Kara } 78ebb3b47eSJan Kara 79ebb3b47eSJan Kara __iget(inode); 80ebb3b47eSJan Kara spin_unlock(&inode->i_lock); 81ebb3b47eSJan Kara spin_unlock(&sb->s_inode_list_lock); 82ebb3b47eSJan Kara 83ebb3b47eSJan Kara if (iput_inode) 84ebb3b47eSJan Kara iput(iput_inode); 85ebb3b47eSJan Kara 86ebb3b47eSJan Kara /* for each watch, send FS_UNMOUNT and then remove it */ 87ebb3b47eSJan Kara fsnotify(inode, FS_UNMOUNT, inode, FSNOTIFY_EVENT_INODE, NULL, 0); 88ebb3b47eSJan Kara 89ebb3b47eSJan Kara fsnotify_inode_delete(inode); 90ebb3b47eSJan Kara 91ebb3b47eSJan Kara iput_inode = inode; 92ebb3b47eSJan Kara 93ebb3b47eSJan Kara spin_lock(&sb->s_inode_list_lock); 94ebb3b47eSJan Kara } 95ebb3b47eSJan Kara spin_unlock(&sb->s_inode_list_lock); 96ebb3b47eSJan Kara 97ebb3b47eSJan Kara if (iput_inode) 98ebb3b47eSJan Kara iput(iput_inode); 99ebb3b47eSJan Kara } 100ebb3b47eSJan Kara 1011e6cb723SAmir Goldstein void fsnotify_sb_delete(struct super_block *sb) 1021e6cb723SAmir Goldstein { 1031e6cb723SAmir Goldstein fsnotify_unmount_inodes(sb); 1041e6cb723SAmir Goldstein fsnotify_clear_marks_by_sb(sb); 1051e6cb723SAmir Goldstein } 1061e6cb723SAmir Goldstein 1073be25f49SEric Paris /* 108c28f7e56SEric Paris * Given an inode, first check if we care what happens to our children. Inotify 109c28f7e56SEric Paris * and dnotify both tell their parents about events. If we care about any event 110c28f7e56SEric Paris * on a child we run all of our children and set a dentry flag saying that the 111c28f7e56SEric Paris * parent cares. Thus when an event happens on a child it can quickly tell if 112c28f7e56SEric Paris * if there is a need to find a parent and send the event to the parent. 113c28f7e56SEric Paris */ 114c28f7e56SEric Paris void __fsnotify_update_child_dentry_flags(struct inode *inode) 115c28f7e56SEric Paris { 116c28f7e56SEric Paris struct dentry *alias; 117c28f7e56SEric Paris int watched; 118c28f7e56SEric Paris 119c28f7e56SEric Paris if (!S_ISDIR(inode->i_mode)) 120c28f7e56SEric Paris return; 121c28f7e56SEric Paris 122c28f7e56SEric Paris /* determine if the children should tell inode about their events */ 123c28f7e56SEric Paris watched = fsnotify_inode_watches_children(inode); 124c28f7e56SEric Paris 125873feea0SNick Piggin spin_lock(&inode->i_lock); 126c28f7e56SEric Paris /* run all of the dentries associated with this inode. Since this is a 127c28f7e56SEric Paris * directory, there damn well better only be one item on this list */ 128946e51f2SAl Viro hlist_for_each_entry(alias, &inode->i_dentry, d_u.d_alias) { 129c28f7e56SEric Paris struct dentry *child; 130c28f7e56SEric Paris 131c28f7e56SEric Paris /* run all of the children of the original inode and fix their 132c28f7e56SEric Paris * d_flags to indicate parental interest (their parent is the 133c28f7e56SEric Paris * original inode) */ 1342fd6b7f5SNick Piggin spin_lock(&alias->d_lock); 135946e51f2SAl Viro list_for_each_entry(child, &alias->d_subdirs, d_child) { 136c28f7e56SEric Paris if (!child->d_inode) 137c28f7e56SEric Paris continue; 138c28f7e56SEric Paris 1392fd6b7f5SNick Piggin spin_lock_nested(&child->d_lock, DENTRY_D_LOCK_NESTED); 140c28f7e56SEric Paris if (watched) 141c28f7e56SEric Paris child->d_flags |= DCACHE_FSNOTIFY_PARENT_WATCHED; 142c28f7e56SEric Paris else 143c28f7e56SEric Paris child->d_flags &= ~DCACHE_FSNOTIFY_PARENT_WATCHED; 144c28f7e56SEric Paris spin_unlock(&child->d_lock); 145c28f7e56SEric Paris } 1462fd6b7f5SNick Piggin spin_unlock(&alias->d_lock); 147c28f7e56SEric Paris } 148873feea0SNick Piggin spin_unlock(&inode->i_lock); 149c28f7e56SEric Paris } 150c28f7e56SEric Paris 151c28f7e56SEric Paris /* Notify this dentry's parent about a child's events. */ 15212c7f9dcSAl Viro int __fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask) 153c28f7e56SEric Paris { 154c28f7e56SEric Paris struct dentry *parent; 155c28f7e56SEric Paris struct inode *p_inode; 15652420392SEric Paris int ret = 0; 157c28f7e56SEric Paris 15872acc854SAndreas Gruenbacher if (!dentry) 1592069601bSLinus Torvalds dentry = path->dentry; 16028c60e37SEric Paris 161c28f7e56SEric Paris if (!(dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED)) 16252420392SEric Paris return 0; 163c28f7e56SEric Paris 1644d4eb366SChristoph Hellwig parent = dget_parent(dentry); 165c28f7e56SEric Paris p_inode = parent->d_inode; 166c28f7e56SEric Paris 1674d4eb366SChristoph Hellwig if (unlikely(!fsnotify_inode_watches_children(p_inode))) 1684d4eb366SChristoph Hellwig __fsnotify_update_child_dentry_flags(p_inode); 1694d4eb366SChristoph Hellwig else if (p_inode->i_fsnotify_mask & mask) { 17049d31c2fSAl Viro struct name_snapshot name; 17149d31c2fSAl Viro 172c28f7e56SEric Paris /* we are notifying a parent so come up with the new mask which 173c28f7e56SEric Paris * specifies these are events which came from a child. */ 174c28f7e56SEric Paris mask |= FS_EVENT_ON_CHILD; 175c28f7e56SEric Paris 17649d31c2fSAl Viro take_dentry_name_snapshot(&name, dentry); 1772069601bSLinus Torvalds if (path) 17852420392SEric Paris ret = fsnotify(p_inode, mask, path, FSNOTIFY_EVENT_PATH, 17949d31c2fSAl Viro name.name, 0); 18028c60e37SEric Paris else 18152420392SEric Paris ret = fsnotify(p_inode, mask, dentry->d_inode, FSNOTIFY_EVENT_INODE, 18249d31c2fSAl Viro name.name, 0); 18349d31c2fSAl Viro release_dentry_name_snapshot(&name); 184c28f7e56SEric Paris } 185c28f7e56SEric Paris 186c28f7e56SEric Paris dput(parent); 18752420392SEric Paris 18852420392SEric Paris return ret; 189c28f7e56SEric Paris } 190c28f7e56SEric Paris EXPORT_SYMBOL_GPL(__fsnotify_parent); 191c28f7e56SEric Paris 192fd657170SDan Carpenter static int send_to_group(struct inode *to_tell, 193e637835eSAl Viro __u32 mask, const void *data, 194613a807fSEric Paris int data_is, u32 cookie, 1959385a84dSJan Kara const unsigned char *file_name, 1969385a84dSJan Kara struct fsnotify_iter_info *iter_info) 1977131485aSEric Paris { 198faa9560aSEric Paris struct fsnotify_group *group = NULL; 199007d1e83SAmir Goldstein __u32 test_mask = (mask & ALL_FSNOTIFY_EVENTS); 20092183a42SAmir Goldstein __u32 marks_mask = 0; 20192183a42SAmir Goldstein __u32 marks_ignored_mask = 0; 2023dca1a74SAmir Goldstein struct fsnotify_mark *mark; 2033dca1a74SAmir Goldstein int type; 204613a807fSEric Paris 2055b0457adSAmir Goldstein if (WARN_ON(!iter_info->report_mask)) 206faa9560aSEric Paris return 0; 2075ba08e2eSEric Paris 208ce8f76fbSEric Paris /* clear ignored on inode modification */ 209ce8f76fbSEric Paris if (mask & FS_MODIFY) { 2103dca1a74SAmir Goldstein fsnotify_foreach_obj_type(type) { 2113dca1a74SAmir Goldstein if (!fsnotify_iter_should_report_type(iter_info, type)) 2123dca1a74SAmir Goldstein continue; 2133dca1a74SAmir Goldstein mark = iter_info->marks[type]; 2143dca1a74SAmir Goldstein if (mark && 2153dca1a74SAmir Goldstein !(mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY)) 2163dca1a74SAmir Goldstein mark->ignored_mask = 0; 2173dca1a74SAmir Goldstein } 218ce8f76fbSEric Paris } 219613a807fSEric Paris 2203dca1a74SAmir Goldstein fsnotify_foreach_obj_type(type) { 2213dca1a74SAmir Goldstein if (!fsnotify_iter_should_report_type(iter_info, type)) 2223dca1a74SAmir Goldstein continue; 2233dca1a74SAmir Goldstein mark = iter_info->marks[type]; 2243dca1a74SAmir Goldstein /* does the object mark tell us to do something? */ 2253dca1a74SAmir Goldstein if (mark) { 2263dca1a74SAmir Goldstein group = mark->group; 2273dca1a74SAmir Goldstein marks_mask |= mark->mask; 2283dca1a74SAmir Goldstein marks_ignored_mask |= mark->ignored_mask; 2293dca1a74SAmir Goldstein } 230ce8f76fbSEric Paris } 231ce8f76fbSEric Paris 2323dca1a74SAmir Goldstein pr_debug("%s: group=%p to_tell=%p mask=%x marks_mask=%x marks_ignored_mask=%x" 2337053aee2SJan Kara " data=%p data_is=%d cookie=%d\n", 2343dca1a74SAmir Goldstein __func__, group, to_tell, mask, marks_mask, marks_ignored_mask, 2353dca1a74SAmir Goldstein data, data_is, cookie); 236faa9560aSEric Paris 23792183a42SAmir Goldstein if (!(test_mask & marks_mask & ~marks_ignored_mask)) 238613a807fSEric Paris return 0; 239613a807fSEric Paris 2405b0457adSAmir Goldstein return group->ops->handle_event(group, to_tell, mask, data, data_is, 2419385a84dSJan Kara file_name, cookie, iter_info); 2427131485aSEric Paris } 2437131485aSEric Paris 2443427ce71SMiklos Szeredi static struct fsnotify_mark *fsnotify_first_mark(struct fsnotify_mark_connector **connp) 2453427ce71SMiklos Szeredi { 2463427ce71SMiklos Szeredi struct fsnotify_mark_connector *conn; 2473427ce71SMiklos Szeredi struct hlist_node *node = NULL; 2483427ce71SMiklos Szeredi 2493427ce71SMiklos Szeredi conn = srcu_dereference(*connp, &fsnotify_mark_srcu); 2503427ce71SMiklos Szeredi if (conn) 2513427ce71SMiklos Szeredi node = srcu_dereference(conn->list.first, &fsnotify_mark_srcu); 2523427ce71SMiklos Szeredi 2533427ce71SMiklos Szeredi return hlist_entry_safe(node, struct fsnotify_mark, obj_list); 2543427ce71SMiklos Szeredi } 2553427ce71SMiklos Szeredi 2563427ce71SMiklos Szeredi static struct fsnotify_mark *fsnotify_next_mark(struct fsnotify_mark *mark) 2573427ce71SMiklos Szeredi { 2583427ce71SMiklos Szeredi struct hlist_node *node = NULL; 2593427ce71SMiklos Szeredi 2603427ce71SMiklos Szeredi if (mark) 2613427ce71SMiklos Szeredi node = srcu_dereference(mark->obj_list.next, 2623427ce71SMiklos Szeredi &fsnotify_mark_srcu); 2633427ce71SMiklos Szeredi 2643427ce71SMiklos Szeredi return hlist_entry_safe(node, struct fsnotify_mark, obj_list); 2653427ce71SMiklos Szeredi } 2663427ce71SMiklos Szeredi 267c28f7e56SEric Paris /* 268d9a6f30bSAmir Goldstein * iter_info is a multi head priority queue of marks. 269d9a6f30bSAmir Goldstein * Pick a subset of marks from queue heads, all with the 270d9a6f30bSAmir Goldstein * same group and set the report_mask for selected subset. 271d9a6f30bSAmir Goldstein * Returns the report_mask of the selected subset. 272d9a6f30bSAmir Goldstein */ 273d9a6f30bSAmir Goldstein static unsigned int fsnotify_iter_select_report_types( 274d9a6f30bSAmir Goldstein struct fsnotify_iter_info *iter_info) 275d9a6f30bSAmir Goldstein { 27647d9c7ccSAmir Goldstein struct fsnotify_group *max_prio_group = NULL; 27747d9c7ccSAmir Goldstein struct fsnotify_mark *mark; 27847d9c7ccSAmir Goldstein int type; 279d9a6f30bSAmir Goldstein 28047d9c7ccSAmir Goldstein /* Choose max prio group among groups of all queue heads */ 28147d9c7ccSAmir Goldstein fsnotify_foreach_obj_type(type) { 28247d9c7ccSAmir Goldstein mark = iter_info->marks[type]; 28347d9c7ccSAmir Goldstein if (mark && 28447d9c7ccSAmir Goldstein fsnotify_compare_groups(max_prio_group, mark->group) > 0) 28547d9c7ccSAmir Goldstein max_prio_group = mark->group; 286d9a6f30bSAmir Goldstein } 287d9a6f30bSAmir Goldstein 28847d9c7ccSAmir Goldstein if (!max_prio_group) 28947d9c7ccSAmir Goldstein return 0; 29047d9c7ccSAmir Goldstein 29147d9c7ccSAmir Goldstein /* Set the report mask for marks from same group as max prio group */ 292d9a6f30bSAmir Goldstein iter_info->report_mask = 0; 29347d9c7ccSAmir Goldstein fsnotify_foreach_obj_type(type) { 29447d9c7ccSAmir Goldstein mark = iter_info->marks[type]; 29547d9c7ccSAmir Goldstein if (mark && 29647d9c7ccSAmir Goldstein fsnotify_compare_groups(max_prio_group, mark->group) == 0) 29747d9c7ccSAmir Goldstein fsnotify_iter_set_report_type(iter_info, type); 29847d9c7ccSAmir Goldstein } 299d9a6f30bSAmir Goldstein 300d9a6f30bSAmir Goldstein return iter_info->report_mask; 301d9a6f30bSAmir Goldstein } 302d9a6f30bSAmir Goldstein 303d9a6f30bSAmir Goldstein /* 304d9a6f30bSAmir Goldstein * Pop from iter_info multi head queue, the marks that were iterated in the 305d9a6f30bSAmir Goldstein * current iteration step. 306d9a6f30bSAmir Goldstein */ 307d9a6f30bSAmir Goldstein static void fsnotify_iter_next(struct fsnotify_iter_info *iter_info) 308d9a6f30bSAmir Goldstein { 30947d9c7ccSAmir Goldstein int type; 310d9a6f30bSAmir Goldstein 31147d9c7ccSAmir Goldstein fsnotify_foreach_obj_type(type) { 31247d9c7ccSAmir Goldstein if (fsnotify_iter_should_report_type(iter_info, type)) 31347d9c7ccSAmir Goldstein iter_info->marks[type] = 31447d9c7ccSAmir Goldstein fsnotify_next_mark(iter_info->marks[type]); 31547d9c7ccSAmir Goldstein } 316d9a6f30bSAmir Goldstein } 317d9a6f30bSAmir Goldstein 318d9a6f30bSAmir Goldstein /* 31990586523SEric Paris * This is the main call to fsnotify. The VFS calls into hook specific functions 32090586523SEric Paris * in linux/fsnotify.h. Those functions then in turn call here. Here will call 32190586523SEric Paris * out to all of the registered fsnotify_group. Those groups can then use the 32290586523SEric Paris * notification event in whatever means they feel necessary. 32390586523SEric Paris */ 324e637835eSAl Viro int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, 32559b0df21SEric Paris const unsigned char *file_name, u32 cookie) 32690586523SEric Paris { 3273427ce71SMiklos Szeredi struct fsnotify_iter_info iter_info = {}; 32860f7ed8cSAmir Goldstein struct super_block *sb = NULL; 32960f7ed8cSAmir Goldstein struct mount *mnt = NULL; 33060f7ed8cSAmir Goldstein __u32 mnt_or_sb_mask = 0; 3319385a84dSJan Kara int ret = 0; 332007d1e83SAmir Goldstein __u32 test_mask = (mask & ALL_FSNOTIFY_EVENTS); 33390586523SEric Paris 33460f7ed8cSAmir Goldstein if (data_is == FSNOTIFY_EVENT_PATH) { 335e637835eSAl Viro mnt = real_mount(((const struct path *)data)->mnt); 33660f7ed8cSAmir Goldstein sb = mnt->mnt.mnt_sb; 33760f7ed8cSAmir Goldstein mnt_or_sb_mask = mnt->mnt_fsnotify_mask | sb->s_fsnotify_mask; 33860f7ed8cSAmir Goldstein } 339613a807fSEric Paris 340613a807fSEric Paris /* 3417c49b861SDave Hansen * Optimization: srcu_read_lock() has a memory barrier which can 3427c49b861SDave Hansen * be expensive. It protects walking the *_fsnotify_marks lists. 3437c49b861SDave Hansen * However, if we do not walk the lists, we do not have to do 3447c49b861SDave Hansen * SRCU because we have no references to any objects and do not 3457c49b861SDave Hansen * need SRCU to keep them "alive". 3467c49b861SDave Hansen */ 3479dd813c1SJan Kara if (!to_tell->i_fsnotify_marks && 34860f7ed8cSAmir Goldstein (!mnt || (!mnt->mnt_fsnotify_marks && !sb->s_fsnotify_marks))) 3497c49b861SDave Hansen return 0; 3507c49b861SDave Hansen /* 351613a807fSEric Paris * if this is a modify event we may need to clear the ignored masks 35260f7ed8cSAmir Goldstein * otherwise return if neither the inode nor the vfsmount/sb care about 353613a807fSEric Paris * this type of event. 354613a807fSEric Paris */ 355613a807fSEric Paris if (!(mask & FS_MODIFY) && 35660f7ed8cSAmir Goldstein !(test_mask & (to_tell->i_fsnotify_mask | mnt_or_sb_mask))) 357613a807fSEric Paris return 0; 3583a9fb89fSEric Paris 3599385a84dSJan Kara iter_info.srcu_idx = srcu_read_lock(&fsnotify_mark_srcu); 3607131485aSEric Paris 36147d9c7ccSAmir Goldstein iter_info.marks[FSNOTIFY_OBJ_TYPE_INODE] = 3623427ce71SMiklos Szeredi fsnotify_first_mark(&to_tell->i_fsnotify_marks); 3639bdda4e9SAmir Goldstein if (mnt) { 36447d9c7ccSAmir Goldstein iter_info.marks[FSNOTIFY_OBJ_TYPE_VFSMOUNT] = 3653427ce71SMiklos Szeredi fsnotify_first_mark(&mnt->mnt_fsnotify_marks); 36660f7ed8cSAmir Goldstein iter_info.marks[FSNOTIFY_OBJ_TYPE_SB] = 36760f7ed8cSAmir Goldstein fsnotify_first_mark(&sb->s_fsnotify_marks); 3687131485aSEric Paris } 36975c1be48SEric Paris 3708edc6e16SJan Kara /* 37160f7ed8cSAmir Goldstein * We need to merge inode/vfsmount/sb mark lists so that e.g. inode mark 37260f7ed8cSAmir Goldstein * ignore masks are properly reflected for mount/sb mark notifications. 3738edc6e16SJan Kara * That's why this traversal is so complicated... 3748edc6e16SJan Kara */ 375d9a6f30bSAmir Goldstein while (fsnotify_iter_select_report_types(&iter_info)) { 3765b0457adSAmir Goldstein ret = send_to_group(to_tell, mask, data, data_is, cookie, 3775b0457adSAmir Goldstein file_name, &iter_info); 37884a5b68eSEric Paris 379ff8bcbd0SEric Paris if (ret && (mask & ALL_FSNOTIFY_PERM_EVENTS)) 380ff8bcbd0SEric Paris goto out; 381ff8bcbd0SEric Paris 382d9a6f30bSAmir Goldstein fsnotify_iter_next(&iter_info); 3837131485aSEric Paris } 384ff8bcbd0SEric Paris ret = 0; 385ff8bcbd0SEric Paris out: 3869385a84dSJan Kara srcu_read_unlock(&fsnotify_mark_srcu, iter_info.srcu_idx); 387c4ec54b4SEric Paris 38898b5c10dSJean-Christophe Dubois return ret; 38990586523SEric Paris } 39090586523SEric Paris EXPORT_SYMBOL_GPL(fsnotify); 39190586523SEric Paris 3929dd813c1SJan Kara extern struct kmem_cache *fsnotify_mark_connector_cachep; 3939dd813c1SJan Kara 39490586523SEric Paris static __init int fsnotify_init(void) 39590586523SEric Paris { 39675c1be48SEric Paris int ret; 39775c1be48SEric Paris 398007d1e83SAmir Goldstein BUG_ON(hweight32(ALL_FSNOTIFY_BITS) != 23); 39920dee624SEric Paris 40075c1be48SEric Paris ret = init_srcu_struct(&fsnotify_mark_srcu); 40175c1be48SEric Paris if (ret) 40275c1be48SEric Paris panic("initializing fsnotify_mark_srcu"); 40375c1be48SEric Paris 4049dd813c1SJan Kara fsnotify_mark_connector_cachep = KMEM_CACHE(fsnotify_mark_connector, 4059dd813c1SJan Kara SLAB_PANIC); 4069dd813c1SJan Kara 40775c1be48SEric Paris return 0; 40890586523SEric Paris } 40975c1be48SEric Paris core_initcall(fsnotify_init); 410