From: David Gibson <david@gibson.dropbear.id.au>
To: passt-dev@passt.top, Stefano Brivio <sbrivio@redhat.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 2/5] tcp: Split init and ns cases for tcp_sock_refill()
Date: Mon, 9 Jan 2023 11:50:23 +1100 [thread overview]
Message-ID: <20230109005026.24512-3-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20230109005026.24512-1-david@gibson.dropbear.id.au>
With the creation of the tcp_sock_refill_pool() helper, the ns==true and
ns==false paths for tcp_sock_refill() now have almost nothing in common.
Split the two versions into tcp_sock_refill_init() and tcp_sock_refill_ns()
functions.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
tcp.c | 53 +++++++++++++++++++++--------------------------------
1 file changed, 21 insertions(+), 32 deletions(-)
diff --git a/tcp.c b/tcp.c
index becad80..4da823c 100644
--- a/tcp.c
+++ b/tcp.c
@@ -3011,40 +3011,33 @@ static void tcp_sock_refill_pool(const struct ctx *c, int pool[], int af)
}
/**
- * struct tcp_sock_refill_arg - Arguments for tcp_sock_refill()
+ * tcp_sock_refill_init() - Refill pools of pre-opened sockets in init ns
* @c: Execution context
- * @ns: Set to refill pool of sockets created in namespace
*/
-struct tcp_sock_refill_arg {
- struct ctx *c;
- int ns;
-};
+static void tcp_sock_refill_init(const struct ctx *c)
+{
+ if (c->ifi4)
+ tcp_sock_refill_pool(c, init_sock_pool4, AF_INET);
+ if (c->ifi6)
+ tcp_sock_refill_pool(c, init_sock_pool6, AF_INET6);
+}
/**
- * tcp_sock_refill() - Refill pool of pre-opened sockets
- * @arg: See @tcp_sock_refill_arg
+ * tcp_sock_refill_ns() - Refill pools of pre-opened sockets in namespace
+ * @arg: Execution context cast to void *
*
* Return: 0
*/
-static int tcp_sock_refill(void *arg)
+static int tcp_sock_refill_ns(void *arg)
{
- struct tcp_sock_refill_arg *a = (struct tcp_sock_refill_arg *)arg;
- int *p4, *p6;
+ const struct ctx *c = (const struct ctx *)arg;
- if (a->ns) {
- ns_enter(a->c);
- p4 = ns_sock_pool4;
- p6 = ns_sock_pool6;
- } else {
- p4 = init_sock_pool4;
- p6 = init_sock_pool6;
- }
-
- if (a->c->ifi4)
- tcp_sock_refill_pool(a->c, p4, AF_INET);
+ ns_enter(c);
- if (a->c->ifi6)
- tcp_sock_refill_pool(a->c, p6, AF_INET6);
+ if (c->ifi4)
+ tcp_sock_refill_pool(c, ns_sock_pool4, AF_INET);
+ if (c->ifi6)
+ tcp_sock_refill_pool(c, ns_sock_pool6, AF_INET6);
return 0;
}
@@ -3057,7 +3050,6 @@ static int tcp_sock_refill(void *arg)
*/
int tcp_init(struct ctx *c)
{
- struct tcp_sock_refill_arg refill_arg = { c, 0 };
int i;
#ifndef HAS_GETRANDOM
int dev_random = open("/dev/random", O_RDONLY);
@@ -3103,15 +3095,14 @@ int tcp_init(struct ctx *c)
memset(tcp_sock_init_ext, 0xff, sizeof(tcp_sock_init_ext));
memset(tcp_sock_ns, 0xff, sizeof(tcp_sock_ns));
- tcp_sock_refill(&refill_arg);
+ tcp_sock_refill_init(c);
if (c->mode == MODE_PASTA) {
tcp_splice_init(c);
NS_CALL(tcp_ns_socks_init, c);
- refill_arg.ns = 1;
- NS_CALL(tcp_sock_refill, &refill_arg);
+ NS_CALL(tcp_sock_refill_ns, c);
}
return 0;
@@ -3231,7 +3222,6 @@ static int tcp_port_rebind(void *arg)
*/
void tcp_timer(struct ctx *c, const struct timespec *ts)
{
- struct tcp_sock_refill_arg refill_arg = { c, 0 };
union tcp_conn *conn;
(void)ts;
@@ -3264,12 +3254,11 @@ void tcp_timer(struct ctx *c, const struct timespec *ts)
}
}
- tcp_sock_refill(&refill_arg);
+ tcp_sock_refill_init(c);
if (c->mode == MODE_PASTA) {
- refill_arg.ns = 1;
if ((c->ifi4 && ns_sock_pool4[TCP_SOCK_POOL_TSH] < 0) ||
(c->ifi6 && ns_sock_pool6[TCP_SOCK_POOL_TSH] < 0))
- NS_CALL(tcp_sock_refill, &refill_arg);
+ NS_CALL(tcp_sock_refill_ns, c);
tcp_splice_pipe_refill(c);
}
--
@@ -3011,40 +3011,33 @@ static void tcp_sock_refill_pool(const struct ctx *c, int pool[], int af)
}
/**
- * struct tcp_sock_refill_arg - Arguments for tcp_sock_refill()
+ * tcp_sock_refill_init() - Refill pools of pre-opened sockets in init ns
* @c: Execution context
- * @ns: Set to refill pool of sockets created in namespace
*/
-struct tcp_sock_refill_arg {
- struct ctx *c;
- int ns;
-};
+static void tcp_sock_refill_init(const struct ctx *c)
+{
+ if (c->ifi4)
+ tcp_sock_refill_pool(c, init_sock_pool4, AF_INET);
+ if (c->ifi6)
+ tcp_sock_refill_pool(c, init_sock_pool6, AF_INET6);
+}
/**
- * tcp_sock_refill() - Refill pool of pre-opened sockets
- * @arg: See @tcp_sock_refill_arg
+ * tcp_sock_refill_ns() - Refill pools of pre-opened sockets in namespace
+ * @arg: Execution context cast to void *
*
* Return: 0
*/
-static int tcp_sock_refill(void *arg)
+static int tcp_sock_refill_ns(void *arg)
{
- struct tcp_sock_refill_arg *a = (struct tcp_sock_refill_arg *)arg;
- int *p4, *p6;
+ const struct ctx *c = (const struct ctx *)arg;
- if (a->ns) {
- ns_enter(a->c);
- p4 = ns_sock_pool4;
- p6 = ns_sock_pool6;
- } else {
- p4 = init_sock_pool4;
- p6 = init_sock_pool6;
- }
-
- if (a->c->ifi4)
- tcp_sock_refill_pool(a->c, p4, AF_INET);
+ ns_enter(c);
- if (a->c->ifi6)
- tcp_sock_refill_pool(a->c, p6, AF_INET6);
+ if (c->ifi4)
+ tcp_sock_refill_pool(c, ns_sock_pool4, AF_INET);
+ if (c->ifi6)
+ tcp_sock_refill_pool(c, ns_sock_pool6, AF_INET6);
return 0;
}
@@ -3057,7 +3050,6 @@ static int tcp_sock_refill(void *arg)
*/
int tcp_init(struct ctx *c)
{
- struct tcp_sock_refill_arg refill_arg = { c, 0 };
int i;
#ifndef HAS_GETRANDOM
int dev_random = open("/dev/random", O_RDONLY);
@@ -3103,15 +3095,14 @@ int tcp_init(struct ctx *c)
memset(tcp_sock_init_ext, 0xff, sizeof(tcp_sock_init_ext));
memset(tcp_sock_ns, 0xff, sizeof(tcp_sock_ns));
- tcp_sock_refill(&refill_arg);
+ tcp_sock_refill_init(c);
if (c->mode == MODE_PASTA) {
tcp_splice_init(c);
NS_CALL(tcp_ns_socks_init, c);
- refill_arg.ns = 1;
- NS_CALL(tcp_sock_refill, &refill_arg);
+ NS_CALL(tcp_sock_refill_ns, c);
}
return 0;
@@ -3231,7 +3222,6 @@ static int tcp_port_rebind(void *arg)
*/
void tcp_timer(struct ctx *c, const struct timespec *ts)
{
- struct tcp_sock_refill_arg refill_arg = { c, 0 };
union tcp_conn *conn;
(void)ts;
@@ -3264,12 +3254,11 @@ void tcp_timer(struct ctx *c, const struct timespec *ts)
}
}
- tcp_sock_refill(&refill_arg);
+ tcp_sock_refill_init(c);
if (c->mode == MODE_PASTA) {
- refill_arg.ns = 1;
if ((c->ifi4 && ns_sock_pool4[TCP_SOCK_POOL_TSH] < 0) ||
(c->ifi6 && ns_sock_pool6[TCP_SOCK_POOL_TSH] < 0))
- NS_CALL(tcp_sock_refill, &refill_arg);
+ NS_CALL(tcp_sock_refill_ns, c);
tcp_splice_pipe_refill(c);
}
--
2.39.0
next prev parent reply other threads:[~2023-01-09 0:50 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-09 0:50 [PATCH 0/5] Cleanups to tcp socket pool handling David Gibson
2023-01-09 0:50 ` [PATCH 1/5] tcp: Make a helper to refill each socket pool David Gibson
2023-01-12 18:09 ` Stefano Brivio
2023-01-15 0:22 ` David Gibson
2023-01-09 0:50 ` David Gibson [this message]
2023-01-09 0:50 ` [PATCH 3/5] tcp: Move socket pool declarations around David Gibson
2023-01-12 18:09 ` Stefano Brivio
2023-01-15 0:26 ` David Gibson
2023-01-09 0:50 ` [PATCH 4/5] tcp: Split pool lookup from creating new sockets in tcp_conn_new_sock() David Gibson
2023-01-09 0:50 ` [PATCH 5/5] tcp: Improve handling of fallback if socket pool is empty on new splice David Gibson
2023-01-12 18:09 ` Stefano Brivio
2023-01-15 0:31 ` David Gibson
2023-01-23 17:47 ` Stefano Brivio
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230109005026.24512-3-david@gibson.dropbear.id.au \
--to=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).