Skip to contentSkip to conversation

fixes for create_netns

PATCH Superseded Geliang Tang 2 participants 5 messages May 15, 2024

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Geliang Tang

author reviewer
#0 lore raw

cover fixes for create_netns

From: Geliang Tang <[email protected]>

Since create_netns() is updated in "bpf-next add netns helpers" series, some mptcp bpf patches need to be updated.

This series epends on "bpf-next add netns helpers" series.

Geliang Tang (3):
selftests/bpf: Handle SIGINT when creating netns Squash to "selftests/bpf: Add mptcp subflow subtest" Squash to "selftests/bpf: Add bpf scheduler test"

 tools/testing/selftests/bpf/network_helpers.c  | 12 ++++++++++++
 tools/testing/selftests/bpf/prog_tests/mptcp.c |  4 ++--
 2 files changed, 14 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0
author reviewer
#1 lore raw

PATCH 1/3 selftests/bpf: Handle SIGINT when creating netns

From: Geliang Tang <[email protected]>

It's necessary to delete netns during BPF selftests interrupt, otherwise the next tests run will fail due to unable to create netns.

This patch adds a new SIGINT handle netns_sig_handler() in create_netns(), and deletes NS_TEST in this handler.

For passing argument to signal handler, a trick mentioned in [1] is used.

[1]
https://stackoverflow.com/questions/6970224/providing-passing-argument-to-signal-handler

---
 tools/testing/selftests/bpf/network_helpers.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
tools/testing/selftests/bpf/network_helpers.c +12 -0
index 0b25b008f4f6..7e233b8c75d9 100644
@@ -519,6 +519,16 @@ void cleanup_netns(struct nstoken *token)
 	close_netns(token);
 }
 
+static int netns_sig_handler(const int sig, void *ptr)
+{
+	struct nstoken *token = (struct nstoken *)ptr;
+
+	signal(sig, SIG_IGN);
+	if (sig == SIGINT)
+		cleanup_netns(token);
+	return 0;
+}
+
 struct nstoken *create_netns(const char *name)
 {
 	struct nstoken *token = NULL;
@@ -539,6 +549,8 @@ struct nstoken *create_netns(const char *name)
 		goto fail;
 	}
 
+	signal(SIGINT, (__sighandler_t)netns_sig_handler);
+	netns_sig_handler(SIGUSR1, (void *)token);
 	return token;
 
 fail:
Signature · 1 line
2.43.0
maintainer
#2 lore raw

Re: [PATCH mptcp-next 1/3] selftests/bpf: Handle SIGINT when creating netns

Hi Geliang,

Quoted 4 lines · Geliang Tang

From: Geliang Tang <[email protected]>

It's necessary to delete netns during BPF selftests interrupt, otherwise the next tests run will fail due to unable to create netns.

I think this patch can be part of the series you sent to BPF maintainers, because that's not specific to MPTCP, no? (If yes, don't forget to wait 24h between posting).

Or do you send it here to have a pre-review? If yes, please see below:

Quoted 8 lines

This patch adds a new SIGINT handle netns_sig_handler() in create_netns(), and deletes NS_TEST in this handler.

For passing argument to signal handler, a trick mentioned in [1] is used.

[1]
https://stackoverflow.com/questions/6970224/providing-passing-argument-to-signal-handler

Interesting!

I guess you are referring to this answer, right?

(instead of sharing the link to the question with multiple answers)

Quoted 27 lines
---
 tools/testing/selftests/bpf/network_helpers.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
tools/testing/selftests/bpf/network_helpers.c +10 -0
index 0b25b008f4f6..7e233b8c75d9 100644
@@ -519,6 +519,16 @@ void cleanup_netns(struct nstoken *token)
 	close_netns(token);
 }
 
+static int netns_sig_handler(const int sig, void *ptr)
+{
+	struct nstoken *token = (struct nstoken *)ptr;
+
+	signal(sig, SIG_IGN);
+	if (sig == SIGINT)
+		cleanup_netns(token);
+	return 0;
+}
+
 struct nstoken *create_netns(const char *name)
 {
 	struct nstoken *token = NULL;

tools/testing/selftests/bpf/network_helpers.c struct nstoken *create_netns(const char *name) · line 553

Quoted 5 lines
tools/testing/selftests/bpf/network_helpers.c +2 -0
@@ -539,6 +549,8 @@ struct nstoken *create_netns(const char *name)
 		goto fail;
 	}
 
+	signal(SIGINT, (__sighandler_t)netns_sig_handler);
+	netns_sig_handler(SIGUSR1, (void *)token);

It doesn't look like it will work with multiple netns per test, right? It sounds a bit restricting to limit to only one netns. Or the helper name should be clearer about that: create_netns_single()? (not even sure people will understand this helper can only be used if there is only one netns to create...)

Can you not use an array (xfrm_info.c seems to be the one creating the
maximum: 3) or a list in a global variable instead?

tools/testing/selftests/bpf/network_helpers.c struct nstoken *create_netns(const char *name) · line 556

Quoted 3 lines
tools/testing/selftests/bpf/network_helpers.c +0 -0
 	return token;
 
 fail:

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author reviewer
#3 lore raw

PATCH 2/3 Squash to "selftests/bpf: Add mptcp subflow subtest"

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

create_netns() is updated in "bpf-next add netns helpers" series, test_subflow() needs to be updated too.

That means v3 of "selftests/bpf: new MPTCP subflow subtest" cannot be sent to bpf-next at the moment until this "bpf-next add netns helpers" series is accepted.

---
 tools/testing/selftests/bpf/prog_tests/mptcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +1 -1
index c7f61fd9e7a5..a4863328d2c7 100644
@@ -418,7 +418,7 @@ static void test_subflow(void)
 	if (!ASSERT_OK(err, "prog_attach"))
 		goto skel_destroy;
 
-	nstoken = create_netns();
+	nstoken = create_netns(NS_TEST);
 	if (!ASSERT_OK_PTR(nstoken, "create_netns: mptcp_subflow"))
 		goto skel_destroy;
 
Signature · 1 line
2.43.0
author reviewer
#4 lore raw

PATCH 3/3 Squash to "selftests/bpf: Add bpf scheduler test"

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

create_netns() is updated in "bpf-next add netns helpers" series, sched_init() needs to be updated too.

---
 tools/testing/selftests/bpf/prog_tests/mptcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +1 -1
index a4863328d2c7..1b2ffc5211ea 100644
@@ -439,7 +439,7 @@ static struct nstoken *sched_init(char *flags, char *sched)
 {
 	struct nstoken *nstoken;
 
-	nstoken = create_netns();
+	nstoken = create_netns(NS_TEST);
 	if (!ASSERT_OK_PTR(nstoken, "create_netns"))
 		return NULL;
 
Signature · 1 line
2.43.0