Skip to content

Commit d9b4418

Browse files
committed
io_uring/net: add io_req_msg_cleanup() helper
For the fast inline path, we manually recycle the io_async_msghdr and free the iovec, and then clear the REQ_F_NEED_CLEANUP flag to avoid that needing doing in the slower path. We already do that in 2 spots, and in preparation for adding more, add a helper and use it. Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent fb6328b commit d9b4418

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

io_uring/net.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,17 @@ int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
414414
return 0;
415415
}
416416

417+
static void io_req_msg_cleanup(struct io_kiocb *req,
418+
struct io_async_msghdr *kmsg,
419+
unsigned int issue_flags)
420+
{
421+
req->flags &= ~REQ_F_NEED_CLEANUP;
422+
/* fast path, check for non-NULL to avoid function call */
423+
if (kmsg->free_iov)
424+
kfree(kmsg->free_iov);
425+
io_netmsg_recycle(req, issue_flags);
426+
}
427+
417428
int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags)
418429
{
419430
struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg);
@@ -463,11 +474,7 @@ int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags)
463474
ret = -EINTR;
464475
req_set_fail(req);
465476
}
466-
/* fast path, check for non-NULL to avoid function call */
467-
if (kmsg->free_iov)
468-
kfree(kmsg->free_iov);
469-
req->flags &= ~REQ_F_NEED_CLEANUP;
470-
io_netmsg_recycle(req, issue_flags);
477+
io_req_msg_cleanup(req, kmsg, issue_flags);
471478
if (ret >= 0)
472479
ret += sr->done_io;
473480
else if (sr->done_io)
@@ -927,13 +934,9 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
927934
if (!io_recv_finish(req, &ret, &kmsg->msg, mshot_finished, issue_flags))
928935
goto retry_multishot;
929936

930-
if (mshot_finished) {
931-
/* fast path, check for non-NULL to avoid function call */
932-
if (kmsg->free_iov)
933-
kfree(kmsg->free_iov);
934-
io_netmsg_recycle(req, issue_flags);
935-
req->flags &= ~REQ_F_NEED_CLEANUP;
936-
} else if (ret == -EAGAIN)
937+
if (mshot_finished)
938+
io_req_msg_cleanup(req, kmsg, issue_flags);
939+
else if (ret == -EAGAIN)
937940
return io_setup_async_msg(req, kmsg, issue_flags);
938941

939942
return ret;

0 commit comments

Comments
 (0)