Skip to content

Commit ae3a4f1

Browse files
axboebrauner
authored andcommitted
eventpoll: add epoll_sendevents() helper
Basic helper that copies ready events to the specified userspace address. The event checking is quick and racy, it's up to the caller to ensure it retries appropriately in case 0 events are copied. Signed-off-by: Jens Axboe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 38d2035 commit ae3a4f1

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

fs/eventpoll.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,6 +2474,26 @@ static int ep_check_params(struct file *file, struct epoll_event __user *evs,
24742474
return 0;
24752475
}
24762476

2477+
int epoll_sendevents(struct file *file, struct epoll_event __user *events,
2478+
int maxevents)
2479+
{
2480+
struct eventpoll *ep;
2481+
int ret;
2482+
2483+
ret = ep_check_params(file, events, maxevents);
2484+
if (unlikely(ret))
2485+
return ret;
2486+
2487+
ep = file->private_data;
2488+
/*
2489+
* Racy call, but that's ok - it should get retried based on
2490+
* poll readiness anyway.
2491+
*/
2492+
if (ep_events_available(ep))
2493+
return ep_try_send_events(ep, events, maxevents);
2494+
return 0;
2495+
}
2496+
24772497
/*
24782498
* Implement the event wait interface for the eventpoll file. It is the kernel
24792499
* part of the user space epoll_wait(2).

include/linux/eventpoll.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ struct file *get_epoll_tfile_raw_ptr(struct file *file, int tfd, unsigned long t
2525
/* Used to release the epoll bits inside the "struct file" */
2626
void eventpoll_release_file(struct file *file);
2727

28+
/* Copy ready events to userspace */
29+
int epoll_sendevents(struct file *file, struct epoll_event __user *events,
30+
int maxevents);
31+
2832
/*
2933
* This is called from inside fs/file_table.c:__fput() to unlink files
3034
* from the eventpoll interface. We need to have this facility to cleanup

0 commit comments

Comments
 (0)