[CRIU] [PATCH 4/4] test: mount -- Add simple testcase for deleted bindmounts

Cyrill Gorcunov gorcunov at openvz.org
Mon Aug 17 13:09:49 PDT 2015


Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 test/zdtm.sh                          |  2 +
 test/zdtm/live/static/Makefile        |  1 +
 test/zdtm/live/static/mntns_deleted.c | 75 +++++++++++++++++++++++++++++++++++
 3 files changed, 78 insertions(+)
 create mode 100644 test/zdtm/live/static/mntns_deleted.c

diff --git a/test/zdtm.sh b/test/zdtm.sh
index d0e945b92fac..feece7c05db6 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -218,6 +218,7 @@ generate_test_list()
 		ns/static/mntns_shared_bind
 		ns/static/mntns_shared_bind02
 		ns/static/mntns_root_bind
+		ns/static/mntns_deleted
 	"
 
 	TEST_AIO="
@@ -340,6 +341,7 @@ mntns_shared_bind
 mntns_shared_bind02
 mntns_root_bind
 mntns_rw_ro_rw
+mntns_deleted
 mount_paths
 netns-dev
 sockets00
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index c57308802a0d..dcde0d77ab2d 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -197,6 +197,7 @@ TST_DIR		=				\
 		mntns_root_bind			\
 		mnt_ext_auto			\
 		mnt_ext_master			\
+		mntns_deleted			\
 
 TST_DIR_FILE	=				\
 		chroot				\
diff --git a/test/zdtm/live/static/mntns_deleted.c b/test/zdtm/live/static/mntns_deleted.c
new file mode 100644
index 000000000000..bd1a58b6dc27
--- /dev/null
+++ b/test/zdtm/live/static/mntns_deleted.c
@@ -0,0 +1,75 @@
+#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 the restore of deleted bindmounts";
+const char *test_author	= "Cyrill Gorcunov <gorcunov at openvz.org>";
+
+char *dirname;
+TEST_OPTION(dirname, string, "directory name", 1);
+
+#define TEST_DIR_SRC	"test-src"
+#define TEST_DIR_DST	"test-dst"
+
+int main(int argc, char *argv[])
+{
+	char path_src[PATH_MAX], path_dst[PATH_MAX];
+
+	test_init(argc, argv);
+
+	if (mkdir(dirname, 0700)) {
+		err("mkdir %s", dirname);
+		exit(1);
+	}
+
+	if (mount("none", dirname, "tmpfs", MS_MGC_VAL, NULL)) {
+		err("mount %s", dirname);
+		return 1;
+	}
+
+	snprintf(path_src, sizeof(path_src), "%s/%s", dirname, TEST_DIR_SRC);
+	snprintf(path_dst, sizeof(path_dst), "%s/%s", dirname, TEST_DIR_DST);
+
+	rmdir(path_src);
+	rmdir(path_dst);
+
+	if (mkdir(path_src, 0700) ||
+	    mkdir(path_dst, 0700)) {
+		err("mkdir");
+		return 1;
+	}
+
+	if (mount(path_src, path_dst, NULL, MS_BIND | MS_MGC_VAL, NULL)) {
+		err("mount %s -> %s", path_src, path_dst);
+		return 1;
+	}
+
+	if (rmdir(path_src)) {
+		err("rmdir %s", path_src);
+		return 1;
+	}
+
+	test_daemon();
+	test_waitsig();
+
+	pass();
+	return 0;
+}
-- 
2.4.3



More information about the CRIU mailing list