0001
0002 #include <linux/kernel.h>
0003 #include <linux/errno.h>
0004 #include <linux/file.h>
0005 #include <linux/fs.h>
0006 #include <linux/uaccess.h>
0007 #include <linux/io_uring.h>
0008 #include <linux/eventpoll.h>
0009
0010 #include <uapi/linux/io_uring.h>
0011
0012 #include "io_uring.h"
0013 #include "epoll.h"
0014
0015 #if defined(CONFIG_EPOLL)
0016 struct io_epoll {
0017 struct file *file;
0018 int epfd;
0019 int op;
0020 int fd;
0021 struct epoll_event event;
0022 };
0023
0024 int io_epoll_ctl_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
0025 {
0026 struct io_epoll *epoll = io_kiocb_to_cmd(req, struct io_epoll);
0027
0028 pr_warn_once("%s: epoll_ctl support in io_uring is deprecated and will "
0029 "be removed in a future Linux kernel version.\n",
0030 current->comm);
0031
0032 if (sqe->buf_index || sqe->splice_fd_in)
0033 return -EINVAL;
0034
0035 epoll->epfd = READ_ONCE(sqe->fd);
0036 epoll->op = READ_ONCE(sqe->len);
0037 epoll->fd = READ_ONCE(sqe->off);
0038
0039 if (ep_op_has_event(epoll->op)) {
0040 struct epoll_event __user *ev;
0041
0042 ev = u64_to_user_ptr(READ_ONCE(sqe->addr));
0043 if (copy_from_user(&epoll->event, ev, sizeof(*ev)))
0044 return -EFAULT;
0045 }
0046
0047 return 0;
0048 }
0049
0050 int io_epoll_ctl(struct io_kiocb *req, unsigned int issue_flags)
0051 {
0052 struct io_epoll *ie = io_kiocb_to_cmd(req, struct io_epoll);
0053 int ret;
0054 bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK;
0055
0056 ret = do_epoll_ctl(ie->epfd, ie->op, ie->fd, &ie->event, force_nonblock);
0057 if (force_nonblock && ret == -EAGAIN)
0058 return -EAGAIN;
0059
0060 if (ret < 0)
0061 req_set_fail(req);
0062 io_req_set_res(req, ret, 0);
0063 return IOU_OK;
0064 }
0065 #endif