diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile index 766774d43..2f60c951c 100644 --- a/test/zdtm/static/Makefile +++ b/test/zdtm/static/Makefile @@ -238,6 +238,7 @@ TST_DIR = \ cgroup04 \ cgroup_stray \ unlink_fstat04 \ + mntns_remap \ mntns_open \ mntns_link_remap \ mntns_ghost \ diff --git a/test/zdtm/static/mntns_remap.c b/test/zdtm/static/mntns_remap.c new file mode 100644 index 000000000..f7cdba443 --- /dev/null +++ b/test/zdtm/static/mntns_remap.c @@ -0,0 +1,101 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "zdtmtst.h" + +const char *test_doc = "Check a case when one mount overmount another one"; +const char *test_author = "Andrew Vagin "; + +char *dirname; +TEST_OPTION(dirname, string, "directory name", 1); + +int main(int argc, char **argv) +{ + task_waiter_t t; + pid_t pid; + + test_init(argc, argv); + + mkdir(dirname, 0755); + if (mount("zdtm", dirname, "tmpfs", 0, NULL)) { + pr_perror("mount"); + return 1; + } + if (chdir(dirname)) { + pr_perror("chdir"); + return 1; + } + mkdir("1", 0755); + mkdir("2", 0755); + if (mount("1", "1", NULL, MS_BIND, NULL)) { + pr_perror("mount"); + return 1; + } + if (mount(NULL, "1", NULL, MS_PRIVATE, NULL)) { + pr_perror("mount"); + return 1; + } + if (mount("zdtm", "2", "tmpfs", 0, NULL)) { + pr_perror("mount"); + return 1; + } + mkdir("1/a", 0755); + mkdir("2/a", 0755); + if (mount("1/a", "1/a", NULL, MS_BIND, NULL)) { + pr_perror("mount"); + return 1; + } + if (mount(NULL, "1/a", NULL, MS_SHARED, NULL)) { + pr_perror("mount"); + return 1; + } + if (mount("1/a", "2/a", NULL, MS_BIND, NULL)) { + pr_perror("mount"); + return 1; + } + mkdir("1/a/c", 0755); + if (mount("zdtm", "1/a/c", "tmpfs", 0, NULL)) { + pr_perror("mount"); + return 1; + } + if (mount("2", "1", NULL, MS_MOVE, NULL)) { + pr_perror("mount"); + return 1; + } + + task_waiter_init(&t); + + pid = fork(); + if (pid < 0) + return -1; + + if (pid == 0) { + if (unshare(CLONE_NEWNS)) + return 1; + task_waiter_complete_current(&t); + test_waitsig(); + return 0; + } + + task_waiter_wait4(&t, pid); + test_daemon(); + test_waitsig(); + + kill(pid, SIGTERM); + wait(NULL); + + pass(); + + return 0; +} diff --git a/test/zdtm/static/mntns_remap.desc b/test/zdtm/static/mntns_remap.desc new file mode 100644 index 000000000..3fd8e03f7 --- /dev/null +++ b/test/zdtm/static/mntns_remap.desc @@ -0,0 +1 @@ +{'flavor': 'ns', 'flags': 'suid', 'feature': 'mnt_id'}