[5/5] zdtm/mnt_ext_auto: add different bind-mounts of external mount

Submitted by Pavel Tikhomirov on March 1, 2017, 1:17 p.m.

Details

Message ID 20170301131745.22606-6-ptikhomirov@virtuozzo.com
State New
Series "mount: handle external mount bindmounts"
Headers show

Commit Message

Pavel Tikhomirov March 1, 2017, 1:17 p.m.
https://jira.sw.ru/browse/PSBM-46753
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
---
 test/zdtm/static/mnt_ext_auto.c | 71 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 70 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/test/zdtm/static/mnt_ext_auto.c b/test/zdtm/static/mnt_ext_auto.c
index 44d774b..b13e95a 100644
--- a/test/zdtm/static/mnt_ext_auto.c
+++ b/test/zdtm/static/mnt_ext_auto.c
@@ -16,9 +16,15 @@  const char *test_author	= "Andrew Vagin <avagin@gmail.com>";
 
 #ifdef ZDTM_EXTMAP_MANUAL
 char *dirname = "mnt_ext_manual.test";
+char *dirname_bind = "mnt_ext_manual_bind.test";
+char *dirname_slave_bind = "mnt_ext_manual_slave_bind.test";
+char *dirname_private_bind = "mnt_ext_manual_private_bind.test";
 #define DDIR	"mtest"
 #else
 char *dirname = "mnt_ext_auto.test";
+char *dirname_bind = "mnt_ext_auto_bind.test";
+char *dirname_slave_bind = "mnt_ext_auto_slave_bind.test";
+char *dirname_private_bind = "mnt_ext_auto_private_bind.test";
 #define DDIR	"atest"
 #endif
 TEST_OPTION(dirname, string, "directory name", 1);
@@ -26,8 +32,9 @@  TEST_OPTION(dirname, string, "directory name", 1);
 int main(int argc, char ** argv)
 {
 	char src[PATH_MAX], dst[PATH_MAX], *root;
+	char dst_bind[PATH_MAX], dst_slave_bind[PATH_MAX], dst_private_bind[PATH_MAX];
 	char *dname = "/tmp/zdtm_ext_auto.XXXXXX";
-	struct stat sta, stb;
+	struct stat sta, stb, bsta, bstb, sbsta, sbstb, pbsta, pbstb;
 	char* zdtm_newns = getenv("ZDTM_NEWNS");
 
 	root = getenv("ZDTM_ROOT");
@@ -37,6 +44,9 @@  int main(int argc, char ** argv)
 	}
 
 	sprintf(dst, "%s/%s", get_current_dir_name(), dirname);
+	sprintf(dst_bind, "%s/%s", get_current_dir_name(), dirname_bind);
+	sprintf(dst_slave_bind, "%s/%s", get_current_dir_name(), dirname_slave_bind);
+	sprintf(dst_private_bind, "%s/%s", get_current_dir_name(), dirname_private_bind);
 
 	if (!zdtm_newns) {
 		pr_perror("ZDTM_NEWNS is not set");
@@ -59,6 +69,21 @@  int main(int argc, char ** argv)
 		pr_perror("bind");
 		return 1;
 	}
+	mkdir(dst_bind, 755);
+	if (mount(dst, dst_bind, NULL, MS_BIND, NULL)) {
+		pr_perror("bind");
+		return 1;
+	}
+	mkdir(dst_slave_bind, 755);
+	if (mount(dst_bind, dst_slave_bind, NULL, MS_BIND|MS_SLAVE, NULL)) {
+		pr_perror("bind");
+		return 1;
+	}
+	mkdir(dst_private_bind, 755);
+	if (mount(dst_slave_bind, dst_private_bind, NULL, MS_BIND|MS_PRIVATE, NULL)) {
+		pr_perror("bind");
+		return 1;
+	}
 test:
 	test_init(argc, argv);
 
@@ -67,18 +92,62 @@  int main(int argc, char ** argv)
 		sleep(100);
 		return 1;
 	}
+	if (stat(dirname_bind, &bstb)) {
+		pr_perror("stat");
+		sleep(100);
+		return 1;
+	}
+	if (stat(dirname_slave_bind, &sbstb)) {
+		pr_perror("stat");
+		sleep(100);
+		return 1;
+	}
+	if (stat(dirname_private_bind, &pbstb)) {
+		pr_perror("stat");
+		sleep(100);
+		return 1;
+	}
 
 	test_daemon();
 	test_waitsig();
 
 	if (stat(dirname, &sta)) {
 		pr_perror("stat");
+		sleep(100);
+		return 1;
+	}
+	if (stat(dirname_bind, &bsta)) {
+		pr_perror("stat");
+		sleep(100);
+		return 1;
+	}
+	if (stat(dirname_slave_bind, &sbsta)) {
+		pr_perror("stat");
+		sleep(100);
+		return 1;
+	}
+	if (stat(dirname_private_bind, &pbsta)) {
+		pr_perror("stat");
+		sleep(100);
 		return 1;
 	}
+
 	if (sta.st_dev != stb.st_dev) {
 		fail();
 		return 1;
 	}
+	if (bsta.st_dev != bstb.st_dev) {
+		fail();
+		return 1;
+	}
+	if (sbsta.st_dev != sbstb.st_dev) {
+		fail();
+		return 1;
+	}
+	if (pbsta.st_dev != pbstb.st_dev) {
+		fail();
+		return 1;
+	}
 
 	pass();