Skip to content

Commit f56040b

Browse files
isilenceaxboe
authored andcommitted
io_uring: deduplicate io_grab_files() calls
Move io_req_init_async() into io_grab_files(), it's safer this way. Note that io_queue_async_work() does *init_async(), so it's valid to move out of __io_queue_sqe() punt path. Also, add a helper around io_grab_files(). Signed-off-by: Pavel Begunkov <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent ae34817 commit f56040b

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

fs/io_uring.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ static void io_queue_linked_timeout(struct io_kiocb *req);
912912
static int __io_sqe_files_update(struct io_ring_ctx *ctx,
913913
struct io_uring_files_update *ip,
914914
unsigned nr_args);
915-
static int io_grab_files(struct io_kiocb *req);
915+
static int io_prep_work_files(struct io_kiocb *req);
916916
static void io_complete_rw_common(struct kiocb *kiocb, long res,
917917
struct io_comp_state *cs);
918918
static void __io_clean_op(struct io_kiocb *req);
@@ -5294,13 +5294,9 @@ static int io_req_defer_prep(struct io_kiocb *req,
52945294

52955295
if (io_alloc_async_ctx(req))
52965296
return -EAGAIN;
5297-
5298-
if (io_op_defs[req->opcode].file_table) {
5299-
io_req_init_async(req);
5300-
ret = io_grab_files(req);
5301-
if (unlikely(ret))
5302-
return ret;
5303-
}
5297+
ret = io_prep_work_files(req);
5298+
if (unlikely(ret))
5299+
return ret;
53045300

53055301
switch (req->opcode) {
53065302
case IORING_OP_NOP:
@@ -5851,6 +5847,8 @@ static int io_grab_files(struct io_kiocb *req)
58515847
int ret = -EBADF;
58525848
struct io_ring_ctx *ctx = req->ctx;
58535849

5850+
io_req_init_async(req);
5851+
58545852
if (req->work.files || (req->flags & REQ_F_NO_FILE_TABLE))
58555853
return 0;
58565854
if (!ctx->ring_file)
@@ -5876,6 +5874,13 @@ static int io_grab_files(struct io_kiocb *req)
58765874
return ret;
58775875
}
58785876

5877+
static inline int io_prep_work_files(struct io_kiocb *req)
5878+
{
5879+
if (!io_op_defs[req->opcode].file_table)
5880+
return 0;
5881+
return io_grab_files(req);
5882+
}
5883+
58795884
static enum hrtimer_restart io_link_timeout_fn(struct hrtimer *timer)
58805885
{
58815886
struct io_timeout_data *data = container_of(timer,
@@ -5987,14 +5992,9 @@ static void __io_queue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
59875992
goto exit;
59885993
}
59895994
punt:
5990-
io_req_init_async(req);
5991-
5992-
if (io_op_defs[req->opcode].file_table) {
5993-
ret = io_grab_files(req);
5994-
if (ret)
5995-
goto err;
5996-
}
5997-
5995+
ret = io_prep_work_files(req);
5996+
if (unlikely(ret))
5997+
goto err;
59985998
/*
59995999
* Queued up for async execution, worker will release
60006000
* submit reference when the iocb is actually submitted.

0 commit comments

Comments
 (0)