[CRIU] [PATCH 2/2] zdtm: ghost on readonly fs

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Tue Sep 11 18:53:31 MSK 2018


Test creates two shared mounts, both are readonly, on each mount we have
a different ghost file. Also let these mounts have different mount
flags. That makes us both test do_new_mount hunk for delaying readonly
and do_bind_mount, as one mount will bind from another on restore.

https://jira.sw.ru/browse/PSBM-82991
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 test/zdtm/static/Makefile           |   1 +
 test/zdtm/static/ghost_on_rofs.c    | 179 ++++++++++++++++++++++++++++
 test/zdtm/static/ghost_on_rofs.desc |   1 +
 3 files changed, 181 insertions(+)
 create mode 100644 test/zdtm/static/ghost_on_rofs.c
 create mode 100644 test/zdtm/static/ghost_on_rofs.desc

diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index fe67747db..c311df890 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -340,6 +340,7 @@ TST_DIR		=				\
 		shared_slave_mount_children	\
 		non_uniform_share_propagation	\
 		private_bind_propagation	\
+		ghost_on_rofs			\
 
 TST_DIR_FILE	=				\
 		chroot				\
diff --git a/test/zdtm/static/ghost_on_rofs.c b/test/zdtm/static/ghost_on_rofs.c
new file mode 100644
index 000000000..6362e8334
--- /dev/null
+++ b/test/zdtm/static/ghost_on_rofs.c
@@ -0,0 +1,179 @@
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <limits.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc	= "Check ghost file on readonly fs mount restores fine";
+const char *test_author	= "Pavel Tikhomirov <ptikhomirov at virtuozzo.com>";
+
+#define GHOST_DATA "Ghost Data"
+
+char *dirname;
+TEST_OPTION(dirname, string, "directory name", 1);
+
+int main(int argc, char **argv)
+{
+	char ro_mount[PATH_MAX], ro_bind_mount[PATH_MAX];
+	char ghost_file[PATH_MAX], ghost_file_bind[PATH_MAX];
+	char buf[PATH_MAX];
+	int fd, fd_bind;
+
+	test_init(argc, argv);
+
+	if (mkdir(dirname, 0700)) {
+		pr_perror("mkdir");
+		return 1;
+	}
+
+	if (mount("zdtm_fs", dirname, "tmpfs", 0, NULL)) {
+		pr_perror("mount");
+		return 1;
+	}
+
+	if (mount(NULL, dirname, NULL, MS_PRIVATE, NULL)) {
+		pr_perror("mount");
+		return 1;
+	}
+
+	ssprintf(ro_mount, "%s/ro_mount", dirname);
+	if (mkdir(ro_mount, 0700)) {
+		pr_perror("mkdir");
+		return 1;
+	}
+
+	if (mount("ro_mount", ro_mount, "tmpfs", 0, NULL)) {
+		pr_perror("mount");
+		return 1;
+	}
+
+	/*
+	 * Need shared mount to check the hunk in do_bind_mount, we
+	 * would have ro_bind_mount binded from ro_mount or vice versa.
+	 */
+	if (mount(NULL, ro_mount, NULL, MS_SHARED, NULL)) {
+		pr_perror("mount");
+		return 1;
+	}
+
+	ssprintf(ro_bind_mount, "%s/ro_bind_mount", dirname);
+	if (mkdir(ro_bind_mount, 0700)) {
+		pr_perror("mkdir");
+		return 1;
+	}
+
+	if (mount(ro_mount, ro_bind_mount, NULL, MS_BIND, NULL)) {
+		pr_perror("mount");
+		return 1;
+	}
+
+	ssprintf(ghost_file, "%s/ghost_file", ro_mount);
+	fd = open(ghost_file, O_CREAT|O_WRONLY, 0600);
+	if (fd < 0) {
+		pr_perror("open");
+		return 1;
+	}
+
+	if (write(fd, GHOST_DATA, sizeof(GHOST_DATA)) != sizeof(GHOST_DATA)) {
+		pr_perror("write");
+		return 1;
+	}
+
+	ssprintf(ghost_file_bind, "%s/ghost_file_bind", ro_bind_mount);
+	fd_bind = open(ghost_file_bind, O_CREAT|O_WRONLY, 0600);
+	if (fd_bind < 0) {
+		pr_perror("open");
+		return 1;
+	}
+
+	if (write(fd_bind, GHOST_DATA, sizeof(GHOST_DATA)) != sizeof(GHOST_DATA)) {
+		pr_perror("write");
+		return 1;
+	}
+
+	close(fd);
+	close(fd_bind);
+
+	fd = open(ghost_file, O_RDONLY);
+	if (fd < 0) {
+		pr_perror("open");
+		return 1;
+	}
+
+	fd_bind = open(ghost_file_bind, O_RDONLY);
+	if (fd_bind < 0) {
+		pr_perror("open");
+		return 1;
+	}
+
+	if (unlink(ghost_file)) {
+		pr_perror("unlink %s", ghost_file);
+		return 1;
+	}
+
+	if (unlink(ghost_file_bind)) {
+		pr_perror("unlink %s", ghost_file_bind);
+		return 1;
+	}
+
+	if (mount(NULL, ro_mount, NULL, MS_RDONLY|MS_REMOUNT|MS_BIND, NULL)) {
+		pr_perror("mount");
+		return 1;
+	}
+
+	/*
+	 * Need MS_NOSUID flag to check the hunk in do_bind_mount, case of
+	 * different flags for mount and it's ->bind
+	 */
+	if (mount(NULL, ro_bind_mount, NULL, MS_NOSUID|MS_RDONLY|MS_REMOUNT|MS_BIND, NULL)) {
+		pr_perror("mount");
+		return 1;
+	}
+
+	test_daemon();
+	test_waitsig();
+
+	if (read(fd, buf, sizeof(GHOST_DATA)) != sizeof(GHOST_DATA)) {
+		fail("Can't read from ghost file");
+		return 1;
+	}
+
+	if (strcmp(buf, GHOST_DATA)) {
+		fail("Wrong data in a ghost file");
+		return 1;
+	}
+
+	if (read(fd_bind, buf, sizeof(GHOST_DATA)) != sizeof(GHOST_DATA)) {
+		fail("Can't read from ghost file");
+		return 1;
+	}
+
+	if (strcmp(buf, GHOST_DATA)) {
+		fail("Wrong data in a ghost file");
+		return 1;
+	}
+
+	close(fd);
+	close(fd_bind);
+
+	if (umount(ro_bind_mount)) {
+		pr_perror("Unable to umount %s", ro_bind_mount);
+		return 1;
+	}
+
+	if (umount(ro_mount)) {
+		pr_perror("Unable to umount %s", ro_mount);
+		return 1;
+	}
+
+	if (umount(dirname)) {
+		pr_perror("Unable to umount %s", dirname);
+		return 1;
+	}
+
+	pass();
+
+	return 0;
+}
diff --git a/test/zdtm/static/ghost_on_rofs.desc b/test/zdtm/static/ghost_on_rofs.desc
new file mode 100644
index 000000000..7657ba45c
--- /dev/null
+++ b/test/zdtm/static/ghost_on_rofs.desc
@@ -0,0 +1 @@
+{'flavor': 'ns uns', 'flags': 'suid'}
-- 
2.17.1



More information about the CRIU mailing list