diff options
author | Eric Paris <eparis@redhat.com> | 2009-12-17 21:24:21 -0500 |
---|---|---|
committer | Eric Paris <eparis@redhat.com> | 2010-07-28 09:58:49 -0400 |
commit | 74766bbfa99adf8cb8119df6121851edba21c9d9 (patch) | |
tree | 724dbee0d1e7794401e2d3bdd3c17fd2ce3e4635 /fs/notify/notification.c | |
parent | 28c60e37f874dcbb93c4afc839ba5e4911c4f4bc (diff) |
fsnotify: per group notification queue merge types
inotify only wishes to merge a new event with the last event on the
notification fifo. fanotify is willing to merge any events including by
means of bitwise OR masks of multiple events together. This patch moves
the inotify event merging logic out of the generic fsnotify notification.c
and into the inotify code. This allows each use of fsnotify to provide
their own merge functionality.
Signed-off-by: Eric Paris <eparis@redhat.com>
Diffstat (limited to 'fs/notify/notification.c')
-rw-r--r-- | fs/notify/notification.c | 73 |
1 files changed, 19 insertions, 54 deletions
diff --git a/fs/notify/notification.c b/fs/notify/notification.c index b34ce7ad0409..6dc96b35e4a7 100644 --- a/fs/notify/notification.c +++ b/fs/notify/notification.c | |||
@@ -104,7 +104,8 @@ struct fsnotify_event_holder *fsnotify_alloc_event_holder(void) | |||
104 | 104 | ||
105 | void fsnotify_destroy_event_holder(struct fsnotify_event_holder *holder) | 105 | void fsnotify_destroy_event_holder(struct fsnotify_event_holder *holder) |
106 | { | 106 | { |
107 | kmem_cache_free(fsnotify_event_holder_cachep, holder); | 107 | if (holder) |
108 | kmem_cache_free(fsnotify_event_holder_cachep, holder); | ||
108 | } | 109 | } |
109 | 110 | ||
110 | /* | 111 | /* |
@@ -129,53 +130,17 @@ struct fsnotify_event_private_data *fsnotify_remove_priv_from_event(struct fsnot | |||
129 | } | 130 | } |
130 | 131 | ||
131 | /* | 132 | /* |
132 | * Check if 2 events contain the same information. We do not compare private data | ||
133 | * but at this moment that isn't a problem for any know fsnotify listeners. | ||
134 | */ | ||
135 | static bool event_compare(struct fsnotify_event *old, struct fsnotify_event *new) | ||
136 | { | ||
137 | if ((old->mask == new->mask) && | ||
138 | (old->to_tell == new->to_tell) && | ||
139 | (old->data_type == new->data_type) && | ||
140 | (old->name_len == new->name_len)) { | ||
141 | switch (old->data_type) { | ||
142 | case (FSNOTIFY_EVENT_INODE): | ||
143 | /* remember, after old was put on the wait_q we aren't | ||
144 | * allowed to look at the inode any more, only thing | ||
145 | * left to check was if the file_name is the same */ | ||
146 | if (!old->name_len || | ||
147 | !strcmp(old->file_name, new->file_name)) | ||
148 | return true; | ||
149 | break; | ||
150 | case (FSNOTIFY_EVENT_PATH): | ||
151 | if ((old->path.mnt == new->path.mnt) && | ||
152 | (old->path.dentry == new->path.dentry)) | ||
153 | return true; | ||
154 | break; | ||
155 | case (FSNOTIFY_EVENT_NONE): | ||
156 | if (old->mask & FS_Q_OVERFLOW) | ||
157 | return true; | ||
158 | else if (old->mask & FS_IN_IGNORED) | ||
159 | return false; | ||
160 | return false; | ||
161 | }; | ||
162 | } | ||
163 | return false; | ||
164 | } | ||
165 | |||
166 | /* | ||
167 | * Add an event to the group notification queue. The group can later pull this | 133 | * Add an event to the group notification queue. The group can later pull this |
168 | * event off the queue to deal with. If the event is successfully added to the | 134 | * event off the queue to deal with. If the event is successfully added to the |
169 | * group's notification queue, a reference is taken on event. | 135 | * group's notification queue, a reference is taken on event. |
170 | */ | 136 | */ |
171 | int fsnotify_add_notify_event(struct fsnotify_group *group, struct fsnotify_event *event, | 137 | int fsnotify_add_notify_event(struct fsnotify_group *group, struct fsnotify_event *event, |
172 | struct fsnotify_event_private_data *priv) | 138 | struct fsnotify_event_private_data *priv, |
139 | int (*merge)(struct list_head *, struct fsnotify_event *)) | ||
173 | { | 140 | { |
174 | struct fsnotify_event_holder *holder = NULL; | 141 | struct fsnotify_event_holder *holder = NULL; |
175 | struct list_head *list = &group->notification_list; | 142 | struct list_head *list = &group->notification_list; |
176 | struct fsnotify_event_holder *last_holder; | 143 | int rc = 0; |
177 | struct fsnotify_event *last_event; | ||
178 | int ret = 0; | ||
179 | 144 | ||
180 | /* | 145 | /* |
181 | * There is one fsnotify_event_holder embedded inside each fsnotify_event. | 146 | * There is one fsnotify_event_holder embedded inside each fsnotify_event. |
@@ -196,11 +161,23 @@ alloc_holder: | |||
196 | 161 | ||
197 | if (group->q_len >= group->max_events) { | 162 | if (group->q_len >= group->max_events) { |
198 | event = q_overflow_event; | 163 | event = q_overflow_event; |
199 | ret = -EOVERFLOW; | 164 | rc = -EOVERFLOW; |
200 | /* sorry, no private data on the overflow event */ | 165 | /* sorry, no private data on the overflow event */ |
201 | priv = NULL; | 166 | priv = NULL; |
202 | } | 167 | } |
203 | 168 | ||
169 | if (!list_empty(list) && merge) { | ||
170 | int ret; | ||
171 | |||
172 | ret = merge(list, event); | ||
173 | if (ret) { | ||
174 | mutex_unlock(&group->notification_mutex); | ||
175 | if (holder != &event->holder) | ||
176 | fsnotify_destroy_event_holder(holder); | ||
177 | return ret; | ||
178 | } | ||
179 | } | ||
180 | |||
204 | spin_lock(&event->lock); | 181 | spin_lock(&event->lock); |
205 | 182 | ||
206 | if (list_empty(&event->holder.event_list)) { | 183 | if (list_empty(&event->holder.event_list)) { |
@@ -215,18 +192,6 @@ alloc_holder: | |||
215 | goto alloc_holder; | 192 | goto alloc_holder; |
216 | } | 193 | } |
217 | 194 | ||
218 | if (!list_empty(list)) { | ||
219 | last_holder = list_entry(list->prev, struct fsnotify_event_holder, event_list); | ||
220 | last_event = last_holder->event; | ||
221 | if (event_compare(last_event, event)) { | ||
222 | spin_unlock(&event->lock); | ||
223 | mutex_unlock(&group->notification_mutex); | ||
224 | if (holder != &event->holder) | ||
225 | fsnotify_destroy_event_holder(holder); | ||
226 | return -EEXIST; | ||
227 | } | ||
228 | } | ||
229 | |||
230 | group->q_len++; | 195 | group->q_len++; |
231 | holder->event = event; | 196 | holder->event = event; |
232 | 197 | ||
@@ -238,7 +203,7 @@ alloc_holder: | |||
238 | mutex_unlock(&group->notification_mutex); | 203 | mutex_unlock(&group->notification_mutex); |
239 | 204 | ||
240 | wake_up(&group->notification_waitq); | 205 | wake_up(&group->notification_waitq); |
241 | return ret; | 206 | return rc; |
242 | } | 207 | } |
243 | 208 | ||
244 | /* | 209 | /* |