Skip to content

Commit bb2f7b4

Browse files
amir73iljankara
authored andcommitted
fanotify: open code fill_event_metadata()
The helper is quite trivial and open coding it will make it easier to implement copying event fid info to user. Signed-off-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz>
1 parent 3391399 commit bb2f7b4

File tree

1 file changed

+27
-44
lines changed

1 file changed

+27
-44
lines changed

fs/notify/fanotify/fanotify_user.c

Lines changed: 27 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -114,36 +114,6 @@ static int create_fd(struct fsnotify_group *group,
114114
return client_fd;
115115
}
116116

117-
static int fill_event_metadata(struct fsnotify_group *group,
118-
struct fanotify_event_metadata *metadata,
119-
struct fsnotify_event *fsn_event,
120-
struct file **file)
121-
{
122-
int ret = 0;
123-
struct fanotify_event *event;
124-
125-
pr_debug("%s: group=%p metadata=%p event=%p\n", __func__,
126-
group, metadata, fsn_event);
127-
128-
*file = NULL;
129-
event = container_of(fsn_event, struct fanotify_event, fse);
130-
metadata->event_len = FAN_EVENT_METADATA_LEN;
131-
metadata->metadata_len = FAN_EVENT_METADATA_LEN;
132-
metadata->vers = FANOTIFY_METADATA_VERSION;
133-
metadata->reserved = 0;
134-
metadata->mask = event->mask & FANOTIFY_OUTGOING_EVENTS;
135-
metadata->pid = pid_vnr(event->pid);
136-
if (unlikely(event->mask & FAN_Q_OVERFLOW))
137-
metadata->fd = FAN_NOFD;
138-
else {
139-
metadata->fd = create_fd(group, event, file);
140-
if (metadata->fd < 0)
141-
ret = metadata->fd;
142-
}
143-
144-
return ret;
145-
}
146-
147117
static struct fanotify_perm_event *dequeue_event(
148118
struct fsnotify_group *group, int fd)
149119
{
@@ -205,37 +175,50 @@ static int process_access_response(struct fsnotify_group *group,
205175
}
206176

207177
static ssize_t copy_event_to_user(struct fsnotify_group *group,
208-
struct fsnotify_event *event,
178+
struct fsnotify_event *fsn_event,
209179
char __user *buf, size_t count)
210180
{
211-
struct fanotify_event_metadata fanotify_event_metadata;
212-
struct file *f;
181+
struct fanotify_event_metadata metadata;
182+
struct fanotify_event *event;
183+
struct file *f = NULL;
213184
int fd, ret;
214185

215-
pr_debug("%s: group=%p event=%p\n", __func__, group, event);
186+
pr_debug("%s: group=%p event=%p\n", __func__, group, fsn_event);
216187

217-
ret = fill_event_metadata(group, &fanotify_event_metadata, event, &f);
218-
if (ret < 0)
219-
return ret;
188+
event = container_of(fsn_event, struct fanotify_event, fse);
189+
metadata.event_len = FAN_EVENT_METADATA_LEN;
190+
metadata.metadata_len = FAN_EVENT_METADATA_LEN;
191+
metadata.vers = FANOTIFY_METADATA_VERSION;
192+
metadata.reserved = 0;
193+
metadata.mask = event->mask & FANOTIFY_OUTGOING_EVENTS;
194+
metadata.pid = pid_vnr(event->pid);
195+
196+
if (unlikely(event->mask & FAN_Q_OVERFLOW)) {
197+
fd = FAN_NOFD;
198+
} else {
199+
fd = create_fd(group, event, &f);
200+
if (fd < 0)
201+
return fd;
202+
}
203+
metadata.fd = fd;
220204

221-
fd = fanotify_event_metadata.fd;
222205
ret = -EFAULT;
223206
/*
224207
* Sanity check copy size in case get_one_event() and
225208
* fill_event_metadata() event_len sizes ever get out of sync.
226209
*/
227-
if (WARN_ON_ONCE(fanotify_event_metadata.event_len > count))
210+
if (WARN_ON_ONCE(metadata.event_len > count))
228211
goto out_close_fd;
229-
if (copy_to_user(buf, &fanotify_event_metadata,
230-
fanotify_event_metadata.event_len))
212+
213+
if (copy_to_user(buf, &metadata, metadata.event_len))
231214
goto out_close_fd;
232215

233-
if (fanotify_is_perm_event(FANOTIFY_E(event)->mask))
234-
FANOTIFY_PE(event)->fd = fd;
216+
if (fanotify_is_perm_event(event->mask))
217+
FANOTIFY_PE(fsn_event)->fd = fd;
235218

236219
if (fd != FAN_NOFD)
237220
fd_install(fd, f);
238-
return fanotify_event_metadata.event_len;
221+
return metadata.event_len;
239222

240223
out_close_fd:
241224
if (fd != FAN_NOFD) {

0 commit comments

Comments
 (0)