@@ -144,29 +144,30 @@ void __fsnotify_flush_ignored_mask(struct inode *inode, void *data, int data_is)
144144{
145145 struct fsnotify_mark * mark ;
146146 struct hlist_node * node ;
147+ int idx ;
148+
149+ idx = srcu_read_lock (& fsnotify_mark_srcu );
147150
148151 if (!hlist_empty (& inode -> i_fsnotify_marks )) {
149- spin_lock (& inode -> i_lock );
150- hlist_for_each_entry (mark , node , & inode -> i_fsnotify_marks , i .i_list ) {
152+ hlist_for_each_entry_rcu (mark , node , & inode -> i_fsnotify_marks , i .i_list ) {
151153 if (!(mark -> flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY ))
152154 mark -> ignored_mask = 0 ;
153155 }
154- spin_unlock (& inode -> i_lock );
155156 }
156157
157158 if (data_is == FSNOTIFY_EVENT_FILE ) {
158159 struct vfsmount * mnt ;
159160
160161 mnt = ((struct file * )data )-> f_path .mnt ;
161162 if (mnt && !hlist_empty (& mnt -> mnt_fsnotify_marks )) {
162- spin_lock (& mnt -> mnt_root -> d_lock );
163- hlist_for_each_entry (mark , node , & mnt -> mnt_fsnotify_marks , m .m_list ) {
163+ hlist_for_each_entry_rcu (mark , node , & mnt -> mnt_fsnotify_marks , m .m_list ) {
164164 if (!(mark -> flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY ))
165165 mark -> ignored_mask = 0 ;
166166 }
167- spin_unlock (& mnt -> mnt_root -> d_lock );
168167 }
169168 }
169+
170+ srcu_read_unlock (& fsnotify_mark_srcu , idx );
170171}
171172
172173static int send_to_group (struct fsnotify_group * group , struct inode * to_tell ,
@@ -208,8 +209,10 @@ static bool needed_by_vfsmount(__u32 test_mask, struct vfsmount *mnt)
208209int fsnotify (struct inode * to_tell , __u32 mask , void * data , int data_is ,
209210 const unsigned char * file_name , u32 cookie )
210211{
212+ struct fsnotify_mark * mark ;
211213 struct fsnotify_group * group ;
212214 struct fsnotify_event * event = NULL ;
215+ struct hlist_node * node ;
213216 struct vfsmount * mnt = NULL ;
214217 int idx , ret = 0 ;
215218 /* global tests shouldn't care about events on child only the specific event */
@@ -237,35 +240,47 @@ int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,
237240 !needed_by_vfsmount (test_mask , mnt ))
238241 return 0 ;
239242
240- /*
241- * SRCU!! the groups list is very very much read only and the path is
242- * very hot. The VAST majority of events are not going to need to do
243- * anything other than walk the list so it's crazy to pre-allocate.
244- */
245- idx = srcu_read_lock (& fsnotify_grp_srcu );
243+ idx = srcu_read_lock (& fsnotify_mark_srcu );
246244
247245 if (test_mask & to_tell -> i_fsnotify_mask ) {
248- list_for_each_entry_rcu (group , & fsnotify_inode_groups , inode_group_list ) {
249- if (test_mask & group -> mask ) {
250- ret = send_to_group (group , to_tell , NULL , mask , data , data_is ,
251- cookie , file_name , & event );
246+ hlist_for_each_entry_rcu (mark , node , & to_tell -> i_fsnotify_marks , i .i_list ) {
247+
248+ pr_debug ("%s: inode_loop: mark=%p mark->mask=%x mark->ignored_mask=%x\n" ,
249+ __func__ , mark , mark -> mask , mark -> ignored_mask );
250+
251+ if (test_mask & mark -> mask & ~mark -> ignored_mask ) {
252+ group = mark -> group ;
253+ if (!group )
254+ continue ;
255+ ret = send_to_group (group , to_tell , NULL , mask ,
256+ data , data_is , cookie , file_name ,
257+ & event );
252258 if (ret )
253259 goto out ;
254260 }
255261 }
256262 }
257- if (needed_by_vfsmount (test_mask , mnt )) {
258- list_for_each_entry_rcu (group , & fsnotify_vfsmount_groups , vfsmount_group_list ) {
259- if (test_mask & group -> mask ) {
260- ret = send_to_group (group , to_tell , mnt , mask , data , data_is ,
261- cookie , file_name , & event );
263+
264+ if (mnt && (test_mask & mnt -> mnt_fsnotify_mask )) {
265+ hlist_for_each_entry_rcu (mark , node , & mnt -> mnt_fsnotify_marks , m .m_list ) {
266+
267+ pr_debug ("%s: mnt_loop: mark=%p mark->mask=%x mark->ignored_mask=%x\n" ,
268+ __func__ , mark , mark -> mask , mark -> ignored_mask );
269+
270+ if (test_mask & mark -> mask & ~mark -> ignored_mask ) {
271+ group = mark -> group ;
272+ if (!group )
273+ continue ;
274+ ret = send_to_group (group , to_tell , mnt , mask ,
275+ data , data_is , cookie , file_name ,
276+ & event );
262277 if (ret )
263278 goto out ;
264279 }
265280 }
266281 }
267282out :
268- srcu_read_unlock (& fsnotify_grp_srcu , idx );
283+ srcu_read_unlock (& fsnotify_mark_srcu , idx );
269284 /*
270285 * fsnotify_create_event() took a reference so the event can't be cleaned
271286 * up while we are still trying to add it to lists, drop that one.
@@ -279,8 +294,14 @@ EXPORT_SYMBOL_GPL(fsnotify);
279294
280295static __init int fsnotify_init (void )
281296{
297+ int ret ;
298+
282299 BUG_ON (hweight32 (ALL_FSNOTIFY_EVENTS ) != 23 );
283300
284- return init_srcu_struct (& fsnotify_grp_srcu );
301+ ret = init_srcu_struct (& fsnotify_mark_srcu );
302+ if (ret )
303+ panic ("initializing fsnotify_mark_srcu" );
304+
305+ return 0 ;
285306}
286- subsys_initcall (fsnotify_init );
307+ core_initcall (fsnotify_init );
0 commit comments