Skip to content

Commit a0a92d2

Browse files
amir73iljankara
authored andcommitted
fsnotify: move mask out of struct fsnotify_event
Common fsnotify_event helpers have no need for the mask field. It is only used by backend code, so move the field out of the abstract fsnotify_event struct and into the concrete backend event structs. This change packs struct inotify_event_info better on 64bit machine and will allow us to cram some more fields into struct fanotify_event_info. Signed-off-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz>
1 parent 45a9fb3 commit a0a92d2

File tree

8 files changed

+29
-40
lines changed

8 files changed

+29
-40
lines changed

fs/notify/fanotify/fanotify.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,22 @@ static bool should_merge(struct fsnotify_event *old_fsn,
3636
static int fanotify_merge(struct list_head *list, struct fsnotify_event *event)
3737
{
3838
struct fsnotify_event *test_event;
39+
struct fanotify_event_info *new;
3940

4041
pr_debug("%s: list=%p event=%p\n", __func__, list, event);
42+
new = FANOTIFY_E(event);
4143

4244
/*
4345
* Don't merge a permission event with any other event so that we know
4446
* the event structure we have created in fanotify_handle_event() is the
4547
* one we should check for permission response.
4648
*/
47-
if (fanotify_is_perm_event(event->mask))
49+
if (fanotify_is_perm_event(new->mask))
4850
return 0;
4951

5052
list_for_each_entry_reverse(test_event, list, list) {
5153
if (should_merge(test_event, event)) {
52-
test_event->mask |= event->mask;
54+
FANOTIFY_E(test_event)->mask |= new->mask;
5355
return 1;
5456
}
5557
}
@@ -173,7 +175,8 @@ struct fanotify_event_info *fanotify_alloc_event(struct fsnotify_group *group,
173175
if (!event)
174176
goto out;
175177
init: __maybe_unused
176-
fsnotify_init_event(&event->fse, inode, mask);
178+
fsnotify_init_event(&event->fse, inode);
179+
event->mask = mask;
177180
if (FAN_GROUP_FLAG(group, FAN_REPORT_TID))
178181
event->pid = get_pid(task_pid(current));
179182
else
@@ -280,7 +283,7 @@ static void fanotify_free_event(struct fsnotify_event *fsn_event)
280283
event = FANOTIFY_E(fsn_event);
281284
path_put(&event->path);
282285
put_pid(event->pid);
283-
if (fanotify_is_perm_event(fsn_event->mask)) {
286+
if (fanotify_is_perm_event(event->mask)) {
284287
kmem_cache_free(fanotify_perm_event_cachep,
285288
FANOTIFY_PE(fsn_event));
286289
return;

fs/notify/fanotify/fanotify.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ extern struct kmem_cache *fanotify_perm_event_cachep;
1414
*/
1515
struct fanotify_event_info {
1616
struct fsnotify_event fse;
17+
u32 mask;
1718
/*
1819
* We hold ref to this path so it may be dereferenced at any point
1920
* during this object's lifetime

fs/notify/fanotify/fanotify_user.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ static int fill_event_metadata(struct fsnotify_group *group,
131131
metadata->metadata_len = FAN_EVENT_METADATA_LEN;
132132
metadata->vers = FANOTIFY_METADATA_VERSION;
133133
metadata->reserved = 0;
134-
metadata->mask = fsn_event->mask & FANOTIFY_OUTGOING_EVENTS;
134+
metadata->mask = event->mask & FANOTIFY_OUTGOING_EVENTS;
135135
metadata->pid = pid_vnr(event->pid);
136-
if (unlikely(fsn_event->mask & FAN_Q_OVERFLOW))
136+
if (unlikely(event->mask & FAN_Q_OVERFLOW))
137137
metadata->fd = FAN_NOFD;
138138
else {
139139
metadata->fd = create_fd(group, event, file);
@@ -230,7 +230,7 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
230230
fanotify_event_metadata.event_len))
231231
goto out_close_fd;
232232

233-
if (fanotify_is_perm_event(event->mask))
233+
if (fanotify_is_perm_event(FANOTIFY_E(event)->mask))
234234
FANOTIFY_PE(event)->fd = fd;
235235

236236
if (fd != FAN_NOFD)
@@ -316,7 +316,7 @@ static ssize_t fanotify_read(struct file *file, char __user *buf,
316316
* Permission events get queued to wait for response. Other
317317
* events can be destroyed now.
318318
*/
319-
if (!fanotify_is_perm_event(kevent->mask)) {
319+
if (!fanotify_is_perm_event(FANOTIFY_E(kevent)->mask)) {
320320
fsnotify_destroy_event(group, kevent);
321321
} else {
322322
if (ret <= 0) {
@@ -401,7 +401,7 @@ static int fanotify_release(struct inode *ignored, struct file *file)
401401
*/
402402
while (!fsnotify_notify_queue_is_empty(group)) {
403403
fsn_event = fsnotify_remove_first_event(group);
404-
if (!(fsn_event->mask & FANOTIFY_PERM_EVENTS)) {
404+
if (!(FANOTIFY_E(fsn_event)->mask & FANOTIFY_PERM_EVENTS)) {
405405
spin_unlock(&group->notification_lock);
406406
fsnotify_destroy_event(group, fsn_event);
407407
spin_lock(&group->notification_lock);

fs/notify/inotify/inotify.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
struct inotify_event_info {
77
struct fsnotify_event fse;
8+
u32 mask;
89
int wd;
910
u32 sync_cookie;
1011
int name_len;

fs/notify/inotify/inotify_fsnotify.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ static bool event_compare(struct fsnotify_event *old_fsn,
4343
{
4444
struct inotify_event_info *old, *new;
4545

46-
if (old_fsn->mask & FS_IN_IGNORED)
47-
return false;
4846
old = INOTIFY_E(old_fsn);
4947
new = INOTIFY_E(new_fsn);
50-
if ((old_fsn->mask == new_fsn->mask) &&
48+
if (old->mask & FS_IN_IGNORED)
49+
return false;
50+
if ((old->mask == new->mask) &&
5151
(old_fsn->inode == new_fsn->inode) &&
5252
(old->name_len == new->name_len) &&
5353
(!old->name_len || !strcmp(old->name, new->name)))
@@ -114,7 +114,8 @@ int inotify_handle_event(struct fsnotify_group *group,
114114
}
115115

116116
fsn_event = &event->fse;
117-
fsnotify_init_event(fsn_event, inode, mask);
117+
fsnotify_init_event(fsn_event, inode);
118+
event->mask = mask;
118119
event->wd = i_mark->wd;
119120
event->sync_cookie = cookie;
120121
event->name_len = len;

fs/notify/inotify/inotify_user.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
189189
*/
190190
pad_name_len = round_event_name_len(fsn_event);
191191
inotify_event.len = pad_name_len;
192-
inotify_event.mask = inotify_mask_to_arg(fsn_event->mask);
192+
inotify_event.mask = inotify_mask_to_arg(event->mask);
193193
inotify_event.wd = event->wd;
194194
inotify_event.cookie = event->sync_cookie;
195195

@@ -634,7 +634,8 @@ static struct fsnotify_group *inotify_new_group(unsigned int max_events)
634634
return ERR_PTR(-ENOMEM);
635635
}
636636
group->overflow_event = &oevent->fse;
637-
fsnotify_init_event(group->overflow_event, NULL, FS_Q_OVERFLOW);
637+
fsnotify_init_event(group->overflow_event, NULL);
638+
oevent->mask = FS_Q_OVERFLOW;
638639
oevent->wd = -1;
639640
oevent->sync_cookie = 0;
640641
oevent->name_len = 0;

fs/notify/notification.c

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void fsnotify_destroy_event(struct fsnotify_group *group,
7171
struct fsnotify_event *event)
7272
{
7373
/* Overflow events are per-group and we don't want to free them */
74-
if (!event || event->mask == FS_Q_OVERFLOW)
74+
if (!event || event == group->overflow_event)
7575
return;
7676
/*
7777
* If the event is still queued, we have a problem... Do an unreliable
@@ -194,23 +194,3 @@ void fsnotify_flush_notify(struct fsnotify_group *group)
194194
}
195195
spin_unlock(&group->notification_lock);
196196
}
197-
198-
/*
199-
* fsnotify_create_event - Allocate a new event which will be sent to each
200-
* group's handle_event function if the group was interested in this
201-
* particular event.
202-
*
203-
* @inode the inode which is supposed to receive the event (sometimes a
204-
* parent of the inode to which the event happened.
205-
* @mask what actually happened.
206-
* @data pointer to the object which was actually affected
207-
* @data_type flag indication if the data is a file, path, inode, nothing...
208-
* @name the filename, if available
209-
*/
210-
void fsnotify_init_event(struct fsnotify_event *event, struct inode *inode,
211-
u32 mask)
212-
{
213-
INIT_LIST_HEAD(&event->list);
214-
event->inode = inode;
215-
event->mask = mask;
216-
}

include/linux/fsnotify_backend.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ struct fsnotify_event {
135135
struct list_head list;
136136
/* inode may ONLY be dereferenced during handle_event(). */
137137
struct inode *inode; /* either the inode the event happened to or its parent */
138-
u32 mask; /* the type of access, bitwise OR for FS_* event types */
139138
};
140139

141140
/*
@@ -485,9 +484,12 @@ extern void fsnotify_put_mark(struct fsnotify_mark *mark);
485484
extern void fsnotify_finish_user_wait(struct fsnotify_iter_info *iter_info);
486485
extern bool fsnotify_prepare_user_wait(struct fsnotify_iter_info *iter_info);
487486

488-
/* put here because inotify does some weird stuff when destroying watches */
489-
extern void fsnotify_init_event(struct fsnotify_event *event,
490-
struct inode *to_tell, u32 mask);
487+
static inline void fsnotify_init_event(struct fsnotify_event *event,
488+
struct inode *inode)
489+
{
490+
INIT_LIST_HEAD(&event->list);
491+
event->inode = inode;
492+
}
491493

492494
#else
493495

0 commit comments

Comments
 (0)