On Tue, Apr 30, 2024 at 08:47:46PM +0200, Stefano Brivio wrote:On Mon, 29 Apr 2024 17:09:32 +1000 David Gibson <david(a)gibson.dropbear.id.au> wrote:Yeah, I don't love the name but it was the best I came up with. I wanted to emphasise the fact that it must be given an lvalue - this has to be a macro, not a function (even inline). [snip]Laurent's recent changes mean we use IO vectors much more heavily in the TCP code. In many of those cases, and few others around the code base, individual iovs of these vectors are constructed to exactly cover existing variables or fields. We can make initializing such iovs shorter and clearer with a macro for the purpose. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- iov.h | 3 +++ tap.c | 3 +-- tcp.c | 24 +++++++++--------------- udp.c | 7 +++---- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/iov.h b/iov.h index 6058af77..5668ca5f 100644 --- a/iov.h +++ b/iov.h @@ -18,6 +18,9 @@ #include <unistd.h> #include <string.h> +#define IOV_OF_LVALUE(lval) \ + (struct iovec){ .iov_base = &(lval), .iov_len = sizeof(lval) }I'm not sure if IOV_OF_LVALUE() is much clearer than IOV_FROM() or IOV_OF(). No strong preference though.Oops, fixed. -- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson@@ -315,8 +316,7 @@ static void udp_sock4_iov_init_one(const struct ctx *c, size_t i) .iph = L2_BUF_IP4_INIT(IPPROTO_UDP) }; - siov->iov_base = buf->data; - siov->iov_len = sizeof(buf->data); + *siov = IOV_OF_LVALUE(buf->data); mh->msg_name = &buf->s_in; mh->msg_namelen = sizeof(buf->s_in); @@ -343,8 +343,7 @@ static void udp_sock6_iov_init_one(const struct ctx *c, size_t i) .ip6h = L2_BUF_IP6_INIT(IPPROTO_UDP) }; - siov->iov_base = buf->data; - siov->iov_len = sizeof(buf->data); + *siov = IOV_OF_LVALUE(buf->data);Extra whitespace between tabs and =.