[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <b5f01a0c66b53f5bdc503fb0fbda848dbd6d3ece.1580508735.git.asml.silence@gmail.com>
Date: Sat, 1 Feb 2020 01:15:52 +0300
From: Pavel Begunkov <asml.silence@...il.com>
To: Jens Axboe <axboe@...nel.dk>, io-uring@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH v3 3/6] io_uring: move ring_fd into io_submit_state
ring_fd and ring_file are set per submission, so move them into
the submission state.
Signed-off-by: Pavel Begunkov <asml.silence@...il.com>
---
fs/io_uring.c | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 6109969709ff..725e852e22c5 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -216,6 +216,9 @@ struct io_submit_state {
unsigned int has_refs;
unsigned int used_refs;
unsigned int ios_left;
+
+ struct file *ring_file;
+ int ring_fd;
};
struct io_ring_ctx {
@@ -274,8 +277,6 @@ struct io_ring_ctx {
*/
struct fixed_file_data *file_data;
unsigned nr_user_files;
- int ring_fd;
- struct file *ring_file;
/* if used, fixed mapped user buffers */
unsigned nr_user_bufs;
@@ -2822,7 +2823,7 @@ static int io_close_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
req->close.fd = READ_ONCE(sqe->fd);
if (req->file->f_op == &io_uring_fops ||
- req->close.fd == req->ctx->ring_fd)
+ req->close.fd == req->ctx->submit_state.ring_fd)
return -EBADF;
return 0;
@@ -4517,10 +4518,11 @@ static int io_grab_files(struct io_kiocb *req)
{
int ret = -EBADF;
struct io_ring_ctx *ctx = req->ctx;
+ struct io_submit_state *state = &ctx->submit_state;
if (req->work.files)
return 0;
- if (!ctx->ring_file)
+ if (!state->ring_file)
return -EBADF;
rcu_read_lock();
@@ -4531,7 +4533,7 @@ static int io_grab_files(struct io_kiocb *req)
* the fd has changed since we started down this path, and disallow
* this operation if it has.
*/
- if (fcheck(ctx->ring_fd) == ctx->ring_file) {
+ if (fcheck(state->ring_fd) == state->ring_file) {
list_add(&req->inflight_entry, &ctx->inflight_list);
req->flags |= REQ_F_INFLIGHT;
req->work.files = current->files;
@@ -4839,13 +4841,17 @@ static void io_submit_end(struct io_ring_ctx *ctx)
/*
* Start submission side cache.
*/
-static void io_submit_start(struct io_ring_ctx *ctx, unsigned int max_ios)
+static void io_submit_start(struct io_ring_ctx *ctx, unsigned int max_ios,
+ struct file *ring_file, int ring_fd)
{
struct io_submit_state *state = &ctx->submit_state;
state->free_reqs = 0;
state->file = NULL;
state->ios_left = max_ios;
+
+ state->ring_file = ring_file;
+ state->ring_fd = ring_fd;
}
static void io_commit_sqring(struct io_ring_ctx *ctx)
@@ -4926,13 +4932,10 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
if (!percpu_ref_tryget_many(&ctx->refs, nr))
return -EAGAIN;
- io_submit_start(ctx, nr);
+ io_submit_start(ctx, nr, ring_file, ring_fd);
if (nr > IO_PLUG_THRESHOLD)
blk_start_plug(&plug);
- ctx->ring_fd = ring_fd;
- ctx->ring_file = ring_file;
-
for (i = 0; i < nr; i++) {
const struct io_uring_sqe *sqe;
struct io_kiocb *req;
--
2.24.0
Powered by blists - more mailing lists