]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
inotify: allow users to request not to recieve events on unlinked children
authorEric Paris <eparis@redhat.com>
Wed, 28 Jul 2010 14:18:37 +0000 (10:18 -0400)
committerEric Paris <eparis@redhat.com>
Wed, 28 Jul 2010 14:18:49 +0000 (10:18 -0400)
An inotify watch on a directory will send events for children even if those
children have been unlinked.  This patch add a new inotify flag IN_EXCL_UNLINK
which allows a watch to specificy they don't care about unlinked children.
This should fix performance problems seen by tasks which add a watch to
/tmp and then are overrun with events when other processes are reading and
writing to unlinked files they created in /tmp.

https://bugzilla.kernel.org/show_bug.cgi?id=16296

Requested-by: Matthias Clasen <mclasen@redhat.com>
Signed-off-by: Eric Paris <eparis@redhat.com>
fs/notify/inotify/inotify_fsnotify.c
fs/notify/inotify/inotify_user.c
include/linux/fsnotify_backend.h
include/linux/inotify.h

index 388a150c3d4a4fbda541b4667bc1af106b88b3a2..9d332e7f5a5c582da04a36c6f26a44ca65fffd3d 100644 (file)
@@ -22,6 +22,7 @@
  * General Public License for more details.
  */
 
+#include <linux/dcache.h> /* d_unlinked */
 #include <linux/fs.h> /* struct inode */
 #include <linux/fsnotify_backend.h>
 #include <linux/inotify.h>
@@ -157,6 +158,14 @@ static bool inotify_should_send_event(struct fsnotify_group *group, struct inode
        mask = (mask & ~FS_EVENT_ON_CHILD);
        send = (fsn_mark->mask & mask);
 
+       if (send && (fsn_mark->mask & FS_EXCL_UNLINK) &&
+           (data_type == FSNOTIFY_EVENT_PATH)) {
+               struct path *path  = data;
+
+               if (d_unlinked(path->dentry))
+                       send = false;
+       }
+
        /* find took a reference */
        fsnotify_put_mark(fsn_mark);
 
index f381dafe8efb827508f73c586677838e8debc980..dfc80f70e517880f0bcc1b7d7e195a914a01be7c 100644 (file)
@@ -97,7 +97,7 @@ static inline __u32 inotify_arg_to_mask(u32 arg)
        mask = (FS_IN_IGNORED | FS_EVENT_ON_CHILD | FS_UNMOUNT);
 
        /* mask off the flags used to open the fd */
-       mask |= (arg & (IN_ALL_EVENTS | IN_ONESHOT));
+       mask |= (arg & (IN_ALL_EVENTS | IN_ONESHOT | IN_EXCL_UNLINK));
 
        return mask;
 }
index b9b3f24ad4fcfd90a325ed3d12cec2918c0b042c..4b809fcd4996ebd50064d5310cdad9be38951862 100644 (file)
@@ -44,6 +44,7 @@
 #define FS_OPEN_PERM           0x00010000      /* open event in an permission hook */
 #define FS_ACCESS_PERM         0x00020000      /* access event in a permissions hook */
 
+#define FS_EXCL_UNLINK         0x04000000      /* do not send events if object is unlinked */
 #define FS_IN_ISDIR            0x40000000      /* event occurred against dir */
 #define FS_IN_ONESHOT          0x80000000      /* only send event once */
 
index 94d209a1b68987db9aad7c50de4150df3e5c8131..b74f2ef2c3686c530db576f96a489bd93f1fb1e6 100644 (file)
@@ -51,6 +51,7 @@ struct inotify_event {
 /* special flags */
 #define IN_ONLYDIR             0x01000000      /* only watch the path if it is a directory */
 #define IN_DONT_FOLLOW         0x02000000      /* don't follow a sym link */
+#define IN_EXCL_UNLINK         0x04000000      /* exclude events on unlinked objects */
 #define IN_MASK_ADD            0x20000000      /* add to the mask of an already existing watch */
 #define IN_ISDIR               0x40000000      /* event occurred against dir */
 #define IN_ONESHOT             0x80000000      /* only send event once */