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

Configure Feed

Select the types of activity you want to include in your feed.

io_uring: move epoll handler to its own file

Would be nice to sort out Kconfig for this and don't even compile
epoll.c if we don't have epoll configured.

Signed-off-by: Jens Axboe <axboe@kernel.dk>

+70 -50
+1 -1
io_uring/Makefile
··· 4 4 5 5 obj-$(CONFIG_IO_URING) += io_uring.o xattr.o nop.o fs.o splice.o \ 6 6 sync.o advise.o filetable.o \ 7 - openclose.o uring_cmd.o 7 + openclose.o uring_cmd.o epoll.o 8 8 obj-$(CONFIG_IO_WQ) += io-wq.o
+62
io_uring/epoll.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + #include <linux/kernel.h> 3 + #include <linux/errno.h> 4 + #include <linux/file.h> 5 + #include <linux/fs.h> 6 + #include <linux/uaccess.h> 7 + #include <linux/io_uring.h> 8 + #include <linux/eventpoll.h> 9 + 10 + #include <uapi/linux/io_uring.h> 11 + 12 + #include "io_uring_types.h" 13 + #include "io_uring.h" 14 + #include "epoll.h" 15 + 16 + #if defined(CONFIG_EPOLL) 17 + struct io_epoll { 18 + struct file *file; 19 + int epfd; 20 + int op; 21 + int fd; 22 + struct epoll_event event; 23 + }; 24 + 25 + int io_epoll_ctl_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) 26 + { 27 + struct io_epoll *epoll = io_kiocb_to_cmd(req); 28 + 29 + if (sqe->buf_index || sqe->splice_fd_in) 30 + return -EINVAL; 31 + 32 + epoll->epfd = READ_ONCE(sqe->fd); 33 + epoll->op = READ_ONCE(sqe->len); 34 + epoll->fd = READ_ONCE(sqe->off); 35 + 36 + if (ep_op_has_event(epoll->op)) { 37 + struct epoll_event __user *ev; 38 + 39 + ev = u64_to_user_ptr(READ_ONCE(sqe->addr)); 40 + if (copy_from_user(&epoll->event, ev, sizeof(*ev))) 41 + return -EFAULT; 42 + } 43 + 44 + return 0; 45 + } 46 + 47 + int io_epoll_ctl(struct io_kiocb *req, unsigned int issue_flags) 48 + { 49 + struct io_epoll *ie = io_kiocb_to_cmd(req); 50 + int ret; 51 + bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK; 52 + 53 + ret = do_epoll_ctl(ie->epfd, ie->op, ie->fd, &ie->event, force_nonblock); 54 + if (force_nonblock && ret == -EAGAIN) 55 + return -EAGAIN; 56 + 57 + if (ret < 0) 58 + req_set_fail(req); 59 + io_req_set_res(req, ret, 0); 60 + return IOU_OK; 61 + } 62 + #endif
+6
io_uring/epoll.h
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + #if defined(CONFIG_EPOLL) 4 + int io_epoll_ctl_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); 5 + int io_epoll_ctl(struct io_kiocb *req, unsigned int issue_flags); 6 + #endif
+1 -49
io_uring/io_uring.c
··· 100 100 #include "advise.h" 101 101 #include "openclose.h" 102 102 #include "uring_cmd.h" 103 + #include "epoll.h" 103 104 104 105 #define IORING_MAX_ENTRIES 32768 105 106 #define IORING_MAX_CQ_ENTRIES (2 * IORING_MAX_ENTRIES) ··· 373 372 u64 arg; 374 373 u32 nr_args; 375 374 u32 offset; 376 - }; 377 - 378 - struct io_epoll { 379 - struct file *file; 380 - int epfd; 381 - int op; 382 - int fd; 383 - struct epoll_event event; 384 375 }; 385 376 386 377 struct io_provide_buf { ··· 4032 4039 { 4033 4040 return -EOPNOTSUPP; 4034 4041 } 4035 - 4036 - #if defined(CONFIG_EPOLL) 4037 - static int io_epoll_ctl_prep(struct io_kiocb *req, 4038 - const struct io_uring_sqe *sqe) 4039 - { 4040 - struct io_epoll *epoll = io_kiocb_to_cmd(req); 4041 - 4042 - if (sqe->buf_index || sqe->splice_fd_in) 4043 - return -EINVAL; 4044 - 4045 - epoll->epfd = READ_ONCE(sqe->fd); 4046 - epoll->op = READ_ONCE(sqe->len); 4047 - epoll->fd = READ_ONCE(sqe->off); 4048 - 4049 - if (ep_op_has_event(epoll->op)) { 4050 - struct epoll_event __user *ev; 4051 - 4052 - ev = u64_to_user_ptr(READ_ONCE(sqe->addr)); 4053 - if (copy_from_user(&epoll->event, ev, sizeof(*ev))) 4054 - return -EFAULT; 4055 - } 4056 - 4057 - return 0; 4058 - } 4059 - 4060 - static int io_epoll_ctl(struct io_kiocb *req, unsigned int issue_flags) 4061 - { 4062 - struct io_epoll *ie = io_kiocb_to_cmd(req); 4063 - int ret; 4064 - bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK; 4065 - 4066 - ret = do_epoll_ctl(ie->epfd, ie->op, ie->fd, &ie->event, force_nonblock); 4067 - if (force_nonblock && ret == -EAGAIN) 4068 - return -EAGAIN; 4069 - 4070 - if (ret < 0) 4071 - req_set_fail(req); 4072 - io_req_set_res(req, ret, 0); 4073 - return IOU_OK; 4074 - } 4075 - #endif 4076 4042 4077 4043 static int io_statx_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) 4078 4044 {