@@ -2445,12 +2445,8 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
return do_epoll_ctl(epfd, op, fd, &epds, false);
}
-/*
- * Implement the event wait interface for the eventpoll file. It is the kernel
- * part of the user space epoll_wait(2).
- */
-static int do_epoll_wait(int epfd, struct epoll_event __user *events,
- int maxevents, struct timespec64 *to)
+int epoll_wait(struct file *file, struct epoll_event __user *events,
+ int maxevents, struct timespec64 *to)
{
struct eventpoll *ep;
@@ -2462,28 +2458,37 @@ static int do_epoll_wait(int epfd, struct epoll_event __user *events,
if (!access_ok(events, maxevents * sizeof(struct epoll_event)))
return -EFAULT;
- /* Get the "struct file *" for the eventpoll file */
- CLASS(fd, f)(epfd);
- if (fd_empty(f))
- return -EBADF;
-
/*
* We have to check that the file structure underneath the fd
* the user passed to us _is_ an eventpoll file.
*/
- if (!is_file_epoll(fd_file(f)))
+ if (!is_file_epoll(file))
return -EINVAL;
/*
* At this point it is safe to assume that the "private_data" contains
* our own data structure.
*/
- ep = fd_file(f)->private_data;
+ ep = file->private_data;
/* Time to fish for events ... */
return ep_poll(ep, events, maxevents, to);
}
+/*
+ * Implement the event wait interface for the eventpoll file. It is the kernel
+ * part of the user space epoll_wait(2).
+ */
+static int do_epoll_wait(int epfd, struct epoll_event __user *events,
+ int maxevents, struct timespec64 *to)
+{
+ /* Get the "struct file *" for the eventpoll file */
+ CLASS(fd, f)(epfd);
+ if (!fd_empty(f))
+ return epoll_wait(fd_file(f), events, maxevents, to);
+ return -EBADF;
+}
+
SYSCALL_DEFINE4(epoll_wait, int, epfd, struct epoll_event __user *, events,
int, maxevents, int, timeout)
{
@@ -25,6 +25,10 @@ struct file *get_epoll_tfile_raw_ptr(struct file *file, int tfd, unsigned long t
/* Used to release the epoll bits inside the "struct file" */
void eventpoll_release_file(struct file *file);
+/* Use to reap events */
+int epoll_wait(struct file *file, struct epoll_event __user *events,
+ int maxevents, struct timespec64 *to);
+
/*
* This is called from inside fs/file_table.c:__fput() to unlink files
* from the eventpoll interface. We need to have this facility to cleanup
Add epoll_wait(), which takes a struct file and the number of events etc to reap. This can then be called by do_epoll_wait(), and used by io_uring as well. No intended functional changes in this patch. Signed-off-by: Jens Axboe <axboe@kernel.dk> --- fs/eventpoll.c | 31 ++++++++++++++++++------------- include/linux/eventpoll.h | 4 ++++ 2 files changed, 22 insertions(+), 13 deletions(-)