@@ -142,10 +142,10 @@ void fsnotify_detach_mark(struct fsnotify_mark *mark)
142142
143143 mark -> flags &= ~FSNOTIFY_MARK_FLAG_ATTACHED ;
144144
145- if (mark -> flags & FSNOTIFY_MARK_FLAG_INODE ) {
146- inode = mark -> inode ;
145+ if (mark -> connector -> flags & FSNOTIFY_OBJ_TYPE_INODE ) {
146+ inode = mark -> connector -> inode ;
147147 fsnotify_destroy_inode_mark (mark );
148- } else if (mark -> flags & FSNOTIFY_MARK_FLAG_VFSMOUNT )
148+ } else if (mark -> connector -> flags & FSNOTIFY_OBJ_TYPE_VFSMOUNT )
149149 fsnotify_destroy_vfsmount_mark (mark );
150150 else
151151 BUG ();
@@ -275,7 +275,7 @@ void fsnotify_set_mark_mask_locked(struct fsnotify_mark *mark, __u32 mask)
275275
276276 mark -> mask = mask ;
277277
278- if (mark -> flags & FSNOTIFY_MARK_FLAG_INODE )
278+ if (mark -> connector && mark -> connector -> flags & FSNOTIFY_OBJ_TYPE_INODE )
279279 fsnotify_set_inode_mark_mask_locked (mark , mask );
280280}
281281
@@ -323,14 +323,23 @@ int fsnotify_compare_groups(struct fsnotify_group *a, struct fsnotify_group *b)
323323}
324324
325325static int fsnotify_attach_connector_to_object (
326- struct fsnotify_mark_connector * * connp )
326+ struct fsnotify_mark_connector * * connp ,
327+ struct inode * inode ,
328+ struct vfsmount * mnt )
327329{
328330 struct fsnotify_mark_connector * conn ;
329331
330332 conn = kmem_cache_alloc (fsnotify_mark_connector_cachep , GFP_ATOMIC );
331333 if (!conn )
332334 return - ENOMEM ;
333335 INIT_HLIST_HEAD (& conn -> list );
336+ if (inode ) {
337+ conn -> flags = FSNOTIFY_OBJ_TYPE_INODE ;
338+ conn -> inode = inode ;
339+ } else {
340+ conn -> flags = FSNOTIFY_OBJ_TYPE_VFSMOUNT ;
341+ conn -> mnt = mnt ;
342+ }
334343 /*
335344 * Make sure 'conn' initialization is visible. Matches
336345 * lockless_dereference() in fsnotify().
@@ -348,15 +357,16 @@ static int fsnotify_attach_connector_to_object(
348357 * priority, highest number first, and then by the group's location in memory.
349358 */
350359int fsnotify_add_mark_list (struct fsnotify_mark_connector * * connp ,
351- struct fsnotify_mark * mark , int allow_dups )
360+ struct fsnotify_mark * mark , struct inode * inode ,
361+ struct vfsmount * mnt , int allow_dups )
352362{
353363 struct fsnotify_mark * lmark , * last = NULL ;
354364 struct fsnotify_mark_connector * conn ;
355365 int cmp ;
356366 int err ;
357367
358368 if (!* connp ) {
359- err = fsnotify_attach_connector_to_object (connp );
369+ err = fsnotify_attach_connector_to_object (connp , inode , mnt );
360370 if (err )
361371 return err ;
362372 }
@@ -365,7 +375,7 @@ int fsnotify_add_mark_list(struct fsnotify_mark_connector **connp,
365375 /* is mark the first mark? */
366376 if (hlist_empty (& conn -> list )) {
367377 hlist_add_head_rcu (& mark -> obj_list , & conn -> list );
368- return 0 ;
378+ goto added ;
369379 }
370380
371381 /* should mark be in the middle of the current list? */
@@ -378,13 +388,15 @@ int fsnotify_add_mark_list(struct fsnotify_mark_connector **connp,
378388 cmp = fsnotify_compare_groups (lmark -> group , mark -> group );
379389 if (cmp >= 0 ) {
380390 hlist_add_before_rcu (& mark -> obj_list , & lmark -> obj_list );
381- return 0 ;
391+ goto added ;
382392 }
383393 }
384394
385395 BUG_ON (last == NULL );
386396 /* mark should be the last entry. last is the current last entry */
387397 hlist_add_behind_rcu (& mark -> obj_list , & last -> obj_list );
398+ added :
399+ mark -> connector = conn ;
388400 return 0 ;
389401}
390402
@@ -507,7 +519,7 @@ void fsnotify_clear_marks_by_group_flags(struct fsnotify_group *group,
507519 */
508520 mutex_lock_nested (& group -> mark_mutex , SINGLE_DEPTH_NESTING );
509521 list_for_each_entry_safe (mark , lmark , & group -> marks_list , g_list ) {
510- if (mark -> flags & flags )
522+ if (mark -> connector -> flags & flags )
511523 list_move (& mark -> g_list , & to_free );
512524 }
513525 mutex_unlock (& group -> mark_mutex );
0 commit comments