aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Paris <eparis@redhat.com>2009-12-17 21:24:25 -0500
committerEric Paris <eparis@redhat.com>2010-07-28 09:58:54 -0400
commit767cd46c332d1360cdbe46ef18d80c3ade06fdc1 (patch)
treee3868f28587ca44efd10b30aa4230ff54d09f567
parentff0b16a9850e8a240ad59e10b0a1291a8fcf7cbc (diff)
fanotify:drop notification if they exist in the outgoing queue
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>
-rw-r--r--fs/notify/fanotify/fanotify.c45
1 files changed, 43 insertions, 2 deletions
diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
index 3ffb9dbcab08..c35c1175c4cf 100644
--- a/fs/notify/fanotify/fanotify.c
+++ b/fs/notify/fanotify/fanotify.c
@@ -6,6 +6,45 @@
6 6
7#include "fanotify.h" 7#include "fanotify.h"
8 8
9static bool should_merge(struct fsnotify_event *old, struct fsnotify_event *new)
10{
11 pr_debug("%s: old=%p new=%p\n", __func__, old, new);
12
13 if ((old->mask == new->mask) &&
14 (old->to_tell == new->to_tell) &&
15 (old->data_type == new->data_type)) {
16 switch (old->data_type) {
17 case (FSNOTIFY_EVENT_PATH):
18 if ((old->path.mnt == new->path.mnt) &&
19 (old->path.dentry == new->path.dentry))
20 return true;
21 case (FSNOTIFY_EVENT_NONE):
22 return true;
23 default:
24 BUG();
25 };
26 }
27 return false;
28}
29
30static int fanotify_merge(struct list_head *list, struct fsnotify_event *event)
31{
32 struct fsnotify_event_holder *holder;
33 struct fsnotify_event *test_event;
34
35 pr_debug("%s: list=%p event=%p\n", __func__, list, event);
36
37 /* and the list better be locked by something too! */
38
39 list_for_each_entry_reverse(holder, list, event_list) {
40 test_event = holder->event;
41 if (should_merge(test_event, event))
42 return -EEXIST;
43 }
44
45 return 0;
46}
47
9static int fanotify_handle_event(struct fsnotify_group *group, struct fsnotify_event *event) 48static int fanotify_handle_event(struct fsnotify_group *group, struct fsnotify_event *event)
10{ 49{
11 int ret; 50 int ret;
@@ -21,8 +60,10 @@ static int fanotify_handle_event(struct fsnotify_group *group, struct fsnotify_e
21 60
22 pr_debug("%s: group=%p event=%p\n", __func__, group, event); 61 pr_debug("%s: group=%p event=%p\n", __func__, group, event);
23 62
24 ret = fsnotify_add_notify_event(group, event, NULL, NULL); 63 ret = fsnotify_add_notify_event(group, event, NULL, fanotify_merge);
25 64 /* -EEXIST means this event was merged with another, not that it was an error */
65 if (ret == -EEXIST)
66 ret = 0;
26 return ret; 67 return ret;
27} 68}
28 69