Skip to content

Commit bd5bbda

Browse files
isilenceaxboe
authored andcommitted
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 <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 6e1271e commit bd5bbda

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

fs/io_uring.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6327,15 +6327,6 @@ static struct file *io_file_get(struct io_submit_state *state,
63276327
return file;
63286328
}
63296329

6330-
static int io_req_set_file(struct io_submit_state *state, struct io_kiocb *req,
6331-
int fd)
6332-
{
6333-
req->file = io_file_get(state, req, fd, req->flags & REQ_F_FIXED_FILE);
6334-
if (req->file || io_op_defs[req->opcode].needs_file_no_error)
6335-
return 0;
6336-
return -EBADF;
6337-
}
6338-
63396330
static enum hrtimer_restart io_link_timeout_fn(struct hrtimer *timer)
63406331
{
63416332
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,
67486739
state->plug_started = true;
67496740
}
67506741

6751-
if (!io_op_defs[req->opcode].needs_file)
6752-
return 0;
6742+
ret = 0;
6743+
if (io_op_defs[req->opcode].needs_file) {
6744+
bool fixed = req->flags & REQ_F_FIXED_FILE;
6745+
6746+
req->file = io_file_get(state, req, READ_ONCE(sqe->fd), fixed);
6747+
if (unlikely(!req->file &&
6748+
!io_op_defs[req->opcode].needs_file_no_error))
6749+
ret = -EBADF;
6750+
}
67536751

6754-
ret = io_req_set_file(state, req, READ_ONCE(sqe->fd));
67556752
state->ios_left--;
67566753
return ret;
67576754
}

0 commit comments

Comments
 (0)