[CRIU] [PATCH 4/4] zdtm/tempfs: check that overmounted parts are restored

Andrey Vagin avagin at openvz.org
Mon Feb 24 00:04:50 PST 2014


Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 test/zdtm.sh                   |  2 ++
 test/zdtm/live/static/tempfs.c | 43 ++++++++++++++++++++++++++++--------------
 2 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/test/zdtm.sh b/test/zdtm.sh
index 6f0f964..ac6b974 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -122,6 +122,7 @@ static/pty03
 static/mountpoints
 ns/static/session00
 ns/static/session01
+ns/static/tempfs
 static/utsname
 static/ipc_namespace
 static/shm
@@ -156,6 +157,7 @@ chroot-file
 rtc
 tempfs
 maps007
+tempfs
 "
 
 source $(readlink -f `dirname $0`/env.sh) || exit 1
diff --git a/test/zdtm/live/static/tempfs.c b/test/zdtm/live/static/tempfs.c
index fd5e711..779fd0d 100644
--- a/test/zdtm/live/static/tempfs.c
+++ b/test/zdtm/live/static/tempfs.c
@@ -4,6 +4,7 @@
 #include <unistd.h>
 #include <sys/mount.h>
 #include <sys/stat.h>
+#include <linux/limits.h>
 
 #include "zdtmtst.h"
 
@@ -18,7 +19,7 @@ TEST_OPTION(dirname, string, "directory name", 1);
 int main(int argc, char **argv)
 {
 	int fd, ret = 1;
-	char buf[1024];
+	char buf[1024], fname[PATH_MAX], overmount[PATH_MAX];
 
 	test_init(argc, argv);
 
@@ -28,43 +29,57 @@ int main(int argc, char **argv)
 		return 1;
 	}
 
-	snprintf(buf, sizeof(buf), "%s/test", dirname);
-	fd = open(buf, O_RDWR | O_CREAT);
+	snprintf(overmount, sizeof(buf), "%s/test", dirname);
+	mkdir(overmount, 0700);
+
+	snprintf(fname, sizeof(buf), "%s/test.file", overmount);
+	fd = open(fname, O_RDWR | O_CREAT);
 	if (fd < 0) {
 		err("open failed");
-		goto outum;
+		goto err;
 	}
 
 	if (write(fd, TEST_WORD, sizeof(TEST_WORD)) != sizeof(TEST_WORD)) {
 		err("write() failed");
-		goto outuc;
+		goto err;
+	}
+	close(fd);
+
+	if (mount("none", overmount, "tmpfs", 0, "") < 0) {
+		fail("Can't mount tmpfs");
+		goto err;
 	}
 
 	test_daemon();
 	test_waitsig();
 
-	if (lseek(fd, 0, SEEK_SET) < 0) {
-		fail("Seek failed");
-		goto outuc;
+	if (umount(overmount) < 0) {
+		fail("Can't mount tmpfs");
+		goto err;
+	}
+
+	fd = open(fname, O_RDONLY);
+	if (fd < 0) {
+		err("open failed");
+		goto err;
 	}
 
 	buf[sizeof(TEST_WORD) + 1] = '\0';
 	if (read(fd, buf, sizeof(TEST_WORD)) != sizeof(TEST_WORD)) {
 		fail("Read failed");
-		goto outuc;
+		goto err;
 	}
+	close(fd);
 
 	if (strcmp(buf, TEST_WORD)) {
 		fail("File corrupted");
-		goto outuc;
+		goto err;
 	}
 
 	pass();
 	ret = 0;
-outuc:
-	close(fd);
-outum:
-	umount(dirname);
+err:
+	umount2(dirname, MNT_DETACH);
 	rmdir(dirname);
 	return ret;
 }
-- 
1.8.5.3



More information about the CRIU mailing list