1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <linux/fs.h>
20#include <linux/init.h>
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/mount.h>
24#include <linux/mutex.h>
25#include <linux/spinlock.h>
26
27#include <linux/atomic.h>
28
29#include <linux/fsnotify_backend.h>
30#include "fsnotify.h"
31#include "../mount.h"
32
33void fsnotify_clear_marks_by_mount(struct vfsmount *mnt)
34{
35 struct fsnotify_mark *mark;
36 struct hlist_node *n;
37 struct mount *m = real_mount(mnt);
38 LIST_HEAD(free_list);
39
40 spin_lock(&mnt->mnt_root->d_lock);
41 hlist_for_each_entry_safe(mark, n, &m->mnt_fsnotify_marks, obj_list) {
42 list_add(&mark->free_list, &free_list);
43 hlist_del_init_rcu(&mark->obj_list);
44 fsnotify_get_mark(mark);
45 }
46 spin_unlock(&mnt->mnt_root->d_lock);
47
48 fsnotify_destroy_marks(&free_list);
49}
50
51void fsnotify_clear_vfsmount_marks_by_group(struct fsnotify_group *group)
52{
53 fsnotify_clear_marks_by_group_flags(group, FSNOTIFY_MARK_FLAG_VFSMOUNT);
54}
55
56
57
58
59
60void fsnotify_recalc_vfsmount_mask(struct vfsmount *mnt)
61{
62 struct mount *m = real_mount(mnt);
63
64 spin_lock(&mnt->mnt_root->d_lock);
65 m->mnt_fsnotify_mask = fsnotify_recalc_mask(&m->mnt_fsnotify_marks);
66 spin_unlock(&mnt->mnt_root->d_lock);
67}
68
69void fsnotify_destroy_vfsmount_mark(struct fsnotify_mark *mark)
70{
71 struct vfsmount *mnt = mark->mnt;
72 struct mount *m = real_mount(mnt);
73
74 BUG_ON(!mutex_is_locked(&mark->group->mark_mutex));
75 assert_spin_locked(&mark->lock);
76
77 spin_lock(&mnt->mnt_root->d_lock);
78
79 hlist_del_init_rcu(&mark->obj_list);
80 mark->mnt = NULL;
81
82 m->mnt_fsnotify_mask = fsnotify_recalc_mask(&m->mnt_fsnotify_marks);
83 spin_unlock(&mnt->mnt_root->d_lock);
84}
85
86
87
88
89
90struct fsnotify_mark *fsnotify_find_vfsmount_mark(struct fsnotify_group *group,
91 struct vfsmount *mnt)
92{
93 struct mount *m = real_mount(mnt);
94 struct fsnotify_mark *mark;
95
96 spin_lock(&mnt->mnt_root->d_lock);
97 mark = fsnotify_find_mark(&m->mnt_fsnotify_marks, group);
98 spin_unlock(&mnt->mnt_root->d_lock);
99
100 return mark;
101}
102
103
104
105
106
107
108int fsnotify_add_vfsmount_mark(struct fsnotify_mark *mark,
109 struct fsnotify_group *group, struct vfsmount *mnt,
110 int allow_dups)
111{
112 struct mount *m = real_mount(mnt);
113 int ret;
114
115 mark->flags |= FSNOTIFY_MARK_FLAG_VFSMOUNT;
116
117 BUG_ON(!mutex_is_locked(&group->mark_mutex));
118 assert_spin_locked(&mark->lock);
119
120 spin_lock(&mnt->mnt_root->d_lock);
121 mark->mnt = mnt;
122 ret = fsnotify_add_mark_list(&m->mnt_fsnotify_marks, mark, allow_dups);
123 m->mnt_fsnotify_mask = fsnotify_recalc_mask(&m->mnt_fsnotify_marks);
124 spin_unlock(&mnt->mnt_root->d_lock);
125
126 return ret;
127}
128