Skip to content

Commit 02d5e99

Browse files
metan-ucwpevik
authored andcommitted
testcases/lib: Fix tst_ns_* helpers
Replaces SAFE_CLONE() with tst_clone() in the tst_ns_* helpers. The reason for the replacement is that SAFE_CLONE() uses TST_RETRY_FUNC() which calls tst_multiply_timeout(). The problem with that is that the tst_multiply_timeout() is a test library function that started to print TINFO messages recently and that we rely on parsing the output from the tst_ns_* helpers. The reason SAFE_CLONE() started to call TST_RETRY_FUNC() is that in the case that we create new namespaces with the clone call, we may end up creating them faster than kernel can clean them up which is described in: commit 7d88208 Author: Petr Vorel <[email protected]> Date: Mon Mar 28 22:46:43 2022 +0200 lib: Retry safe_clone() on ENOSPC This combined with the newly introduced changes in the test library that check for kernel debugging options that may need to adjust default timeouts: commit 893ca0a Author: Li Wang <[email protected]> Date: Sun Dec 22 15:22:49 2024 +0800 lib: multiply the timeout if detect slow kconfigs which adds tst_has_slow_kconfig() into the tst_multiply_timeout() causes the TINFO messages to be printed. The reason why we can safely replace the SAFE_CLONE() with tst_clone() here is that we are not creating new namspaces in the tst_ns_* helpers, but rather than that cloning a new process to be executed inside of the namespace, hence we do not need to retry on ENOSPC. Link: https://lore.kernel.org/ltp/[email protected]/ Reviewed-by: Li Wang <[email protected]> Reviewed-by: Petr Vorel <[email protected]> Tested-by: Petr Vorel <[email protected]> Signed-off-by: Cyril Hrubis <[email protected]>
1 parent 5bd7355 commit 02d5e99

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

testcases/lib/tst_ns_create.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@
2323
#include "tst_test.h"
2424
#include "tst_ns_common.h"
2525

26-
extern struct tst_test *tst_test;
27-
28-
static struct tst_test test = {
29-
.forks_child = 1, /* Needed by SAFE_CLONE */
30-
};
31-
3226
static void print_help(void)
3327
{
3428
int i;
@@ -66,8 +60,6 @@ int main(int argc, char *argv[])
6660
return 1;
6761
}
6862

69-
tst_test = &test;
70-
7163
while ((token = strsep(&argv[1], ","))) {
7264
struct param *p = get_param(token);
7365

@@ -80,7 +72,12 @@ int main(int argc, char *argv[])
8072
args.flags |= p->flag;
8173
}
8274

83-
pid = SAFE_CLONE(&args);
75+
pid = tst_clone(&args);
76+
if (pid < 0) {
77+
printf("clone() failed");
78+
return 1;
79+
}
80+
8481
if (!pid) {
8582
child_fn();
8683
return 0;

testcases/lib/tst_ns_exec.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020
#include "tst_test.h"
2121
#include "tst_ns_common.h"
2222

23-
extern struct tst_test *tst_test;
24-
25-
static struct tst_test test = {
26-
.forks_child = 1, /* Needed by SAFE_CLONE */
27-
};
28-
2923
static int ns_fd[NS_TOTAL];
3024
static int ns_fds;
3125

@@ -71,8 +65,6 @@ int main(int argc, char *argv[])
7165
int i, status, pid;
7266
char *token;
7367

74-
tst_test = &test;
75-
7668
if (argc < 4) {
7769
print_help();
7870
return 1;
@@ -100,7 +92,12 @@ int main(int argc, char *argv[])
10092
for (i = 0; i < ns_fds; i++)
10193
SAFE_SETNS(ns_fd[i], 0);
10294

103-
pid = SAFE_CLONE(&args);
95+
pid = tst_clone(&args);
96+
if (pid < 0) {
97+
printf("clone() failed");
98+
return 1;
99+
}
100+
104101
if (!pid)
105102
SAFE_EXECVP(argv[3], argv+3);
106103

0 commit comments

Comments
 (0)