2 * Copyright (C) 2008 Red Hat, Inc., Eric Paris <eparis@redhat.com>
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)
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.
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.
19 #include <linux/dcache.h>
21 #include <linux/init.h>
22 #include <linux/module.h>
23 #include <linux/srcu.h>
25 #include <linux/fsnotify_backend.h>
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.
34 void fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is)
36 struct fsnotify_group *group;
37 struct fsnotify_event *event = NULL;
40 if (list_empty(&fsnotify_groups))
43 if (!(mask & fsnotify_mask))
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.
51 idx = srcu_read_lock(&fsnotify_grp_srcu);
52 list_for_each_entry_rcu(group, &fsnotify_groups, group_list) {
53 if (mask & group->mask) {
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
62 group->ops->handle_event(group, event);
65 srcu_read_unlock(&fsnotify_grp_srcu, idx);
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.
71 fsnotify_put_event(event);
73 EXPORT_SYMBOL_GPL(fsnotify);
75 static __init int fsnotify_init(void)
77 return init_srcu_struct(&fsnotify_grp_srcu);
79 subsys_initcall(fsnotify_init);