[CRIU] [PATCH 2/2] zdtm: check read-only tempfs mount

Andrey Vagin avagin at openvz.org
Tue Sep 22 01:59:53 PDT 2015


From: Andrew Vagin <avagin at openvz.org>

Signed-off-by: Andrew Vagin <avagin at openvz.org>
---
 test/zdtm.sh                      |  2 +
 test/zdtm/live/static/Makefile    |  1 +
 test/zdtm/live/static/tempfs_ro.c | 78 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 81 insertions(+)
 create mode 100644 test/zdtm/live/static/tempfs_ro.c

diff --git a/test/zdtm.sh b/test/zdtm.sh
index ba37265..ba42b77 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -192,6 +192,7 @@ generate_test_list()
 		ns/static/session00
 		ns/static/session01
 		ns/static/tempfs
+		ns/static/tempfs_ro
 		ns/static/mnt_ro_bind
 		ns/static/mount_paths
 		ns/static/bind-mount
@@ -334,6 +335,7 @@ vt
 rtc
 maps007
 tempfs
+tempfs_ro
 mnt_ro_bind
 bind-mount
 mountpoints
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index 7a97b0e..812f0e1 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -186,6 +186,7 @@ TST_DIR		=				\
 		overmount_fifo			\
 		overmount_sock			\
 		tempfs				\
+		tempfs_ro			\
 		mnt_ro_bind			\
 		mount_paths			\
 		bind-mount			\
diff --git a/test/zdtm/live/static/tempfs_ro.c b/test/zdtm/live/static/tempfs_ro.c
new file mode 100644
index 0000000..ff421e2
--- /dev/null
+++ b/test/zdtm/live/static/tempfs_ro.c
@@ -0,0 +1,78 @@
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <linux/limits.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc	= "Check read-only tmpfs mount";
+const char *test_author	= "Andrew Vagin <avagin at openvz.org>";
+
+char *dirname;
+TEST_OPTION(dirname, string, "directory name", 1);
+
+#define TEST_WORD	"testtest"
+
+int main(int argc, char **argv)
+{
+	int fd, ret = 1;
+	char buf[1024], fname[PATH_MAX];
+
+	test_init(argc, argv);
+
+	mkdir(dirname, 0700);
+	if (mount("none", dirname, "tmpfs", 0, "") < 0) {
+		fail("Can't mount tmpfs");
+		return 1;
+	}
+
+	snprintf(fname, sizeof(buf), "%s/test.file", dirname);
+	fd = open(fname, O_RDWR | O_CREAT, 0644);
+	if (fd < 0) {
+		err("open failed");
+		goto err;
+	}
+
+	if (write(fd, TEST_WORD, sizeof(TEST_WORD)) != sizeof(TEST_WORD)) {
+		err("write() failed");
+		goto err;
+	}
+	close(fd);
+
+	if (mount(NULL, dirname, "tmpfs", MS_REMOUNT | MS_RDONLY, NULL) < 0) {
+		fail("Can't mount tmpfs");
+		return 1;
+	}
+
+	test_daemon();
+	test_waitsig();
+
+
+	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 err;
+	}
+	close(fd);
+
+	if (strcmp(buf, TEST_WORD)) {
+		fail("File corrupted");
+		goto err;
+	}
+
+	pass();
+	ret = 0;
+err:
+	umount2(dirname, MNT_DETACH);
+	rmdir(dirname);
+	return ret;
+}
-- 
2.4.3



More information about the CRIU mailing list