]>
Commit | Line | Data |
---|---|---|
90586523 EP |
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 | ||
3be25f49 EP |
28 | /* |
29 | * Clear all of the marks on an inode when it is being evicted from core | |
30 | */ | |
31 | void __fsnotify_inode_delete(struct inode *inode) | |
32 | { | |
33 | fsnotify_clear_marks_by_inode(inode); | |
34 | } | |
35 | EXPORT_SYMBOL_GPL(__fsnotify_inode_delete); | |
36 | ||
90586523 EP |
37 | /* |
38 | * This is the main call to fsnotify. The VFS calls into hook specific functions | |
39 | * in linux/fsnotify.h. Those functions then in turn call here. Here will call | |
40 | * out to all of the registered fsnotify_group. Those groups can then use the | |
41 | * notification event in whatever means they feel necessary. | |
42 | */ | |
43 | void fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is) | |
44 | { | |
45 | struct fsnotify_group *group; | |
46 | struct fsnotify_event *event = NULL; | |
47 | int idx; | |
48 | ||
49 | if (list_empty(&fsnotify_groups)) | |
50 | return; | |
51 | ||
52 | if (!(mask & fsnotify_mask)) | |
53 | return; | |
54 | ||
3be25f49 EP |
55 | if (!(mask & to_tell->i_fsnotify_mask)) |
56 | return; | |
90586523 EP |
57 | /* |
58 | * SRCU!! the groups list is very very much read only and the path is | |
59 | * very hot. The VAST majority of events are not going to need to do | |
60 | * anything other than walk the list so it's crazy to pre-allocate. | |
61 | */ | |
62 | idx = srcu_read_lock(&fsnotify_grp_srcu); | |
63 | list_for_each_entry_rcu(group, &fsnotify_groups, group_list) { | |
64 | if (mask & group->mask) { | |
3be25f49 EP |
65 | if (!group->ops->should_send_event(group, to_tell, mask)) |
66 | continue; | |
90586523 EP |
67 | if (!event) { |
68 | event = fsnotify_create_event(to_tell, mask, data, data_is); | |
69 | /* shit, we OOM'd and now we can't tell, maybe | |
70 | * someday someone else will want to do something | |
71 | * here */ | |
72 | if (!event) | |
73 | break; | |
74 | } | |
75 | group->ops->handle_event(group, event); | |
76 | } | |
77 | } | |
78 | srcu_read_unlock(&fsnotify_grp_srcu, idx); | |
79 | /* | |
80 | * fsnotify_create_event() took a reference so the event can't be cleaned | |
81 | * up while we are still trying to add it to lists, drop that one. | |
82 | */ | |
83 | if (event) | |
84 | fsnotify_put_event(event); | |
85 | } | |
86 | EXPORT_SYMBOL_GPL(fsnotify); | |
87 | ||
88 | static __init int fsnotify_init(void) | |
89 | { | |
90 | return init_srcu_struct(&fsnotify_grp_srcu); | |
91 | } | |
92 | subsys_initcall(fsnotify_init); |