Commit 7ea6040b authored by John McCutchan's avatar John McCutchan Committed by Linus Torvalds

[PATCH] inotify: fix event loss on hardlinked files

People have run into a problem when they do this:

watch (file1, all_events);
watch (file2, some_events);

if file2 is a hard link to file1, some events will be missed because by
default we replace the mask.  The patch below adds a flag IN_MASK_ADD which
will cause inotify to add to the existing mask if present.
Signed-off-by: default avatarJohn McCutchan <ttb@tentacle.dhs.org>
Signed-off-by: default avatarRobert Love <rml@novell.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 8191151d
...@@ -931,6 +931,7 @@ asmlinkage long sys_inotify_add_watch(int fd, const char __user *path, u32 mask) ...@@ -931,6 +931,7 @@ asmlinkage long sys_inotify_add_watch(int fd, const char __user *path, u32 mask)
struct nameidata nd; struct nameidata nd;
struct file *filp; struct file *filp;
int ret, fput_needed; int ret, fput_needed;
int mask_add = 0;
filp = fget_light(fd, &fput_needed); filp = fget_light(fd, &fput_needed);
if (unlikely(!filp)) if (unlikely(!filp))
...@@ -953,6 +954,9 @@ asmlinkage long sys_inotify_add_watch(int fd, const char __user *path, u32 mask) ...@@ -953,6 +954,9 @@ asmlinkage long sys_inotify_add_watch(int fd, const char __user *path, u32 mask)
down(&inode->inotify_sem); down(&inode->inotify_sem);
down(&dev->sem); down(&dev->sem);
if (mask & IN_MASK_ADD)
mask_add = 1;
/* don't let user-space set invalid bits: we don't want flags set */ /* don't let user-space set invalid bits: we don't want flags set */
mask &= IN_ALL_EVENTS; mask &= IN_ALL_EVENTS;
if (unlikely(!mask)) { if (unlikely(!mask)) {
...@@ -966,7 +970,10 @@ asmlinkage long sys_inotify_add_watch(int fd, const char __user *path, u32 mask) ...@@ -966,7 +970,10 @@ asmlinkage long sys_inotify_add_watch(int fd, const char __user *path, u32 mask)
*/ */
old = inode_find_dev(inode, dev); old = inode_find_dev(inode, dev);
if (unlikely(old)) { if (unlikely(old)) {
old->mask = mask; if (mask_add)
old->mask |= mask;
else
old->mask = mask;
ret = old->wd; ret = old->wd;
goto out; goto out;
} }
......
...@@ -47,6 +47,7 @@ struct inotify_event { ...@@ -47,6 +47,7 @@ struct inotify_event {
#define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) /* moves */ #define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) /* moves */
/* special flags */ /* special flags */
#define IN_MASK_ADD 0x20000000 /* add to the mask of an already existing watch */
#define IN_ISDIR 0x40000000 /* event occurred against dir */ #define IN_ISDIR 0x40000000 /* event occurred against dir */
#define IN_ONESHOT 0x80000000 /* only send event once */ #define IN_ONESHOT 0x80000000 /* only send event once */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment