[CRIU] [PATCH 9/9] zdtm: add a test for non-uniform shares

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Tue Jul 10 19:02:31 MSK 2018


Create a tree of shared mounts where shared mounts have different sets
of children (while having the same root):

First share1 is mounted shared tmpfs and second share1/child1 is mounted
inside, third share1 is bind-mounted to share2 (now share1 and share2
have the same shared id, but share2 has no child), fourth share1/child2
is bind-mounted from share1, and also propagated to share2/child2 (now
all except share1/child1 have the same shared id), fifth share1/child3
is mounted and propagates inside the share.

Finally we have four mounts shared between each other with different
sets of children mounts, and even more two of them are children of
another two:

495 494 0:62 / /zdtm/static/non_uniform_share_propagation.test/share1 rw,relatime shared:235 - tmpfs share rw
496 495 0:63 / /zdtm/static/non_uniform_share_propagation.test/share1/child1 rw,relatime shared:236 - tmpfs child1 rw
497 494 0:62 / /zdtm/static/non_uniform_share_propagation.test/share2 rw,relatime shared:235 - tmpfs share rw
498 495 0:62 / /zdtm/static/non_uniform_share_propagation.test/share1/child2 rw,relatime shared:235 - tmpfs share rw
499 497 0:62 / /zdtm/static/non_uniform_share_propagation.test/share2/child2 rw,relatime shared:235 - tmpfs share rw
500 495 0:64 / /zdtm/static/non_uniform_share_propagation.test/share1/child3 rw,relatime shared:237 - tmpfs child3 rw
503 497 0:64 / /zdtm/static/non_uniform_share_propagation.test/share2/child3 rw,relatime shared:237 - tmpfs child3 rw
502 499 0:64 / /zdtm/static/non_uniform_share_propagation.test/share2/child2/child3 rw,relatime shared:237 - tmpfs child3 rw
501 498 0:64 / /zdtm/static/non_uniform_share_propagation.test/share1/child2/child3 rw,relatime shared:237 - tmpfs child3 rw

Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 test/zdtm/static/Makefile                     |   1 +
 .../static/non_uniform_share_propagation.c    | 131 ++++++++++++++++++
 .../static/non_uniform_share_propagation.desc |   1 +
 3 files changed, 133 insertions(+)
 create mode 100644 test/zdtm/static/non_uniform_share_propagation.c
 create mode 100644 test/zdtm/static/non_uniform_share_propagation.desc

diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index c48942eec..ef9685a4e 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -347,6 +347,7 @@ TST_DIR		=				\
 		sk-unix01			\
 		unsupported_children_collision  \
 		shared_slave_mount_children	\
+		non_uniform_share_propagation	\
 
 TST_DIR_FILE	=				\
 		chroot				\
diff --git a/test/zdtm/static/non_uniform_share_propagation.c b/test/zdtm/static/non_uniform_share_propagation.c
new file mode 100644
index 000000000..7a18247ab
--- /dev/null
+++ b/test/zdtm/static/non_uniform_share_propagation.c
@@ -0,0 +1,131 @@
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <limits.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc	= "Check non-uniform shares restore fine";
+const char *test_author	= "Pavel Tikhomirov <ptikhomirov at virtuozzo.com>";
+
+char *dirname;
+TEST_OPTION(dirname, string, "directory name", 1);
+
+int main(int argc, char **argv)
+{
+	char share1[PATH_MAX], share2[PATH_MAX];
+	char child1[PATH_MAX], child2[PATH_MAX], child3[PATH_MAX];
+
+	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;
+	}
+
+	snprintf(share1, sizeof(share1), "%s/share1", dirname);
+	if (mkdir(share1, 0700)) {
+		pr_perror("mkdir");
+		return 1;
+	}
+
+	if (mount("share", share1, "tmpfs", 0, NULL)) {
+		pr_perror("mount");
+		return 1;
+	}
+
+	if (mount(NULL, share1, NULL, MS_SHARED, NULL)) {
+		pr_perror("mount");
+		return 1;
+	}
+
+	snprintf(child1, sizeof(child1), "%s/share1/child1", dirname);
+	if (mkdir(child1, 0700)) {
+		pr_perror("mkdir");
+		return 1;
+	}
+
+	if (mount("child1", child1, "tmpfs", 0, NULL)) {
+		pr_perror("mount");
+		return 1;
+	}
+
+	snprintf(share2, sizeof(share2), "%s/share2", dirname);
+	if (mkdir(share2, 0700)) {
+		pr_perror("mkdir");
+		return 1;
+	}
+
+	if (mount(share1, share2, NULL, MS_BIND, NULL)) {
+		pr_perror("mount");
+		return 1;
+	}
+
+	snprintf(child2, sizeof(child2), "%s/share1/child2", dirname);
+	if (mkdir(child2, 0700)) {
+		pr_perror("mkdir");
+		return 1;
+	}
+
+	if (mount(share1, child2, NULL, MS_BIND, NULL)) {
+		pr_perror("mount");
+		return 1;
+	}
+
+	snprintf(child3, sizeof(child3), "%s/share1/child3", dirname);
+	if (mkdir(child3, 0700)) {
+		pr_perror("mkdir");
+		return 1;
+	}
+
+	if (mount("child3", child3, "tmpfs", 0, NULL)) {
+		pr_perror("mount");
+		return 1;
+	}
+
+	test_daemon();
+	test_waitsig();
+
+	if (umount(child3)) {
+		pr_perror("Unable to umount %s", child1);
+		return 1;
+	}
+
+	if (umount(child2)) {
+		pr_perror("Unable to umount %s", share1);
+		return 1;
+	}
+
+	if (umount(share2)) {
+		pr_perror("Unable to umount %s", share2);
+		return 1;
+	}
+
+	if (umount(child1)) {
+		pr_perror("Unable to umount %s", child1);
+		return 1;
+	}
+
+	if (umount(share1)) {
+		pr_perror("Unable to umount %s", share1);
+		return 1;
+	}
+
+	if (umount(dirname)) {
+		pr_perror("Unable to umount %s", dirname);
+		return 1;
+	}
+
+	pass();
+
+	return 0;
+}
diff --git a/test/zdtm/static/non_uniform_share_propagation.desc b/test/zdtm/static/non_uniform_share_propagation.desc
new file mode 100644
index 000000000..7657ba45c
--- /dev/null
+++ b/test/zdtm/static/non_uniform_share_propagation.desc
@@ -0,0 +1 @@
+{'flavor': 'ns uns', 'flags': 'suid'}
-- 
2.17.0



More information about the CRIU mailing list