Skip to content

Commit ce8f76f

Browse files
committed
fsnotify: pass both the vfsmount mark and inode mark
should_send_event() and handle_event() will both need to look up the inode event if they get a vfsmount event. Lets just pass both at the same time since we have them both after walking the lists in lockstep. Signed-off-by: Eric Paris <eparis@redhat.com>
1 parent 613a807 commit ce8f76f

7 files changed

Lines changed: 91 additions & 45 deletions

File tree

‎fs/notify/dnotify/dnotify.c‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ static void dnotify_recalc_inode_mask(struct fsnotify_mark *fsn_mark)
8383
* events.
8484
*/
8585
static int dnotify_handle_event(struct fsnotify_group *group,
86-
struct fsnotify_mark *mark,
86+
struct fsnotify_mark *inode_mark,
87+
struct fsnotify_mark *vfsmount_mark,
8788
struct fsnotify_event *event)
8889
{
8990
struct dnotify_mark *dn_mark;
@@ -93,11 +94,13 @@ static int dnotify_handle_event(struct fsnotify_group *group,
9394
struct fown_struct *fown;
9495
__u32 test_mask = event->mask & ~FS_EVENT_ON_CHILD;
9596

97+
BUG_ON(vfsmount_mark);
98+
9699
to_tell = event->to_tell;
97100

98-
dn_mark = container_of(mark, struct dnotify_mark, fsn_mark);
101+
dn_mark = container_of(inode_mark, struct dnotify_mark, fsn_mark);
99102

100-
spin_lock(&mark->lock);
103+
spin_lock(&inode_mark->lock);
101104
prev = &dn_mark->dn;
102105
while ((dn = *prev) != NULL) {
103106
if ((dn->dn_mask & test_mask) == 0) {
@@ -111,11 +114,11 @@ static int dnotify_handle_event(struct fsnotify_group *group,
111114
else {
112115
*prev = dn->dn_next;
113116
kmem_cache_free(dnotify_struct_cache, dn);
114-
dnotify_recalc_inode_mask(mark);
117+
dnotify_recalc_inode_mask(inode_mark);
115118
}
116119
}
117120

118-
spin_unlock(&mark->lock);
121+
spin_unlock(&inode_mark->lock);
119122

120123
return 0;
121124
}
@@ -126,8 +129,9 @@ static int dnotify_handle_event(struct fsnotify_group *group,
126129
*/
127130
static bool dnotify_should_send_event(struct fsnotify_group *group,
128131
struct inode *inode, struct vfsmount *mnt,
129-
struct fsnotify_mark *mark, __u32 mask,
130-
void *data, int data_type)
132+
struct fsnotify_mark *inode_mark,
133+
struct fsnotify_mark *vfsmount_mark,
134+
__u32 mask, void *data, int data_type)
131135
{
132136
/* not a dir, dnotify doesn't care */
133137
if (!S_ISDIR(inode->i_mode))

‎fs/notify/fanotify/fanotify.c‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ static int fanotify_get_response_from_access(struct fsnotify_group *group,
115115
#endif
116116

117117
static int fanotify_handle_event(struct fsnotify_group *group,
118-
struct fsnotify_mark *mark,
118+
struct fsnotify_mark *inode_mark,
119+
struct fsnotify_mark *fanotify_mark,
119120
struct fsnotify_event *event)
120121
{
121122
int ret = 0;
@@ -196,8 +197,11 @@ static bool should_send_inode_event(struct fsnotify_group *group,
196197
return true;
197198
}
198199

199-
static bool fanotify_should_send_event(struct fsnotify_group *group, struct inode *to_tell,
200-
struct vfsmount *mnt, struct fsnotify_mark *mark,
200+
static bool fanotify_should_send_event(struct fsnotify_group *group,
201+
struct inode *to_tell,
202+
struct vfsmount *mnt,
203+
struct fsnotify_mark *inode_mark,
204+
struct fsnotify_mark *vfsmount_mark,
201205
__u32 mask, void *data, int data_type)
202206
{
203207
pr_debug("%s: group=%p to_tell=%p mnt=%p mask=%x data=%p data_type=%d\n",
@@ -213,9 +217,10 @@ static bool fanotify_should_send_event(struct fsnotify_group *group, struct inod
213217
return false;
214218

215219
if (mnt)
216-
return should_send_vfsmount_event(group, mnt, to_tell, mark, mask);
220+
return should_send_vfsmount_event(group, mnt, to_tell,
221+
vfsmount_mark, mask);
217222
else
218-
return should_send_inode_event(group, to_tell, mark, mask);
223+
return should_send_inode_event(group, to_tell, inode_mark, mask);
219224
}
220225

221226
const struct fsnotify_ops fanotify_fsnotify_ops = {

‎fs/notify/fsnotify.c‎

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -141,28 +141,51 @@ void __fsnotify_parent(struct file *file, struct dentry *dentry, __u32 mask)
141141
EXPORT_SYMBOL_GPL(__fsnotify_parent);
142142

143143
static int send_to_group(struct inode *to_tell, struct vfsmount *mnt,
144-
struct fsnotify_mark *mark,
145-
__u32 mask, void *data,
144+
struct fsnotify_mark *inode_mark,
145+
struct fsnotify_mark *vfsmount_mark,
146+
__u32 mask, void *data,
146147
int data_is, u32 cookie,
147148
const unsigned char *file_name,
148149
struct fsnotify_event **event)
149150
{
150-
struct fsnotify_group *group = mark->group;
151-
__u32 test_mask = (mask & ~FS_EVENT_ON_CHILD);
151+
struct fsnotify_group *group = inode_mark->group;
152+
__u32 inode_test_mask = (mask & ~FS_EVENT_ON_CHILD);
153+
__u32 vfsmount_test_mask = (mask & ~FS_EVENT_ON_CHILD);
152154

153155
pr_debug("%s: group=%p to_tell=%p mnt=%p mark=%p mask=%x data=%p"
154156
" data_is=%d cookie=%d event=%p\n", __func__, group, to_tell,
155-
mnt, mark, mask, data, data_is, cookie, *event);
157+
mnt, inode_mark, mask, data, data_is, cookie, *event);
158+
159+
/* clear ignored on inode modification */
160+
if (mask & FS_MODIFY) {
161+
if (inode_mark &&
162+
!(inode_mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY))
163+
inode_mark->ignored_mask = 0;
164+
if (vfsmount_mark &&
165+
!(vfsmount_mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY))
166+
vfsmount_mark->ignored_mask = 0;
167+
}
156168

157-
if ((mask & FS_MODIFY) &&
158-
!(mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY))
159-
mark->ignored_mask = 0;
169+
/* does the inode mark tell us to do something? */
170+
if (inode_mark) {
171+
inode_test_mask &= inode_mark->mask;
172+
inode_test_mask &= ~inode_mark->ignored_mask;
173+
}
160174

161-
if (!(test_mask & mark->mask & ~mark->ignored_mask))
175+
/* does the vfsmount_mark tell us to do something? */
176+
if (vfsmount_mark) {
177+
vfsmount_test_mask &= vfsmount_mark->mask;
178+
vfsmount_test_mask &= ~vfsmount_mark->ignored_mask;
179+
if (inode_mark)
180+
vfsmount_test_mask &= ~inode_mark->ignored_mask;
181+
}
182+
183+
if (!inode_test_mask && !vfsmount_test_mask)
162184
return 0;
163185

164-
if (group->ops->should_send_event(group, to_tell, mnt, mark, mask,
165-
data, data_is) == false)
186+
if (group->ops->should_send_event(group, to_tell, mnt, inode_mark,
187+
vfsmount_mark, mask, data,
188+
data_is) == false)
166189
return 0;
167190

168191
if (!*event) {
@@ -172,7 +195,7 @@ static int send_to_group(struct inode *to_tell, struct vfsmount *mnt,
172195
if (!*event)
173196
return -ENOMEM;
174197
}
175-
return group->ops->handle_event(group, mark, *event);
198+
return group->ops->handle_event(group, inode_mark, vfsmount_mark, *event);
176199
}
177200

178201
/*
@@ -213,14 +236,16 @@ int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,
213236

214237
if ((mask & FS_MODIFY) ||
215238
(test_mask & to_tell->i_fsnotify_mask))
216-
inode_node = to_tell->i_fsnotify_marks.first;
239+
inode_node = srcu_dereference(to_tell->i_fsnotify_marks.first,
240+
&fsnotify_mark_srcu);
217241
else
218242
inode_node = NULL;
219243

220244
if (mnt) {
221245
if ((mask & FS_MODIFY) ||
222246
(test_mask & mnt->mnt_fsnotify_mask))
223-
vfsmount_node = mnt->mnt_fsnotify_marks.first;
247+
vfsmount_node = srcu_dereference(mnt->mnt_fsnotify_marks.first,
248+
&fsnotify_mark_srcu);
224249
else
225250
vfsmount_node = NULL;
226251
} else {
@@ -245,26 +270,27 @@ int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,
245270

246271
if (inode_group < vfsmount_group) {
247272
/* handle inode */
248-
send_to_group(to_tell, NULL, inode_mark, mask, data,
273+
send_to_group(to_tell, NULL, inode_mark, NULL, mask, data,
249274
data_is, cookie, file_name, &event);
250275
used_inode = true;
251276
} else if (vfsmount_group < inode_group) {
252-
send_to_group(to_tell, mnt, vfsmount_mark, mask, data,
277+
send_to_group(to_tell, mnt, NULL, vfsmount_mark, mask, data,
253278
data_is, cookie, file_name, &event);
254279
used_vfsmount = true;
255280
} else {
256-
send_to_group(to_tell, mnt, vfsmount_mark, mask, data,
257-
data_is, cookie, file_name, &event);
281+
send_to_group(to_tell, mnt, inode_mark, vfsmount_mark,
282+
mask, data, data_is, cookie, file_name,
283+
&event);
258284
used_vfsmount = true;
259-
send_to_group(to_tell, NULL, inode_mark, mask, data,
260-
data_is, cookie, file_name, &event);
261285
used_inode = true;
262286
}
263287

264288
if (used_inode)
265-
inode_node = inode_node->next;
289+
inode_node = srcu_dereference(inode_node->next,
290+
&fsnotify_mark_srcu);
266291
if (used_vfsmount)
267-
vfsmount_node = vfsmount_node->next;
292+
vfsmount_node = srcu_dereference(vfsmount_node->next,
293+
&fsnotify_mark_srcu);
268294
}
269295

270296
srcu_read_unlock(&fsnotify_mark_srcu, idx);

‎fs/notify/inotify/inotify_fsnotify.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ static struct fsnotify_event *inotify_merge(struct list_head *list,
9090
}
9191

9292
static int inotify_handle_event(struct fsnotify_group *group,
93-
struct fsnotify_mark *mark,
93+
struct fsnotify_mark *inode_mark,
94+
struct fsnotify_mark *vfsmount_mark,
9495
struct fsnotify_event *event)
9596
{
9697
struct inotify_inode_mark *i_mark;
@@ -100,12 +101,14 @@ static int inotify_handle_event(struct fsnotify_group *group,
100101
struct fsnotify_event *added_event;
101102
int wd, ret = 0;
102103

104+
BUG_ON(vfsmount_mark);
105+
103106
pr_debug("%s: group=%p event=%p to_tell=%p mask=%x\n", __func__, group,
104107
event, event->to_tell, event->mask);
105108

106109
to_tell = event->to_tell;
107110

108-
i_mark = container_of(mark, struct inotify_inode_mark,
111+
i_mark = container_of(inode_mark, struct inotify_inode_mark,
109112
fsn_mark);
110113
wd = i_mark->wd;
111114

@@ -127,8 +130,8 @@ static int inotify_handle_event(struct fsnotify_group *group,
127130
ret = PTR_ERR(added_event);
128131
}
129132

130-
if (mark->mask & IN_ONESHOT)
131-
fsnotify_destroy_mark(mark);
133+
if (inode_mark->mask & IN_ONESHOT)
134+
fsnotify_destroy_mark(inode_mark);
132135

133136
return ret;
134137
}
@@ -140,6 +143,7 @@ static void inotify_freeing_mark(struct fsnotify_mark *fsn_mark, struct fsnotify
140143

141144
static bool inotify_should_send_event(struct fsnotify_group *group, struct inode *inode,
142145
struct vfsmount *mnt, struct fsnotify_mark *mark,
146+
struct fsnotify_mark *vfsmount_mark,
143147
__u32 mask, void *data, int data_type)
144148
{
145149
if ((mark->mask & FS_EXCL_UNLINK) &&

‎include/linux/fsnotify_backend.h‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,12 @@ struct fsnotify_event_private_data;
9292
*/
9393
struct fsnotify_ops {
9494
bool (*should_send_event)(struct fsnotify_group *group, struct inode *inode,
95-
struct vfsmount *mnt, struct fsnotify_mark *mark,
95+
struct vfsmount *mnt, struct fsnotify_mark *inode_mark,
96+
struct fsnotify_mark *vfsmount_mark,
9697
__u32 mask, void *data, int data_type);
97-
int (*handle_event)(struct fsnotify_group *group, struct fsnotify_mark *mark,
98+
int (*handle_event)(struct fsnotify_group *group,
99+
struct fsnotify_mark *inode_mark,
100+
struct fsnotify_mark *vfsmount_mark,
98101
struct fsnotify_event *event);
99102
void (*free_group_priv)(struct fsnotify_group *group);
100103
void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);

‎kernel/audit_tree.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,8 @@ static void evict_chunk(struct audit_chunk *chunk)
904904
}
905905

906906
static int audit_tree_handle_event(struct fsnotify_group *group,
907-
struct fsnotify_mark *mark,
907+
struct fsnotify_mark *inode_mark,
908+
struct fsnotify_mark *vfsmonut_mark,
908909
struct fsnotify_event *event)
909910
{
910911
BUG();
@@ -920,7 +921,8 @@ static void audit_tree_freeing_mark(struct fsnotify_mark *entry, struct fsnotify
920921
}
921922

922923
static bool audit_tree_send_event(struct fsnotify_group *group, struct inode *inode,
923-
struct vfsmount *mnt, struct fsnotify_mark *mark,
924+
struct vfsmount *mnt, struct fsnotify_mark *inode_mark,
925+
struct fsnotify_mark *vfsmount_mark,
924926
__u32 mask, void *data, int data_type)
925927
{
926928
return false;

‎kernel/audit_watch.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,23 +503,25 @@ void audit_remove_watch_rule(struct audit_krule *krule)
503503
}
504504

505505
static bool audit_watch_should_send_event(struct fsnotify_group *group, struct inode *inode,
506-
struct vfsmount *mnt, struct fsnotify_mark *mark,
506+
struct vfsmount *mnt, struct fsnotify_mark *inode_mark,
507+
struct fsnotify_mark *vfsmount_mark,
507508
__u32 mask, void *data, int data_type)
508509
{
509510
return true;
510511
}
511512

512513
/* Update watch data in audit rules based on fsnotify events. */
513514
static int audit_watch_handle_event(struct fsnotify_group *group,
514-
struct fsnotify_mark *mark,
515+
struct fsnotify_mark *inode_mark,
516+
struct fsnotify_mark *vfsmount_mark,
515517
struct fsnotify_event *event)
516518
{
517519
struct inode *inode;
518520
__u32 mask = event->mask;
519521
const char *dname = event->file_name;
520522
struct audit_parent *parent;
521523

522-
parent = container_of(mark, struct audit_parent, mark);
524+
parent = container_of(inode_mark, struct audit_parent, mark);
523525

524526
BUG_ON(group != audit_watch_group);
525527

0 commit comments

Comments
 (0)