Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <axboe@kernel.dk>
Link: https://lore.kernel.org/r/20250219172552.1565603-4-axboe@kernel.dk
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Jens Axboe and committed by
Christian Brauner
ae3a4f1f 38d20356

+24
+20
fs/eventpoll.c
··· 2474 2474 return 0; 2475 2475 } 2476 2476 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 + 2477 2497 /* 2478 2498 * Implement the event wait interface for the eventpoll file. It is the kernel 2479 2499 * part of the user space epoll_wait(2).
+4
include/linux/eventpoll.h
··· 25 25 /* Used to release the epoll bits inside the "struct file" */ 26 26 void eventpoll_release_file(struct file *file); 27 27 28 + /* Copy ready events to userspace */ 29 + int epoll_sendevents(struct file *file, struct epoll_event __user *events, 30 + int maxevents); 31 + 28 32 /* 29 33 * This is called from inside fs/file_table.c:__fput() to unlink files 30 34 * from the eventpoll interface. We need to have this facility to cleanup