[4/4] zdtm: check mounts of external devices

Submitted by Andrei Vagin on April 22, 2016, 5:58 a.m.

Details

Message ID 1461304725-25889-4-git-send-email-avagin@openvz.org
State Rejected
Series "Series without cover letter"
Headers show

Patch hide | download patch | download mbox

diff --git a/test/Makefile b/test/Makefile
index 0c68a86..22fcf71 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -11,7 +11,7 @@  all:
 	$(MAKE) zdtm-freezer
 .PHONY: all
 
-TESTS = unix-callback mem-snap rpc libcriu mounts/ext security pipes crit socketpairs overlayfs
+TESTS = unix-callback mem-snap rpc libcriu mounts/ext security pipes crit socketpairs overlayfs mnt-ext-dev
 
 other:
 	for t in $(TESTS); do				\
diff --git a/test/others/mnt-ext-dev/Makefile b/test/others/mnt-ext-dev/Makefile
new file mode 100644
index 0000000..7779a99
--- /dev/null
+++ b/test/others/mnt-ext-dev/Makefile
@@ -0,0 +1,2 @@ 
+run:
+	./run.sh
diff --git a/test/others/mnt-ext-dev/run.sh b/test/others/mnt-ext-dev/run.sh
new file mode 100755
index 0000000..368c03d
--- /dev/null
+++ b/test/others/mnt-ext-dev/run.sh
@@ -0,0 +1,17 @@ 
+#!/bin/sh
+set -e -x
+
+# construct root
+python ../../zdtm.py run -t zdtm/static/env00 --iter 0 -f ns
+
+truncate -s 0 zdtm.loop
+truncate -s 50M zdtm.loop
+mkfs.ext4 zdtm.loop
+dev=`losetup --find --show zdtm.loop`
+mkdir -p ../../dev
+cp -ap $dev ../../dev
+export ZDTM_MNT_EXT_DEV=$dev
+python ../../zdtm.py run -t zdtm/static/mnt_ext_dev || ret=$?
+losetup -d $dev
+unlink zdtm.loop
+exit $ret
diff --git a/test/zdtm.py b/test/zdtm.py
index 87904d7..e10fcef 100755
--- a/test/zdtm.py
+++ b/test/zdtm.py
@@ -414,10 +414,10 @@  class zdtm_test:
 		return opts
 
 	def getdopts(self):
-		return self.__getcropts() + self.__freezer.getdopts()
+		return self.__getcropts() + self.__freezer.getdopts() + self.__desc.get('dopts', '').split()
 
 	def getropts(self):
-		return self.__getcropts() + self.__freezer.getropts()
+		return self.__getcropts() + self.__freezer.getropts() + self.__desc.get('ropts', '').split()
 
 	def gone(self, force = True):
 		if not self.auto_reap:
diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index 2811bac..dd15f4a 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -234,6 +234,7 @@  TST_DIR		=				\
 		unlink_regular00		\
 		autofs				\
 		mnt_enablefs			\
+		mnt_ext_dev			\
 
 TST_DIR_FILE	=				\
 		chroot				\
diff --git a/test/zdtm/static/mnt_ext_dev.c b/test/zdtm/static/mnt_ext_dev.c
new file mode 100644
index 0000000..7c3bd56
--- /dev/null
+++ b/test/zdtm/static/mnt_ext_dev.c
@@ -0,0 +1,106 @@ 
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+
+#include <linux/limits.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc	= "Check mounts of external devices";
+const char *test_author	= "Andrei Vagin <avagin@virtuozzo.com";
+
+char *dirname;
+TEST_OPTION(dirname, string, "directory name", 1);
+
+int main(int argc, char **argv)
+{
+	char *loop, fd, dfd, fd2;
+	test_init(argc, argv);
+	struct stat st, stp, st2;
+	char dname[PATH_MAX], dname2[PATH_MAX];
+
+	snprintf(dname, sizeof(dname), "%s/test_dir", dirname);
+	snprintf(dname2, sizeof(dname2), "%s/test_dir2", dirname);
+
+	mkdir(dirname, 0777);
+	loop = getenv("ZDTM_MNT_EXT_DEV");
+	if (loop == NULL)
+		return 1;
+
+	if (mount(loop, dirname, "ext4", 0, NULL) == -1) {
+		pr_perror("mount");
+		return -1;
+	}
+
+	dfd = open(dirname, O_RDONLY);
+	if (dfd < 0) {
+		pr_perror("open");
+		return -1;
+	}
+
+	fd = openat(dfd, "test_file", O_RDWR | O_CREAT, 0666);
+	if (fd < 0) {
+		pr_perror("open");
+		return -1;
+	}
+
+	if (fstat(fd, &st) < 0) {
+		pr_perror("stat");
+		return 1;
+	}
+
+	mkdir(dname, 0777);
+	mkdir(dname2, 0777);
+
+	if (mount(dname, dname2, NULL, MS_BIND, NULL)) {
+		pr_perror("mount");
+		return 1;
+	}
+	fd2 = openat(dfd, "test_dir2/test_file2", O_RDWR | O_CREAT, 0666);
+	if (fd2 < 0) {
+		pr_perror("open");
+		return -1;
+	}
+
+	if (fstat(fd2, &st2) < 0) {
+		pr_perror("stat");
+		return 1;
+	}
+
+	test_daemon();
+	test_waitsig();
+
+	if (fstat(fd, &stp) < 0) {
+		pr_perror("stat");
+		return 1;
+	}
+
+	if (st.st_ino != stp.st_ino) {
+		fail("file1");
+		return 1;
+	}
+
+	if (fstat(fd2, &stp) < 0) {
+		pr_perror("stat");
+		return 1;
+	}
+
+	if (st2.st_ino != stp.st_ino) {
+		fail("file2");
+		return 1;
+	}
+
+	if (umount2(dname2, MNT_DETACH)) {
+		pr_perror("umount");
+		return 1;
+	}
+
+	pass();
+
+	return 0;
+}
diff --git a/test/zdtm/static/mnt_ext_dev.desc b/test/zdtm/static/mnt_ext_dev.desc
new file mode 100644
index 0000000..6382479
--- /dev/null
+++ b/test/zdtm/static/mnt_ext_dev.desc
@@ -0,0 +1,6 @@ 
+os.getenv("ZDTM_MNT_EXT_DEV") and \
+( lambda dev, rdev:
+{'flavor': 'ns', 'feature': 'mnt_id', "flags": "suid",
+"dopts": "--ext-mount-map dev[%d/%d]:loop" % (os.major(rdev), os.minor(rdev)),
+"ropts": "--ext-mount-map loop:%s" % dev,
+} ) (os.getenv("ZDTM_MNT_EXT_DEV"), os.stat(os.getenv("ZDTM_MNT_EXT_DEV")).st_rdev) or {'flags': 'noauto'}