linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Paris <eparis@redhat.com>
To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	netdev@vger.kernel.org
Cc: davem@davemloft.net, viro@zeniv.linux.org.uk,
	alan@linux.intel.com, hch@infradead.org
Subject: [PATCH 5/9] fanotify:drop notification if they exist in the outgoing queue
Date: Fri, 28 Aug 2009 14:56:12 -0400	[thread overview]
Message-ID: <20090828185611.8014.4931.stgit@paris.rdu.redhat.com> (raw)
In-Reply-To: <20090828185542.8014.22791.stgit@paris.rdu.redhat.com>

fanotify listeners get an open file descriptor to the object in question so
the ordering of operations is not as important as in other notification
systems.  inotify will drop events if the last event in the event FIFO is
the same as the current event.  This patch will drop fanotify events if
they are the same as another event anywhere in the event FIFO.

Signed-off-by: Eric Paris <eparis@redhat.com>
---

 fs/notify/fanotify/fanotify.c |   40 ++++++++++++++++++++++++++++++++++++++--
 1 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
index 59bc883..caf34bb 100644
--- a/fs/notify/fanotify/fanotify.c
+++ b/fs/notify/fanotify/fanotify.c
@@ -8,6 +8,40 @@
 
 #include "fanotify.h"
 
+static bool try_merge(struct fsnotify_event *old, struct fsnotify_event *new)
+{
+	if ((old->mask == new->mask) &&
+	    (old->to_tell == new->to_tell) &&
+	    (old->data_type == new->data_type)) {
+		switch (old->data_type) {
+		case (FSNOTIFY_EVENT_PATH):
+			if ((old->path.mnt == new->path.mnt) &&
+			    (old->path.dentry == new->path.dentry))
+				return true;
+		case (FSNOTIFY_EVENT_NONE):
+			return true;
+		default:
+			BUG();
+		};
+	}
+	return false;
+}
+
+static int fanotify_merge(struct list_head *list, struct fsnotify_event *event)
+{
+	struct fsnotify_event_holder *holder;
+	struct fsnotify_event *test_event;
+
+	/* and the list better be locked by something too! */
+
+	list_for_each_entry_reverse(holder, list, event_list) {
+		test_event = holder->event;
+		if (try_merge(test_event, event))
+			return -EEXIST;
+	}
+
+	return 0;
+}
 static int fanotify_handle_event(struct fsnotify_group *group, struct fsnotify_event *event)
 {
 	int ret;
@@ -20,8 +54,10 @@ static int fanotify_handle_event(struct fsnotify_group *group, struct fsnotify_e
 	BUILD_BUG_ON(FAN_EVENT_ON_CHILD != FS_EVENT_ON_CHILD);
 	BUILD_BUG_ON(FAN_Q_OVERFLOW != FS_Q_OVERFLOW);
 
-	ret = fsnotify_add_notify_event(group, event, NULL, NULL);
-
+	ret = fsnotify_add_notify_event(group, event, NULL, fanotify_merge);
+	/* -EEXIST means this event was merged with another, not that it was an error */
+	if (ret == -EEXIST)
+		ret = 0;
 	return ret;
 }
 


  parent reply	other threads:[~2009-08-28 18:56 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-28 18:55 [PATCH 1/9] task_struct: add PF_NONOTIFY for fanotify to use Eric Paris
2009-08-28 18:55 ` [PATCH 2/9] vfs: introduce FMODE_NONOTIFY Eric Paris
2009-08-28 18:55 ` [PATCH 3/9] networking/fanotify: declare fanotify socket numbers Eric Paris
2009-08-28 18:56 ` [PATCH 4/9] fanotify: fscking all notification system Eric Paris
2009-08-28 18:56 ` Eric Paris [this message]
2009-08-28 18:56 ` [PATCH 6/9] fanotify: merge notification events with different masks Eric Paris
2009-08-28 18:56 ` [PATCH 7/9] fanotify: userspace socket Eric Paris
2009-08-28 18:56 ` [PATCH 8/9] fanotify: userspace can add and remove fsnotify inode marks Eric Paris
2009-08-28 18:56 ` [PATCH 9/9] fanotify: send events to userspace over socket reads Eric Paris
2009-08-28 22:36 ` [PATCH 1/9] task_struct: add PF_NONOTIFY for fanotify to use Evgeniy Polyakov
2009-08-28 22:39   ` Eric Paris
2009-08-28 22:50     ` Evgeniy Polyakov
2009-09-03 20:25   ` Eric Paris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090828185611.8014.4931.stgit@paris.rdu.redhat.com \
    --to=eparis@redhat.com \
    --cc=alan@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=hch@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).