]> git.karo-electronics.de Git - mv-sheeva.git/blob - fs/notify/fsnotify.c
fsnotify: unified filesystem notification backend
[mv-sheeva.git] / fs / notify / fsnotify.c
1 /*
2  *  Copyright (C) 2008 Red Hat, Inc., Eric Paris <eparis@redhat.com>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2, or (at your option)
7  *  any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; see the file COPYING.  If not, write to
16  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18
19 #include <linux/dcache.h>
20 #include <linux/fs.h>
21 #include <linux/init.h>
22 #include <linux/module.h>
23 #include <linux/srcu.h>
24
25 #include <linux/fsnotify_backend.h>
26 #include "fsnotify.h"
27
28 /*
29  * This is the main call to fsnotify.  The VFS calls into hook specific functions
30  * in linux/fsnotify.h.  Those functions then in turn call here.  Here will call
31  * out to all of the registered fsnotify_group.  Those groups can then use the
32  * notification event in whatever means they feel necessary.
33  */
34 void fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is)
35 {
36         struct fsnotify_group *group;
37         struct fsnotify_event *event = NULL;
38         int idx;
39
40         if (list_empty(&fsnotify_groups))
41                 return;
42
43         if (!(mask & fsnotify_mask))
44                 return;
45
46         /*
47          * SRCU!!  the groups list is very very much read only and the path is
48          * very hot.  The VAST majority of events are not going to need to do
49          * anything other than walk the list so it's crazy to pre-allocate.
50          */
51         idx = srcu_read_lock(&fsnotify_grp_srcu);
52         list_for_each_entry_rcu(group, &fsnotify_groups, group_list) {
53                 if (mask & group->mask) {
54                         if (!event) {
55                                 event = fsnotify_create_event(to_tell, mask, data, data_is);
56                                 /* shit, we OOM'd and now we can't tell, maybe
57                                  * someday someone else will want to do something
58                                  * here */
59                                 if (!event)
60                                         break;
61                         }
62                         group->ops->handle_event(group, event);
63                 }
64         }
65         srcu_read_unlock(&fsnotify_grp_srcu, idx);
66         /*
67          * fsnotify_create_event() took a reference so the event can't be cleaned
68          * up while we are still trying to add it to lists, drop that one.
69          */
70         if (event)
71                 fsnotify_put_event(event);
72 }
73 EXPORT_SYMBOL_GPL(fsnotify);
74
75 static __init int fsnotify_init(void)
76 {
77         return init_srcu_struct(&fsnotify_grp_srcu);
78 }
79 subsys_initcall(fsnotify_init);