/* Expect random access pattern */
 #define FMODE_RANDOM           ((__force fmode_t)0x1000)
 
+/* File was opened by fanotify and shouldn't generate fanotify events */
+#define FMODE_NONOTIFY         ((__force fmode_t)8388608)
+
 /*
  * The below are the various read and write types that we support. Some of
  * them include behavioral modifiers that send information down to the
 int __init get_filesystem_list(char *buf);
 
 #define ACC_MODE(x) ("\004\002\006\006"[(x)&O_ACCMODE])
-#define OPEN_FMODE(flag) ((__force fmode_t)((flag + 1) & O_ACCMODE))
+#define OPEN_FMODE(flag) ((__force fmode_t)(((flag + 1) & O_ACCMODE) | \
+                                           (flag & FMODE_NONOTIFY)))
 
 #endif /* __KERNEL__ */
 #endif /* _LINUX_FS_H */
 
        if (S_ISDIR(inode->i_mode))
                mask |= FS_IN_ISDIR;
 
-       fsnotify_parent(path, NULL, mask);
-       fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
+       if (!(file->f_mode & FMODE_NONOTIFY)) {
+               fsnotify_parent(path, NULL, mask);
+               fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
+       }
 }
 
 /*
        if (S_ISDIR(inode->i_mode))
                mask |= FS_IN_ISDIR;
 
-       fsnotify_parent(path, NULL, mask);
-       fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
+       if (!(file->f_mode & FMODE_NONOTIFY)) {
+               fsnotify_parent(path, NULL, mask);
+               fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
+       }
 }
 
 /*
        if (S_ISDIR(inode->i_mode))
                mask |= FS_IN_ISDIR;
 
-       fsnotify_parent(path, NULL, mask);
-       fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
+       if (!(file->f_mode & FMODE_NONOTIFY)) {
+               fsnotify_parent(path, NULL, mask);
+               fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
+       }
 }
 
 /*
        if (S_ISDIR(inode->i_mode))
                mask |= FS_IN_ISDIR;
 
-       fsnotify_parent(path, NULL, mask);
-       fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
+       if (!(file->f_mode & FMODE_NONOTIFY)) {
+               fsnotify_parent(path, NULL, mask);
+               fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
+       }
 }
 
 /*