@@ -28,6 +28,11 @@ void __fsnotify_vfsmount_delete(struct vfsmount *mnt)
2828 fsnotify_clear_marks_by_mount (mnt );
2929}
3030
31+ void __fsnotify_mntns_delete (struct mnt_namespace * mntns )
32+ {
33+ fsnotify_clear_marks_by_mntns (mntns );
34+ }
35+
3136/**
3237 * fsnotify_unmount_inodes - an sb is unmounting. handle any watched inodes.
3338 * @sb: superblock being unmounted.
@@ -420,7 +425,7 @@ static int send_to_group(__u32 mask, const void *data, int data_type,
420425 file_name , cookie , iter_info );
421426}
422427
423- static struct fsnotify_mark * fsnotify_first_mark (struct fsnotify_mark_connector * * connp )
428+ static struct fsnotify_mark * fsnotify_first_mark (struct fsnotify_mark_connector * const * connp )
424429{
425430 struct fsnotify_mark_connector * conn ;
426431 struct hlist_node * node = NULL ;
@@ -538,14 +543,15 @@ int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir,
538543{
539544 const struct path * path = fsnotify_data_path (data , data_type );
540545 struct super_block * sb = fsnotify_data_sb (data , data_type );
541- struct fsnotify_sb_info * sbinfo = fsnotify_sb_info (sb );
546+ const struct fsnotify_mnt * mnt_data = fsnotify_data_mnt (data , data_type );
547+ struct fsnotify_sb_info * sbinfo = sb ? fsnotify_sb_info (sb ) : NULL ;
542548 struct fsnotify_iter_info iter_info = {};
543549 struct mount * mnt = NULL ;
544550 struct inode * inode2 = NULL ;
545551 struct dentry * moved ;
546552 int inode2_type ;
547553 int ret = 0 ;
548- __u32 test_mask , marks_mask ;
554+ __u32 test_mask , marks_mask = 0 ;
549555
550556 if (path )
551557 mnt = real_mount (path -> mnt );
@@ -578,17 +584,20 @@ int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir,
578584 if ((!sbinfo || !sbinfo -> sb_marks ) &&
579585 (!mnt || !mnt -> mnt_fsnotify_marks ) &&
580586 (!inode || !inode -> i_fsnotify_marks ) &&
581- (!inode2 || !inode2 -> i_fsnotify_marks ))
587+ (!inode2 || !inode2 -> i_fsnotify_marks ) &&
588+ (!mnt_data || !mnt_data -> ns -> n_fsnotify_marks ))
582589 return 0 ;
583590
584- marks_mask = READ_ONCE (sb -> s_fsnotify_mask );
591+ if (sb )
592+ marks_mask |= READ_ONCE (sb -> s_fsnotify_mask );
585593 if (mnt )
586594 marks_mask |= READ_ONCE (mnt -> mnt_fsnotify_mask );
587595 if (inode )
588596 marks_mask |= READ_ONCE (inode -> i_fsnotify_mask );
589597 if (inode2 )
590598 marks_mask |= READ_ONCE (inode2 -> i_fsnotify_mask );
591-
599+ if (mnt_data )
600+ marks_mask |= READ_ONCE (mnt_data -> ns -> n_fsnotify_mask );
592601
593602 /*
594603 * If this is a modify event we may need to clear some ignore masks.
@@ -618,6 +627,10 @@ int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir,
618627 iter_info .marks [inode2_type ] =
619628 fsnotify_first_mark (& inode2 -> i_fsnotify_marks );
620629 }
630+ if (mnt_data ) {
631+ iter_info .marks [FSNOTIFY_ITER_TYPE_MNTNS ] =
632+ fsnotify_first_mark (& mnt_data -> ns -> n_fsnotify_marks );
633+ }
621634
622635 /*
623636 * We need to merge inode/vfsmount/sb mark lists so that e.g. inode mark
@@ -702,11 +715,31 @@ void file_set_fsnotify_mode(struct file *file)
702715}
703716#endif
704717
718+ void fsnotify_mnt (__u32 mask , struct mnt_namespace * ns , struct vfsmount * mnt )
719+ {
720+ struct fsnotify_mnt data = {
721+ .ns = ns ,
722+ .mnt_id = real_mount (mnt )-> mnt_id_unique ,
723+ };
724+
725+ if (WARN_ON_ONCE (!ns ))
726+ return ;
727+
728+ /*
729+ * This is an optimization as well as making sure fsnotify_init() has
730+ * been called.
731+ */
732+ if (!ns -> n_fsnotify_marks )
733+ return ;
734+
735+ fsnotify (mask , & data , FSNOTIFY_EVENT_MNT , NULL , NULL , NULL , 0 );
736+ }
737+
705738static __init int fsnotify_init (void )
706739{
707740 int ret ;
708741
709- BUILD_BUG_ON (HWEIGHT32 (ALL_FSNOTIFY_BITS ) != 24 );
742+ BUILD_BUG_ON (HWEIGHT32 (ALL_FSNOTIFY_BITS ) != 26 );
710743
711744 ret = init_srcu_struct (& fsnotify_mark_srcu );
712745 if (ret )
0 commit comments