[CRIU] [PATCH 9/9] zdtm: add a test to check non-root shared bind-mounts
Andrey Vagin
avagin at openvz.org
Thu Oct 23 06:49:07 PDT 2014
Here is an example from a fedora container:
65 64 252:0 /vz/private/1 / rw,relatime shared:29 - ext4 /dev/mapper/centos_pcs-root rw,data=ordered
77 65 252:0 /vz/private/1/var/tmp/systemd-httpd.service-XLnJPNc/tmp /var/tmp rw,relatime shared:41 - ext4 /dev/mapper/centos_pcs-root rw,data=ordered
We can see non-root shared mount, which is mounted to the root
mount from the same shared group. The test emulates this situation.
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
test/zdtm.sh | 3 +
test/zdtm/live/static/Makefile | 1 +
test/zdtm/live/static/mntns_root_bind.c | 106 ++++++++++++++++++++++++++++++++
3 files changed, 110 insertions(+)
create mode 100644 test/zdtm/live/static/mntns_root_bind.c
diff --git a/test/zdtm.sh b/test/zdtm.sh
index 9a2c188..e910621 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -181,6 +181,7 @@ static/cgroup01
static/cgroup02
ns/static/clean_mntns
static/remap_dead_pid
+ns/static/mntns_root_bind
"
TEST_CR_KERNEL="
@@ -232,6 +233,7 @@ deleted_dev
mntns_open
mntns_link_remap
mntns_link_ghost
+mntns_root_bind
sockets00
"
@@ -509,6 +511,7 @@ run_test()
echo "Execute $test"
start_test $tdir $tname || return 1
+ read
if [ $START_ONLY -eq 1 ]; then
echo "Test is started"
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index e9cac39..00104dd 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -175,6 +175,7 @@ TST_DIR = \
mntns_open \
mntns_link_remap \
mntns_link_ghost \
+ mntns_root_bind \
TST_DIR_FILE = \
chroot \
diff --git a/test/zdtm/live/static/mntns_root_bind.c b/test/zdtm/live/static/mntns_root_bind.c
new file mode 100644
index 0000000..2ab5837
--- /dev/null
+++ b/test/zdtm/live/static/mntns_root_bind.c
@@ -0,0 +1,106 @@
+#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 that mnt_id is repsected";
+const char *test_author = "Pavel Emelianov <xemul at 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];
+ 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);
+ 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 (umount(bpath)) {
+ 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();
+
+ if (umount(spath)) {
+ fail("umount");
+ return 1;
+ }
+ 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;
+}
--
1.9.3
More information about the CRIU
mailing list