diff mbox series

[1/4] io_uring/net: introduce io_kmsg_set_iovec

Message ID c987adc69862de06c50f10d55502064478fd9f2d.1729650350.git.asml.silence@gmail.com (mailing list archive)
State New
Headers show
Series implement vectored registered buffers for sendzc | expand

Commit Message

Pavel Begunkov Oct. 23, 2024, 2:38 a.m. UTC
A prep patch, add a helper function taking an allocated iovec and
assigning it to the kmsg cache. It'll be expanded upon in the following
patch.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 io_uring/net.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/io_uring/net.c b/io_uring/net.c
index 0a0b148a153c..bd24290fa646 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -125,12 +125,18 @@  static bool io_net_retry(struct socket *sock, int flags)
 	return sock->type == SOCK_STREAM || sock->type == SOCK_SEQPACKET;
 }
 
+static inline void io_kmsg_set_iovec(struct io_async_msghdr *kmsg,
+				     struct iovec *iov, int nr)
+{
+	kmsg->free_iov_nr = nr;
+	kmsg->free_iov = iov;
+}
+
 static void io_netmsg_iovec_free(struct io_async_msghdr *kmsg)
 {
 	if (kmsg->free_iov) {
 		kfree(kmsg->free_iov);
-		kmsg->free_iov_nr = 0;
-		kmsg->free_iov = NULL;
+		io_kmsg_set_iovec(kmsg, NULL, 0);
 	}
 }
 
@@ -174,8 +180,7 @@  static struct io_async_msghdr *io_msg_alloc_async(struct io_kiocb *req)
 
 	if (!io_alloc_async_data(req)) {
 		hdr = req->async_data;
-		hdr->free_iov_nr = 0;
-		hdr->free_iov = NULL;
+		io_kmsg_set_iovec(hdr, NULL, 0);
 		return hdr;
 	}
 	return NULL;
@@ -187,10 +192,9 @@  static int io_net_vec_assign(struct io_kiocb *req, struct io_async_msghdr *kmsg,
 {
 	if (iov) {
 		req->flags |= REQ_F_NEED_CLEANUP;
-		kmsg->free_iov_nr = kmsg->msg.msg_iter.nr_segs;
 		if (kmsg->free_iov)
 			kfree(kmsg->free_iov);
-		kmsg->free_iov = iov;
+		io_kmsg_set_iovec(kmsg, iov, kmsg->msg.msg_iter.nr_segs);
 	}
 	return 0;
 }
@@ -623,8 +627,7 @@  int io_send(struct io_kiocb *req, unsigned int issue_flags)
 			return ret;
 
 		if (arg.iovs != &kmsg->fast_iov && arg.iovs != kmsg->free_iov) {
-			kmsg->free_iov_nr = ret;
-			kmsg->free_iov = arg.iovs;
+			io_kmsg_set_iovec(kmsg, arg.iovs, ret);
 			req->flags |= REQ_F_NEED_CLEANUP;
 		}
 		sr->len = arg.out_len;
@@ -1107,8 +1110,7 @@  static int io_recv_buf_select(struct io_kiocb *req, struct io_async_msghdr *kmsg
 		iov_iter_init(&kmsg->msg.msg_iter, ITER_DEST, arg.iovs, ret,
 				arg.out_len);
 		if (arg.iovs != &kmsg->fast_iov && arg.iovs != kmsg->free_iov) {
-			kmsg->free_iov_nr = ret;
-			kmsg->free_iov = arg.iovs;
+			io_kmsg_set_iovec(kmsg, arg.iovs, ret);
 			req->flags |= REQ_F_NEED_CLEANUP;
 		}
 	} else {