aboutsummaryrefslogtreecommitdiffstats
path: root/fs/io_uring.c
diff options
context:
space:
mode:
authorPavel Begunkov <asml.silence@gmail.com>2020-11-20 15:50:51 +0000
committerJens Axboe <axboe@kernel.dk>2020-12-09 12:04:01 -0700
commitbd5bbda72f7fa013ddea0ff7c4d91daedb821869 (patch)
tree0015681228d97bacae9546fa04257b0f7eda2b83 /fs/io_uring.c
parentio_uring: change submit file state invariant (diff)
downloadlinux-dev-bd5bbda72f7fa013ddea0ff7c4d91daedb821869.tar.xz
linux-dev-bd5bbda72f7fa013ddea0ff7c4d91daedb821869.zip
io_uring: fix miscounting ios_left
io_req_init() doesn't decrement state->ios_left if a request doesn't need ->file, it just returns before that on if(!needs_file). That's not really a problem but may cause overhead for an additional fput(). Also inline and kill io_req_set_file() as it's of no use anymore. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'fs/io_uring.c')
-rw-r--r--fs/io_uring.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/fs/io_uring.c b/fs/io_uring.c
index a83593cadcc9..91536947ef08 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -6327,15 +6327,6 @@ static struct file *io_file_get(struct io_submit_state *state,
return file;
}
-static int io_req_set_file(struct io_submit_state *state, struct io_kiocb *req,
- int fd)
-{
- req->file = io_file_get(state, req, fd, req->flags & REQ_F_FIXED_FILE);
- if (req->file || io_op_defs[req->opcode].needs_file_no_error)
- return 0;
- return -EBADF;
-}
-
static enum hrtimer_restart io_link_timeout_fn(struct hrtimer *timer)
{
struct io_timeout_data *data = container_of(timer,
@@ -6748,10 +6739,16 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
state->plug_started = true;
}
- if (!io_op_defs[req->opcode].needs_file)
- return 0;
+ ret = 0;
+ if (io_op_defs[req->opcode].needs_file) {
+ bool fixed = req->flags & REQ_F_FIXED_FILE;
+
+ req->file = io_file_get(state, req, READ_ONCE(sqe->fd), fixed);
+ if (unlikely(!req->file &&
+ !io_op_defs[req->opcode].needs_file_no_error))
+ ret = -EBADF;
+ }
- ret = io_req_set_file(state, req, READ_ONCE(sqe->fd));
state->ios_left--;
return ret;
}