summaryrefslogtreecommitdiffstats
path: root/fs/notify
diff options
context:
space:
mode:
authorAmir Goldstein <amir73il@gmail.com>2019-01-10 12:04:33 -0500
committerJan Kara <jack@suse.cz>2019-02-07 10:37:01 -0500
commitbb2f7b4542c7a1d023d516af37dc70bb49db0438 (patch)
tree9afb110f7e14bf9fbdd4c01226714e8a66ec3227 /fs/notify
parent33913997d5c06781c162952c6e5017131fc5aa19 (diff)
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>
Diffstat (limited to 'fs/notify')
-rw-r--r--fs/notify/fanotify/fanotify_user.c71
1 files changed, 27 insertions, 44 deletions
diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index 55cd87b0cc26..096503bd0edb 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -114,36 +114,6 @@ static int create_fd(struct fsnotify_group *group,
114 return client_fd; 114 return client_fd;
115} 115}
116 116
117static 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
147static struct fanotify_perm_event *dequeue_event( 117static struct fanotify_perm_event *dequeue_event(
148 struct fsnotify_group *group, int fd) 118 struct fsnotify_group *group, int fd)
149{ 119{
@@ -205,37 +175,50 @@ static int process_access_response(struct fsnotify_group *group,
205} 175}
206 176
207static ssize_t copy_event_to_user(struct fsnotify_group *group, 177static ssize_t copy_event_to_user(struct fsnotify_group *group,
208 struct fsnotify_event *event, 178 struct fsnotify_event *fsn_event,
209 char __user *buf, size_t count) 179 char __user *buf, size_t count)
210{ 180{
211 struct fanotify_event_metadata fanotify_event_metadata; 181 struct fanotify_event_metadata metadata;
212 struct file *f; 182 struct fanotify_event *event;
183 struct file *f = NULL;
213 int fd, ret; 184 int fd, ret;
214 185
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);
216 187
217 ret = fill_event_metadata(group, &fanotify_event_metadata, event, &f); 188 event = container_of(fsn_event, struct fanotify_event, fse);
218 if (ret < 0) 189 metadata.event_len = FAN_EVENT_METADATA_LEN;
219 return ret; 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;
220 204
221 fd = fanotify_event_metadata.fd;
222 ret = -EFAULT; 205 ret = -EFAULT;
223 /* 206 /*
224 * Sanity check copy size in case get_one_event() and 207 * Sanity check copy size in case get_one_event() and
225 * fill_event_metadata() event_len sizes ever get out of sync. 208 * fill_event_metadata() event_len sizes ever get out of sync.
226 */ 209 */
227 if (WARN_ON_ONCE(fanotify_event_metadata.event_len > count)) 210 if (WARN_ON_ONCE(metadata.event_len > count))
228 goto out_close_fd; 211 goto out_close_fd;
229 if (copy_to_user(buf, &fanotify_event_metadata, 212
230 fanotify_event_metadata.event_len)) 213 if (copy_to_user(buf, &metadata, metadata.event_len))
231 goto out_close_fd; 214 goto out_close_fd;
232 215
233 if (fanotify_is_perm_event(FANOTIFY_E(event)->mask)) 216 if (fanotify_is_perm_event(event->mask))
234 FANOTIFY_PE(event)->fd = fd; 217 FANOTIFY_PE(fsn_event)->fd = fd;
235 218
236 if (fd != FAN_NOFD) 219 if (fd != FAN_NOFD)
237 fd_install(fd, f); 220 fd_install(fd, f);
238 return fanotify_event_metadata.event_len; 221 return metadata.event_len;
239 222
240out_close_fd: 223out_close_fd:
241 if (fd != FAN_NOFD) { 224 if (fd != FAN_NOFD) {