Skip to content

Commit

Permalink
testcases/lib: Fix tst_ns_* helpers
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
metan-ucw authored and pevik committed Jan 17, 2025
1 parent 5bd7355 commit 02d5e99
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
15 changes: 6 additions & 9 deletions testcases/lib/tst_ns_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@
#include "tst_test.h"
#include "tst_ns_common.h"

extern struct tst_test *tst_test;

static struct tst_test test = {
.forks_child = 1, /* Needed by SAFE_CLONE */
};

static void print_help(void)
{
int i;
Expand Down Expand Up @@ -66,8 +60,6 @@ int main(int argc, char *argv[])
return 1;
}

tst_test = &test;

while ((token = strsep(&argv[1], ","))) {
struct param *p = get_param(token);

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

pid = SAFE_CLONE(&args);
pid = tst_clone(&args);
if (pid < 0) {
printf("clone() failed");
return 1;
}

if (!pid) {
child_fn();
return 0;
Expand Down
15 changes: 6 additions & 9 deletions testcases/lib/tst_ns_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@
#include "tst_test.h"
#include "tst_ns_common.h"

extern struct tst_test *tst_test;

static struct tst_test test = {
.forks_child = 1, /* Needed by SAFE_CLONE */
};

static int ns_fd[NS_TOTAL];
static int ns_fds;

Expand Down Expand Up @@ -71,8 +65,6 @@ int main(int argc, char *argv[])
int i, status, pid;
char *token;

tst_test = &test;

if (argc < 4) {
print_help();
return 1;
Expand Down Expand Up @@ -100,7 +92,12 @@ int main(int argc, char *argv[])
for (i = 0; i < ns_fds; i++)
SAFE_SETNS(ns_fd[i], 0);

pid = SAFE_CLONE(&args);
pid = tst_clone(&args);
if (pid < 0) {
printf("clone() failed");
return 1;
}

if (!pid)
SAFE_EXECVP(argv[3], argv+3);

Expand Down

0 comments on commit 02d5e99

Please sign in to comment.