Skip to content

Commit a9c210c

Browse files
committed
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 <[email protected]>
1 parent 4cf9049 commit a9c210c

File tree

4 files changed

+70
-50
lines changed

4 files changed

+70
-50
lines changed

io_uring/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
obj-$(CONFIG_IO_URING) += io_uring.o xattr.o nop.o fs.o splice.o \
66
sync.o advise.o filetable.o \
7-
openclose.o uring_cmd.o
7+
openclose.o uring_cmd.o epoll.o
88
obj-$(CONFIG_IO_WQ) += io-wq.o

io_uring/epoll.c

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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

io_uring/epoll.h

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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

io_uring/io_uring.c

+1-49
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
#include "advise.h"
101101
#include "openclose.h"
102102
#include "uring_cmd.h"
103+
#include "epoll.h"
103104

104105
#define IORING_MAX_ENTRIES 32768
105106
#define IORING_MAX_CQ_ENTRIES (2 * IORING_MAX_ENTRIES)
@@ -374,14 +375,6 @@ struct io_rsrc_update {
374375
u32 offset;
375376
};
376377

377-
struct io_epoll {
378-
struct file *file;
379-
int epfd;
380-
int op;
381-
int fd;
382-
struct epoll_event event;
383-
};
384-
385378
struct io_provide_buf {
386379
struct file *file;
387380
__u64 addr;
@@ -4040,47 +4033,6 @@ static __maybe_unused int io_eopnotsupp_prep(struct io_kiocb *kiocb,
40404033
return -EOPNOTSUPP;
40414034
}
40424035

4043-
#if defined(CONFIG_EPOLL)
4044-
static int io_epoll_ctl_prep(struct io_kiocb *req,
4045-
const struct io_uring_sqe *sqe)
4046-
{
4047-
struct io_epoll *epoll = io_kiocb_to_cmd(req);
4048-
4049-
if (sqe->buf_index || sqe->splice_fd_in)
4050-
return -EINVAL;
4051-
4052-
epoll->epfd = READ_ONCE(sqe->fd);
4053-
epoll->op = READ_ONCE(sqe->len);
4054-
epoll->fd = READ_ONCE(sqe->off);
4055-
4056-
if (ep_op_has_event(epoll->op)) {
4057-
struct epoll_event __user *ev;
4058-
4059-
ev = u64_to_user_ptr(READ_ONCE(sqe->addr));
4060-
if (copy_from_user(&epoll->event, ev, sizeof(*ev)))
4061-
return -EFAULT;
4062-
}
4063-
4064-
return 0;
4065-
}
4066-
4067-
static int io_epoll_ctl(struct io_kiocb *req, unsigned int issue_flags)
4068-
{
4069-
struct io_epoll *ie = io_kiocb_to_cmd(req);
4070-
int ret;
4071-
bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK;
4072-
4073-
ret = do_epoll_ctl(ie->epfd, ie->op, ie->fd, &ie->event, force_nonblock);
4074-
if (force_nonblock && ret == -EAGAIN)
4075-
return -EAGAIN;
4076-
4077-
if (ret < 0)
4078-
req_set_fail(req);
4079-
io_req_set_res(req, ret, 0);
4080-
return IOU_OK;
4081-
}
4082-
#endif
4083-
40844036
static int io_statx_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
40854037
{
40864038
struct io_statx *sx = io_kiocb_to_cmd(req);

0 commit comments

Comments
 (0)