Skip to content

Commit

Permalink
zdtm: make ns_file_bindmount parent/child sync with futex
Browse files Browse the repository at this point in the history
This is a preparation for a next patch, previousely we needed child to
fork only, now to w/a ip route bug we want to set lo link up in child,
and we need to wait for it.

https://jira.sw.ru/browse/PSBM-123769
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>

Feature: NSFS bindmounts
  • Loading branch information
Snorch committed Apr 26, 2023
1 parent a034a15 commit d5ce54e
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions test/zdtm/static/ns_file_bindmount.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mount.h>
#include <sys/mman.h>
#include <linux/limits.h>

#include "zdtmtst.h"
#include "lock.h"
#include "fs.h"

const char *test_doc = "Check namespace file (/proc/pid/ns/name) bindmounts";
Expand All @@ -18,10 +20,19 @@ const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>";
char *dirname = "ns_file_bindmount";
TEST_OPTION(dirname, string, "directory name", 1);

enum {
FUTEX_INITIALIZED = 0,
CHILD_READY,
TEST_FINISH,
EMERGENCY_ABORT,
};

futex_t *futex;

static int child(void *unused)
{
while (1)
sleep(1);
futex_set_and_wake(futex, CHILD_READY);
futex_wait_while_lt(futex, TEST_FINISH);
return 0;
}

Expand Down Expand Up @@ -155,17 +166,31 @@ int main(int argc, char **argv)

test_init(argc, argv);

futex = mmap(NULL, sizeof(*futex), PROT_WRITE | PROT_READ,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
if (futex == MAP_FAILED) {
pr_perror("Failed to mmap futex");
return 1;
}
futex_init(futex);

if (prepare_dirname(dirname))
return 1;

pid = clone(child, &stack[CLONE_STACK_SIZE],
pid = clone(child, &stack[CLONE_STACK_SIZE],
CLONE_NEWNET | CLONE_NEWIPC | CLONE_NEWUTS | SIGCHLD,
NULL);
if (pid == -1) {
pr_perror("Failed to clone child with nested namespaces");
return 1;
}

futex_wait_while_lt(futex, CHILD_READY);
if (futex_get(futex) == EMERGENCY_ABORT) {
pr_err("Fail in child\n");
goto err;
}

if (create_ns_bind("ipc", pid, ipc_file, ipc_bind))
goto err;
if (create_ns_bind("uts", pid, uts_file, uts_bind))
Expand Down Expand Up @@ -209,13 +234,14 @@ int main(int argc, char **argv)
pass();
ret = 0;
err:
futex_set_and_wake(futex, TEST_FINISH);
if (ipc_fd != -1)
close(ipc_fd);
if (uts_fd != -1)
close(uts_fd);
if (net_fd != -1)
close(net_fd);
kill(pid, SIGKILL);
wait(NULL);
munmap(futex, sizeof(*futex));
return ret;
}

0 comments on commit d5ce54e

Please sign in to comment.