From: Eric Paris <eparis@redhat.com>
To: linux-kernel@vger.kernel.org, linus-fsdevel@vger.kernel.org
Cc: viro@zeniv.linux.org.uk, hch@infradead.org, agruen@suse.de,
eparis@redhat.com
Subject: [PATCH 04/10] fanotify: merge notification events with different masks
Date: Sat, 31 Oct 2009 14:47:41 -0400 [thread overview]
Message-ID: <20091031184741.17244.16660.stgit@paris.rdu.redhat.com> (raw)
In-Reply-To: <20091031184721.17244.16465.stgit@paris.rdu.redhat.com>
Instead of just merging fanotify events if they are exactly the same, merge
notification events with different masks. To do this we have to clone the
old event, update the mask in the new event with the new merged mask, and
put the new event in place of the old event.
Signed-off-by: Eric Paris <eparis@redhat.com>
---
fs/notify/fanotify/fanotify.c | 39 ++++++++++++++++++++++++++++++---------
1 files changed, 30 insertions(+), 9 deletions(-)
diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
index c35c117..8e574d6 100644
--- a/fs/notify/fanotify/fanotify.c
+++ b/fs/notify/fanotify/fanotify.c
@@ -10,8 +10,7 @@ static bool should_merge(struct fsnotify_event *old, struct fsnotify_event *new)
{
pr_debug("%s: old=%p new=%p\n", __func__, old, new);
- if ((old->mask == new->mask) &&
- (old->to_tell == new->to_tell) &&
+ if ((old->to_tell == new->to_tell) &&
(old->data_type == new->data_type)) {
switch (old->data_type) {
case (FSNOTIFY_EVENT_PATH):
@@ -29,20 +28,42 @@ static bool should_merge(struct fsnotify_event *old, struct fsnotify_event *new)
static int fanotify_merge(struct list_head *list, struct fsnotify_event *event)
{
- struct fsnotify_event_holder *holder;
+ struct fsnotify_event_holder *test_holder;
struct fsnotify_event *test_event;
+ struct fsnotify_event *new_event;
+ int ret = 0;
pr_debug("%s: list=%p event=%p\n", __func__, list, event);
/* and the list better be locked by something too! */
- list_for_each_entry_reverse(holder, list, event_list) {
- test_event = holder->event;
- if (should_merge(test_event, event))
- return -EEXIST;
+ list_for_each_entry_reverse(test_holder, list, event_list) {
+ test_event = test_holder->event;
+ if (should_merge(test_event, event)) {
+ ret = -EEXIST;
+
+ /* if they are exactly the same we are done */
+ if (test_event->mask == event->mask)
+ goto out;
+
+ /* can't allocate memory, merge was no possible */
+ new_event = fsnotify_clone_event(test_event);
+ if (unlikely(!new_event)) {
+ ret = 0;
+ goto out;
+ }
+
+ /* build new event and replace it on the list */
+ new_event->mask = (test_event->mask | event->mask);
+ fsnotify_replace_event(test_holder, new_event);
+ /* match ref from fsnotify_clone_event() */
+ fsnotify_put_event(new_event);
+
+ break;
+ }
}
-
- return 0;
+out:
+ return ret;
}
static int fanotify_handle_event(struct fsnotify_group *group, struct fsnotify_event *event)
next prev parent reply other threads:[~2009-10-31 18:47 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-31 18:47 [PATCH 01/10] vfs: introduce FMODE_NONOTIFY Eric Paris
2009-10-31 18:47 ` [PATCH 02/10] fanotify: fscking all notification system Eric Paris
2009-11-06 15:31 ` Eric Paris
2009-11-06 15:54 ` Andreas Gruenbacher
2009-10-31 18:47 ` [PATCH 03/10] fanotify:drop notification if they exist in the outgoing queue Eric Paris
2009-10-31 18:47 ` Eric Paris [this message]
2009-10-31 18:47 ` [PATCH 05/10] fanotify: do not clone on merge unless needed Eric Paris
2009-10-31 18:47 ` [PATCH 06/10] fanotify: fanotify_init syscall declaration Eric Paris
2009-10-31 18:48 ` [PATCH 07/10] fanotify: fanotify_init syscall implementation Eric Paris
2009-10-31 18:48 ` [PATCH 08/10] fanotify: sys_fanotify_mark declartion Eric Paris
2009-10-31 18:48 ` [PATCH 09/10] fanotify: fanotify_mark syscall implementation Eric Paris
2009-10-31 18:48 ` [PATCH 10/10] send events using read Eric Paris
2009-11-03 23:59 ` Jonathan Corbet
2009-11-04 0:55 ` Eric Paris
2009-11-04 8:07 ` Vegard Nossum
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=20091031184741.17244.16660.stgit@paris.rdu.redhat.com \
--to=eparis@redhat.com \
--cc=agruen@suse.de \
--cc=hch@infradead.org \
--cc=linus-fsdevel@vger.kernel.org \
--cc=linux-kernel@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