Skip to content

Commit 5b0457a

Browse files
amir73iljankara
authored andcommitted
fsnotify: remove redundant arguments to handle_event()
inode_mark and vfsmount_mark arguments are passed to handle_event() operation as function arguments as well as on iter_info struct. The difference is that iter_info struct may contain marks that should not be handled and are represented as NULL arguments to inode_mark or vfsmount_mark. Instead of passing the inode_mark and vfsmount_mark arguments, add a report_mask member to iter_info struct to indicate which marks should be handled, versus marks that should only be kept alive during user wait. This change is going to be used for passing more mark types with handle_event() (i.e. super block marks). Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Jan Kara <[email protected]>
1 parent d6f7b98 commit 5b0457a

File tree

11 files changed

+58
-50
lines changed

11 files changed

+58
-50
lines changed

fs/notify/dnotify/dnotify.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,11 @@ static void dnotify_recalc_inode_mask(struct fsnotify_mark *fsn_mark)
7979
*/
8080
static int dnotify_handle_event(struct fsnotify_group *group,
8181
struct inode *inode,
82-
struct fsnotify_mark *inode_mark,
83-
struct fsnotify_mark *vfsmount_mark,
8482
u32 mask, const void *data, int data_type,
8583
const unsigned char *file_name, u32 cookie,
8684
struct fsnotify_iter_info *iter_info)
8785
{
86+
struct fsnotify_mark *inode_mark = fsnotify_iter_inode_mark(iter_info);
8887
struct dnotify_mark *dn_mark;
8988
struct dnotify_struct *dn;
9089
struct dnotify_struct **prev;
@@ -95,7 +94,8 @@ static int dnotify_handle_event(struct fsnotify_group *group,
9594
if (!S_ISDIR(inode->i_mode))
9695
return 0;
9796

98-
BUG_ON(vfsmount_mark);
97+
if (WARN_ON(fsnotify_iter_vfsmount_mark(iter_info)))
98+
return 0;
9999

100100
dn_mark = container_of(inode_mark, struct dnotify_mark, fsn_mark);
101101

fs/notify/fanotify/fanotify.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,12 @@ static int fanotify_get_response(struct fsnotify_group *group,
8787
return ret;
8888
}
8989

90-
static bool fanotify_should_send_event(struct fsnotify_mark *inode_mark,
91-
struct fsnotify_mark *vfsmnt_mark,
92-
u32 event_mask,
93-
const void *data, int data_type)
90+
static bool fanotify_should_send_event(struct fsnotify_iter_info *iter_info,
91+
u32 event_mask, const void *data,
92+
int data_type)
9493
{
94+
struct fsnotify_mark *inode_mark = fsnotify_iter_inode_mark(iter_info);
95+
struct fsnotify_mark *vfsmnt_mark = fsnotify_iter_vfsmount_mark(iter_info);
9596
__u32 marks_mask = 0, marks_ignored_mask = 0;
9697
const struct path *path = data;
9798

@@ -178,8 +179,6 @@ init: __maybe_unused
178179

179180
static int fanotify_handle_event(struct fsnotify_group *group,
180181
struct inode *inode,
181-
struct fsnotify_mark *inode_mark,
182-
struct fsnotify_mark *fanotify_mark,
183182
u32 mask, const void *data, int data_type,
184183
const unsigned char *file_name, u32 cookie,
185184
struct fsnotify_iter_info *iter_info)
@@ -199,8 +198,7 @@ static int fanotify_handle_event(struct fsnotify_group *group,
199198
BUILD_BUG_ON(FAN_ACCESS_PERM != FS_ACCESS_PERM);
200199
BUILD_BUG_ON(FAN_ONDIR != FS_ISDIR);
201200

202-
if (!fanotify_should_send_event(inode_mark, fanotify_mark, mask, data,
203-
data_type))
201+
if (!fanotify_should_send_event(iter_info, mask, data, data_type))
204202
return 0;
205203

206204
pr_debug("%s: group=%p inode=%p mask=%x\n", __func__, group, inode,

fs/notify/fsnotify.c

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -184,22 +184,20 @@ int __fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask
184184
EXPORT_SYMBOL_GPL(__fsnotify_parent);
185185

186186
static int send_to_group(struct inode *to_tell,
187-
struct fsnotify_mark *inode_mark,
188-
struct fsnotify_mark *vfsmount_mark,
189187
__u32 mask, const void *data,
190188
int data_is, u32 cookie,
191189
const unsigned char *file_name,
192190
struct fsnotify_iter_info *iter_info)
193191
{
192+
struct fsnotify_mark *inode_mark = fsnotify_iter_inode_mark(iter_info);
193+
struct fsnotify_mark *vfsmount_mark = fsnotify_iter_vfsmount_mark(iter_info);
194194
struct fsnotify_group *group = NULL;
195195
__u32 test_mask = (mask & ~FS_EVENT_ON_CHILD);
196196
__u32 marks_mask = 0;
197197
__u32 marks_ignored_mask = 0;
198198

199-
if (unlikely(!inode_mark && !vfsmount_mark)) {
200-
BUG();
199+
if (WARN_ON(!iter_info->report_mask))
201200
return 0;
202-
}
203201

204202
/* clear ignored on inode modification */
205203
if (mask & FS_MODIFY) {
@@ -235,8 +233,7 @@ static int send_to_group(struct inode *to_tell,
235233
if (!(test_mask & marks_mask & ~marks_ignored_mask))
236234
return 0;
237235

238-
return group->ops->handle_event(group, to_tell, inode_mark,
239-
vfsmount_mark, mask, data, data_is,
236+
return group->ops->handle_event(group, to_tell, mask, data, data_is,
240237
file_name, cookie, iter_info);
241238
}
242239

@@ -327,27 +324,32 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is,
327324
while (iter_info.inode_mark || iter_info.vfsmount_mark) {
328325
struct fsnotify_mark *inode_mark = iter_info.inode_mark;
329326
struct fsnotify_mark *vfsmount_mark = iter_info.vfsmount_mark;
327+
int cmp;
330328

331329
if (inode_mark && vfsmount_mark) {
332-
int cmp = fsnotify_compare_groups(inode_mark->group,
333-
vfsmount_mark->group);
334-
if (cmp > 0)
335-
inode_mark = NULL;
336-
else if (cmp < 0)
337-
vfsmount_mark = NULL;
330+
cmp = fsnotify_compare_groups(inode_mark->group,
331+
vfsmount_mark->group);
332+
} else {
333+
cmp = inode_mark ? -1 : 1;
338334
}
339335

340-
ret = send_to_group(to_tell, inode_mark, vfsmount_mark, mask,
341-
data, data_is, cookie, file_name,
342-
&iter_info);
336+
iter_info.report_mask = 0;
337+
if (cmp <= 0)
338+
iter_info.report_mask |= FSNOTIFY_OBJ_TYPE_INODE_FL;
339+
if (cmp >= 0)
340+
iter_info.report_mask |= FSNOTIFY_OBJ_TYPE_VFSMOUNT_FL;
341+
342+
ret = send_to_group(to_tell, mask, data, data_is, cookie,
343+
file_name, &iter_info);
343344

344345
if (ret && (mask & ALL_FSNOTIFY_PERM_EVENTS))
345346
goto out;
346347

347-
if (inode_mark)
348+
if (iter_info.report_mask & FSNOTIFY_OBJ_TYPE_INODE_FL)
348349
iter_info.inode_mark =
349350
fsnotify_next_mark(iter_info.inode_mark);
350-
if (vfsmount_mark)
351+
352+
if (iter_info.report_mask & FSNOTIFY_OBJ_TYPE_VFSMOUNT_FL)
351353
iter_info.vfsmount_mark =
352354
fsnotify_next_mark(iter_info.vfsmount_mark);
353355
}

fs/notify/fsnotify.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@
99

1010
#include "../mount.h"
1111

12-
struct fsnotify_iter_info {
13-
struct fsnotify_mark *inode_mark;
14-
struct fsnotify_mark *vfsmount_mark;
15-
int srcu_idx;
16-
};
17-
1812
/* destroy all events sitting in this groups notification queue */
1913
extern void fsnotify_flush_notify(struct fsnotify_group *group);
2014

fs/notify/inotify/inotify.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ extern void inotify_ignored_and_remove_idr(struct fsnotify_mark *fsn_mark,
2525
struct fsnotify_group *group);
2626
extern int inotify_handle_event(struct fsnotify_group *group,
2727
struct inode *inode,
28-
struct fsnotify_mark *inode_mark,
29-
struct fsnotify_mark *vfsmount_mark,
3028
u32 mask, const void *data, int data_type,
3129
const unsigned char *file_name, u32 cookie,
3230
struct fsnotify_iter_info *iter_info);

fs/notify/inotify/inotify_fsnotify.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,20 @@ static int inotify_merge(struct list_head *list,
6565

6666
int inotify_handle_event(struct fsnotify_group *group,
6767
struct inode *inode,
68-
struct fsnotify_mark *inode_mark,
69-
struct fsnotify_mark *vfsmount_mark,
7068
u32 mask, const void *data, int data_type,
7169
const unsigned char *file_name, u32 cookie,
7270
struct fsnotify_iter_info *iter_info)
7371
{
72+
struct fsnotify_mark *inode_mark = fsnotify_iter_inode_mark(iter_info);
7473
struct inotify_inode_mark *i_mark;
7574
struct inotify_event_info *event;
7675
struct fsnotify_event *fsn_event;
7776
int ret;
7877
int len = 0;
7978
int alloc_len = sizeof(struct inotify_event_info);
8079

81-
BUG_ON(vfsmount_mark);
80+
if (WARN_ON(fsnotify_iter_vfsmount_mark(iter_info)))
81+
return 0;
8282

8383
if ((inode_mark->mask & FS_EXCL_UNLINK) &&
8484
(data_type == FSNOTIFY_EVENT_PATH)) {

fs/notify/inotify/inotify_user.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,14 @@ void inotify_ignored_and_remove_idr(struct fsnotify_mark *fsn_mark,
485485
struct fsnotify_group *group)
486486
{
487487
struct inotify_inode_mark *i_mark;
488+
struct fsnotify_iter_info iter_info = {
489+
.inode_mark = fsn_mark,
490+
.report_mask = FSNOTIFY_OBJ_TYPE_INODE_FL,
491+
};
488492

489493
/* Queue ignore event for the watch */
490-
inotify_handle_event(group, NULL, fsn_mark, NULL, FS_IN_IGNORED,
491-
NULL, FSNOTIFY_EVENT_NONE, NULL, 0, NULL);
494+
inotify_handle_event(group, NULL, FS_IN_IGNORED, NULL,
495+
FSNOTIFY_EVENT_NONE, NULL, 0, &iter_info);
492496

493497
i_mark = container_of(fsn_mark, struct inotify_inode_mark, fsn_mark);
494498
/* remove this mark from the idr */

include/linux/fsnotify_backend.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ struct fsnotify_iter_info;
9898
struct fsnotify_ops {
9999
int (*handle_event)(struct fsnotify_group *group,
100100
struct inode *inode,
101-
struct fsnotify_mark *inode_mark,
102-
struct fsnotify_mark *vfsmount_mark,
103101
u32 mask, const void *data, int data_type,
104102
const unsigned char *file_name, u32 cookie,
105103
struct fsnotify_iter_info *iter_info);
@@ -212,6 +210,24 @@ enum fsnotify_obj_type {
212210
#define FSNOTIFY_OBJ_TYPE_VFSMOUNT_FL (1U << FSNOTIFY_OBJ_TYPE_VFSMOUNT)
213211
#define FSNOTIFY_OBJ_ALL_TYPES_MASK ((1U << FSNOTIFY_OBJ_TYPE_COUNT) - 1)
214212

213+
struct fsnotify_iter_info {
214+
struct fsnotify_mark *inode_mark;
215+
struct fsnotify_mark *vfsmount_mark;
216+
unsigned int report_mask;
217+
int srcu_idx;
218+
};
219+
220+
#define FSNOTIFY_ITER_FUNCS(name, NAME) \
221+
static inline struct fsnotify_mark *fsnotify_iter_##name##_mark( \
222+
struct fsnotify_iter_info *iter_info) \
223+
{ \
224+
return (iter_info->report_mask & FSNOTIFY_OBJ_TYPE_##NAME##_FL) ? \
225+
iter_info->name##_mark : NULL; \
226+
}
227+
228+
FSNOTIFY_ITER_FUNCS(inode, INODE)
229+
FSNOTIFY_ITER_FUNCS(vfsmount, VFSMOUNT)
230+
215231
/*
216232
* Inode / vfsmount point to this structure which tracks all marks attached to
217233
* the inode / vfsmount. The reference to inode / vfsmount is held by this

kernel/audit_fsnotify.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,11 @@ static void audit_autoremove_mark_rule(struct audit_fsnotify_mark *audit_mark)
165165
/* Update mark data in audit rules based on fsnotify events. */
166166
static int audit_mark_handle_event(struct fsnotify_group *group,
167167
struct inode *to_tell,
168-
struct fsnotify_mark *inode_mark,
169-
struct fsnotify_mark *vfsmount_mark,
170168
u32 mask, const void *data, int data_type,
171169
const unsigned char *dname, u32 cookie,
172170
struct fsnotify_iter_info *iter_info)
173171
{
172+
struct fsnotify_mark *inode_mark = fsnotify_iter_inode_mark(iter_info);
174173
struct audit_fsnotify_mark *audit_mark;
175174
const struct inode *inode = NULL;
176175

kernel/audit_tree.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,8 +989,6 @@ static void evict_chunk(struct audit_chunk *chunk)
989989

990990
static int audit_tree_handle_event(struct fsnotify_group *group,
991991
struct inode *to_tell,
992-
struct fsnotify_mark *inode_mark,
993-
struct fsnotify_mark *vfsmount_mark,
994992
u32 mask, const void *data, int data_type,
995993
const unsigned char *file_name, u32 cookie,
996994
struct fsnotify_iter_info *iter_info)

kernel/audit_watch.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,12 +472,11 @@ void audit_remove_watch_rule(struct audit_krule *krule)
472472
/* Update watch data in audit rules based on fsnotify events. */
473473
static int audit_watch_handle_event(struct fsnotify_group *group,
474474
struct inode *to_tell,
475-
struct fsnotify_mark *inode_mark,
476-
struct fsnotify_mark *vfsmount_mark,
477475
u32 mask, const void *data, int data_type,
478476
const unsigned char *dname, u32 cookie,
479477
struct fsnotify_iter_info *iter_info)
480478
{
479+
struct fsnotify_mark *inode_mark = fsnotify_iter_inode_mark(iter_info);
481480
const struct inode *inode;
482481
struct audit_parent *parent;
483482

0 commit comments

Comments
 (0)