mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-26 03:25:30 +00:00
zdtm: add a test to check non-root shared bind-mounts
Signed-off-by: Andrey Vagin <avagin@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
7dbd38dbc9
commit
dfeccaddf7
3 changed files with 113 additions and 0 deletions
|
|
@ -183,6 +183,7 @@ static/cgroup01
|
|||
static/cgroup02
|
||||
ns/static/clean_mntns
|
||||
static/remap_dead_pid
|
||||
ns/static/mntns_root_bind
|
||||
"
|
||||
|
||||
TEST_CR_KERNEL="
|
||||
|
|
@ -198,6 +199,7 @@ ns/static/mntns_link_remap
|
|||
ns/static/mntns_link_ghost
|
||||
ns/static/mntns_shared_bind
|
||||
ns/static/mntns_shared_bind02
|
||||
ns/static/mntns_root_bind
|
||||
"
|
||||
else
|
||||
export ZDTM_NOSUBNS=1
|
||||
|
|
@ -247,6 +249,7 @@ ns/static/console
|
|||
ns/static/rtc
|
||||
ns/static/mntns_shared_bind
|
||||
ns/static/mntns_shared_bind02
|
||||
ns/static/mntns_root_bind
|
||||
"
|
||||
|
||||
source $(readlink -f `dirname $0`/env.sh) || exit 1
|
||||
|
|
@ -306,6 +309,7 @@ mntns_link_remap
|
|||
mntns_link_ghost
|
||||
mntns_shared_bind
|
||||
mntns_shared_bind02
|
||||
mntns_root_bind
|
||||
sockets00
|
||||
"
|
||||
|
||||
|
|
|
|||
|
|
@ -179,6 +179,7 @@ TST_DIR = \
|
|||
mntns_link_ghost \
|
||||
mntns_shared_bind \
|
||||
mntns_shared_bind02 \
|
||||
mntns_root_bind \
|
||||
|
||||
TST_DIR_FILE = \
|
||||
chroot \
|
||||
|
|
|
|||
108
test/zdtm/live/static/mntns_root_bind.c
Normal file
108
test/zdtm/live/static/mntns_root_bind.c
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
#define _GNU_SOURCE
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sched.h>
|
||||
#include <sys/wait.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "zdtmtst.h"
|
||||
|
||||
#ifndef CLONE_NEWNS
|
||||
#define CLONE_NEWNS 0x00020000
|
||||
#endif
|
||||
|
||||
const char *test_doc = "Check bind-mouns of the root mount";
|
||||
const char *test_author = "Andrew Vagin <avagin@parallels.com>";
|
||||
|
||||
char *dirname;
|
||||
TEST_OPTION(dirname, string, "directory name", 1);
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char path[PATH_MAX], bpath[PATH_MAX], spath[PATH_MAX], bspath[PATH_MAX];
|
||||
pid_t pid;
|
||||
int status;
|
||||
task_waiter_t t;
|
||||
|
||||
test_init(argc, argv);
|
||||
|
||||
task_waiter_init(&t);
|
||||
|
||||
mount(NULL, "/", NULL, MS_SHARED, NULL);
|
||||
|
||||
snprintf(path, sizeof(path), "%s/test", dirname);
|
||||
snprintf(bpath, sizeof(bpath), "%s/test.bind", dirname);
|
||||
snprintf(spath, sizeof(spath), "%s/test/sub", dirname);
|
||||
snprintf(bspath, sizeof(bspath), "%s/test.bind/sub", dirname);
|
||||
|
||||
if (mkdir(dirname, 0700) ||
|
||||
mkdir(path, 0700) ||
|
||||
mkdir(spath, 0700) ||
|
||||
mkdir(bpath, 0700)) {
|
||||
err("mkdir");
|
||||
return 1;
|
||||
}
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
err("fork");
|
||||
return 1;
|
||||
}
|
||||
if (pid == 0) {
|
||||
unshare(CLONE_NEWNS);
|
||||
if (mount(path, bpath, NULL, MS_BIND, NULL)) {
|
||||
err("mount");
|
||||
return 1;
|
||||
}
|
||||
|
||||
task_waiter_complete(&t, 1);
|
||||
task_waiter_wait4(&t, 2);
|
||||
|
||||
if (access(bspath, F_OK)) {
|
||||
fail("%s isn't accessiable", bspath);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if (umount2(bpath, MNT_DETACH)) {
|
||||
fail("umount");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
task_waiter_wait4(&t, 1);
|
||||
|
||||
if (mount("test", spath, "tmpfs", 0, NULL)) {
|
||||
err("mount");
|
||||
return 1;
|
||||
}
|
||||
|
||||
test_daemon();
|
||||
test_waitsig();
|
||||
|
||||
task_waiter_complete(&t, 2);
|
||||
|
||||
if (waitpid(pid, &status, 0) != pid) {
|
||||
err("waitpid %d", pid);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (status) {
|
||||
err("%d/%d/%d/%d", WIFEXITED(status), WEXITSTATUS(status), WIFSIGNALED(status), WTERMSIG(status));
|
||||
return 1;
|
||||
}
|
||||
|
||||
pass();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue