Skip to content

Commit 1d4240c

Browse files
isilenceaxboe
authored andcommitted
io_uring: early submission req fail code
Having only one place for cleaning up a request after a link assembly/ submission failure will play handy in the future. At least it allows to remove duplicated cleanup sequence. Signed-off-by: Pavel Begunkov <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent bf9c2f1 commit 1d4240c

File tree

1 file changed

+19
-31
lines changed

1 file changed

+19
-31
lines changed

fs/io_uring.c

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5608,7 +5608,7 @@ static inline void io_queue_link_head(struct io_kiocb *req)
56085608
IOSQE_IO_HARDLINK | IOSQE_ASYNC | \
56095609
IOSQE_BUFFER_SELECT)
56105610

5611-
static bool io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
5611+
static int io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
56125612
struct io_submit_state *state, struct io_kiocb **link)
56135613
{
56145614
struct io_ring_ctx *ctx = req->ctx;
@@ -5618,24 +5618,18 @@ static bool io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
56185618
sqe_flags = READ_ONCE(sqe->flags);
56195619

56205620
/* enforce forwards compatibility on users */
5621-
if (unlikely(sqe_flags & ~SQE_VALID_FLAGS)) {
5622-
ret = -EINVAL;
5623-
goto err_req;
5624-
}
5621+
if (unlikely(sqe_flags & ~SQE_VALID_FLAGS))
5622+
return -EINVAL;
56255623

56265624
if ((sqe_flags & IOSQE_BUFFER_SELECT) &&
5627-
!io_op_defs[req->opcode].buffer_select) {
5628-
ret = -EOPNOTSUPP;
5629-
goto err_req;
5630-
}
5625+
!io_op_defs[req->opcode].buffer_select)
5626+
return -EOPNOTSUPP;
56315627

56325628
id = READ_ONCE(sqe->personality);
56335629
if (id) {
56345630
req->work.creds = idr_find(&ctx->personality_idr, id);
5635-
if (unlikely(!req->work.creds)) {
5636-
ret = -EINVAL;
5637-
goto err_req;
5638-
}
5631+
if (unlikely(!req->work.creds))
5632+
return -EINVAL;
56395633
get_cred(req->work.creds);
56405634
}
56415635

@@ -5646,12 +5640,8 @@ static bool io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
56465640

56475641
fd = READ_ONCE(sqe->fd);
56485642
ret = io_req_set_file(state, req, fd, sqe_flags);
5649-
if (unlikely(ret)) {
5650-
err_req:
5651-
io_cqring_add_event(req, ret);
5652-
io_double_put_req(req);
5653-
return false;
5654-
}
5643+
if (unlikely(ret))
5644+
return ret;
56555645

56565646
/*
56575647
* If we already have a head request, queue this one for async
@@ -5674,16 +5664,14 @@ static bool io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
56745664
head->flags |= REQ_F_IO_DRAIN;
56755665
ctx->drain_next = 1;
56765666
}
5677-
if (io_alloc_async_ctx(req)) {
5678-
ret = -EAGAIN;
5679-
goto err_req;
5680-
}
5667+
if (io_alloc_async_ctx(req))
5668+
return -EAGAIN;
56815669

56825670
ret = io_req_defer_prep(req, sqe);
56835671
if (ret) {
56845672
/* fail even hard links since we don't submit */
56855673
head->flags |= REQ_F_FAIL_LINK;
5686-
goto err_req;
5674+
return ret;
56875675
}
56885676
trace_io_uring_link(ctx, req, head);
56895677
list_add_tail(&req->link_list, &head->link_list);
@@ -5702,10 +5690,9 @@ static bool io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
57025690
req->flags |= REQ_F_LINK;
57035691
INIT_LIST_HEAD(&req->link_list);
57045692

5705-
if (io_alloc_async_ctx(req)) {
5706-
ret = -EAGAIN;
5707-
goto err_req;
5708-
}
5693+
if (io_alloc_async_ctx(req))
5694+
return -EAGAIN;
5695+
57095696
ret = io_req_defer_prep(req, sqe);
57105697
if (ret)
57115698
req->flags |= REQ_F_FAIL_LINK;
@@ -5715,7 +5702,7 @@ static bool io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
57155702
}
57165703
}
57175704

5718-
return true;
5705+
return 0;
57195706
}
57205707

57215708
/*
@@ -5880,8 +5867,9 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
58805867
req->needs_fixed_file = async;
58815868
trace_io_uring_submit_sqe(ctx, req->opcode, req->user_data,
58825869
true, async);
5883-
if (!io_submit_sqe(req, sqe, statep, &link))
5884-
break;
5870+
err = io_submit_sqe(req, sqe, statep, &link);
5871+
if (err)
5872+
goto fail_req;
58855873
}
58865874

58875875
if (unlikely(submitted != nr)) {

0 commit comments

Comments
 (0)