Skip to content

Commit 1968f5e

Browse files
committed
fanotify: use both marks when possible
fanotify currently, when given a vfsmount_mark will look up (if it exists) the corresponding inode mark. This patch drops that lookup and uses the mark provided. Signed-off-by: Eric Paris <eparis@redhat.com>
1 parent ce8f76f commit 1968f5e

7 files changed

Lines changed: 41 additions & 61 deletions

File tree

‎fs/notify/dnotify/dnotify.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static int dnotify_handle_event(struct fsnotify_group *group,
128128
* userspace notification for that pair.
129129
*/
130130
static bool dnotify_should_send_event(struct fsnotify_group *group,
131-
struct inode *inode, struct vfsmount *mnt,
131+
struct inode *inode,
132132
struct fsnotify_mark *inode_mark,
133133
struct fsnotify_mark *vfsmount_mark,
134134
__u32 mask, void *data, int data_type)

‎fs/notify/fanotify/fanotify.c‎

Lines changed: 34 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -153,59 +153,20 @@ static int fanotify_handle_event(struct fsnotify_group *group,
153153
return ret;
154154
}
155155

156-
static bool should_send_vfsmount_event(struct fsnotify_group *group,
157-
struct vfsmount *mnt,
158-
struct inode *inode,
159-
struct fsnotify_mark *mnt_mark,
160-
__u32 mask)
161-
{
162-
struct fsnotify_mark *inode_mark;
163-
164-
pr_debug("%s: group=%p vfsmount=%p mark=%p mask=%x\n",
165-
__func__, group, mnt, mnt_mark, mask);
166-
167-
mask &= mnt_mark->mask;
168-
mask &= ~mnt_mark->ignored_mask;
169-
170-
if (mask) {
171-
inode_mark = fsnotify_find_inode_mark(group, inode);
172-
if (inode_mark) {
173-
mask &= ~inode_mark->ignored_mask;
174-
fsnotify_put_mark(inode_mark);
175-
}
176-
}
177-
178-
return mask;
179-
}
180-
181-
static bool should_send_inode_event(struct fsnotify_group *group,
182-
struct inode *inode,
183-
struct fsnotify_mark *mark,
184-
__u32 mask)
185-
{
186-
pr_debug("%s: group=%p inode=%p mark=%p mask=%x\n",
187-
__func__, group, inode, mark, mask);
188-
189-
/*
190-
* if the event is for a child and this inode doesn't care about
191-
* events on the child, don't send it!
192-
*/
193-
if ((mask & FS_EVENT_ON_CHILD) &&
194-
!(mark->mask & FS_EVENT_ON_CHILD))
195-
return false;
196-
else
197-
return true;
198-
}
199-
200156
static bool fanotify_should_send_event(struct fsnotify_group *group,
201157
struct inode *to_tell,
202-
struct vfsmount *mnt,
203158
struct fsnotify_mark *inode_mark,
204-
struct fsnotify_mark *vfsmount_mark,
205-
__u32 mask, void *data, int data_type)
159+
struct fsnotify_mark *vfsmnt_mark,
160+
__u32 event_mask, void *data, int data_type)
206161
{
207-
pr_debug("%s: group=%p to_tell=%p mnt=%p mask=%x data=%p data_type=%d\n",
208-
__func__, group, to_tell, mnt, mask, data, data_type);
162+
__u32 marks_mask, marks_ignored_mask;
163+
164+
pr_debug("%s: group=%p to_tell=%p inode_mark=%p vfsmnt_mark=%p "
165+
"mask=%x data=%p data_type=%d\n", __func__, group, to_tell,
166+
inode_mark, vfsmnt_mark, event_mask, data, data_type);
167+
168+
pr_debug("%s: group=%p vfsmount_mark=%p inode_mark=%p mask=%x\n",
169+
__func__, group, vfsmnt_mark, inode_mark, event_mask);
209170

210171
/* sorry, fanotify only gives a damn about files and dirs */
211172
if (!S_ISREG(to_tell->i_mode) &&
@@ -216,11 +177,30 @@ static bool fanotify_should_send_event(struct fsnotify_group *group,
216177
if (data_type != FSNOTIFY_EVENT_FILE)
217178
return false;
218179

219-
if (mnt)
220-
return should_send_vfsmount_event(group, mnt, to_tell,
221-
vfsmount_mark, mask);
222-
else
223-
return should_send_inode_event(group, to_tell, inode_mark, mask);
180+
if (inode_mark && vfsmnt_mark) {
181+
marks_mask = (vfsmnt_mark->mask | inode_mark->mask);
182+
marks_ignored_mask = (vfsmnt_mark->ignored_mask | inode_mark->ignored_mask);
183+
} else if (inode_mark) {
184+
/*
185+
* if the event is for a child and this inode doesn't care about
186+
* events on the child, don't send it!
187+
*/
188+
if ((event_mask & FS_EVENT_ON_CHILD) &&
189+
!(inode_mark->mask & FS_EVENT_ON_CHILD))
190+
return false;
191+
marks_mask = inode_mark->mask;
192+
marks_ignored_mask = inode_mark->ignored_mask;
193+
} else if (vfsmnt_mark) {
194+
marks_mask = vfsmnt_mark->mask;
195+
marks_ignored_mask = vfsmnt_mark->ignored_mask;
196+
} else {
197+
BUG();
198+
}
199+
200+
if (event_mask & marks_mask & ~marks_ignored_mask)
201+
return true;
202+
203+
return false;
224204
}
225205

226206
const struct fsnotify_ops fanotify_fsnotify_ops = {

‎fs/notify/fsnotify.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static int send_to_group(struct inode *to_tell, struct vfsmount *mnt,
183183
if (!inode_test_mask && !vfsmount_test_mask)
184184
return 0;
185185

186-
if (group->ops->should_send_event(group, to_tell, mnt, inode_mark,
186+
if (group->ops->should_send_event(group, to_tell, inode_mark,
187187
vfsmount_mark, mask, data,
188188
data_is) == false)
189189
return 0;

‎fs/notify/inotify/inotify_fsnotify.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,11 @@ static void inotify_freeing_mark(struct fsnotify_mark *fsn_mark, struct fsnotify
142142
}
143143

144144
static bool inotify_should_send_event(struct fsnotify_group *group, struct inode *inode,
145-
struct vfsmount *mnt, struct fsnotify_mark *mark,
145+
struct fsnotify_mark *inode_mark,
146146
struct fsnotify_mark *vfsmount_mark,
147147
__u32 mask, void *data, int data_type)
148148
{
149-
if ((mark->mask & FS_EXCL_UNLINK) &&
149+
if ((inode_mark->mask & FS_EXCL_UNLINK) &&
150150
(data_type == FSNOTIFY_EVENT_FILE)) {
151151
struct file *file = data;
152152

‎include/linux/fsnotify_backend.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ 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 *inode_mark,
95+
struct fsnotify_mark *inode_mark,
9696
struct fsnotify_mark *vfsmount_mark,
9797
__u32 mask, void *data, int data_type);
9898
int (*handle_event)(struct fsnotify_group *group,

‎kernel/audit_tree.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ static void audit_tree_freeing_mark(struct fsnotify_mark *entry, struct fsnotify
921921
}
922922

923923
static bool audit_tree_send_event(struct fsnotify_group *group, struct inode *inode,
924-
struct vfsmount *mnt, struct fsnotify_mark *inode_mark,
924+
struct fsnotify_mark *inode_mark,
925925
struct fsnotify_mark *vfsmount_mark,
926926
__u32 mask, void *data, int data_type)
927927
{

‎kernel/audit_watch.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ 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 *inode_mark,
506+
struct fsnotify_mark *inode_mark,
507507
struct fsnotify_mark *vfsmount_mark,
508508
__u32 mask, void *data, int data_type)
509509
{

0 commit comments

Comments
 (0)