[CRIU] [PATCH 2/2] zdtm: don't destruct an external mount-namespace

Andrey Vagin avagin at openvz.org
Fri Jul 5 01:19:55 EDT 2013


Before doing something with mounts they should be marked as private,
otherwise our actions can affects someone else.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 test/zdtm/live/static/mountpoints.c | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/test/zdtm/live/static/mountpoints.c b/test/zdtm/live/static/mountpoints.c
index d7ab190..ddd45d2 100644
--- a/test/zdtm/live/static/mountpoints.c
+++ b/test/zdtm/live/static/mountpoints.c
@@ -1,3 +1,4 @@
+#include <stdbool.h>
 #include <string.h>
 #include <fcntl.h>
 #include <unistd.h>
@@ -18,11 +19,8 @@ static int test_fn(int argc, char **argv)
 	FILE *f;
 	int fd, tmpfs_fd;
 	unsigned fs_cnt, fs_cnt_last = 0;
+	bool private = false;
 
-	if (mount("none", "/", "none", MS_REC|MS_PRIVATE, NULL)) {
-		err("Can't remount root with MS_PRIVATE");
-		return -1;
-	}
 again:
 	fs_cnt = 0;
 	f = fopen("/proc/self/mountinfo", "r");
@@ -41,18 +39,31 @@ again:
 		end = strchr(mp, ' ');
 		*end = '\0';
 
-		if (!strcmp(mp, "/"))
-			continue;
-		if (!strcmp(mp, "/proc"))
-			continue;
-
-		if (umount(mp))
-			test_msg("umount(`%s') failed: %m\n", mp);
+		if (private) {
+			if (!strcmp(mp, "/"))
+				continue;
+			if (!strcmp(mp, "/proc"))
+				continue;
+
+			if (umount(mp))
+				test_msg("umount(`%s') failed: %m\n", mp);
+		} else {
+			/* mount --make-rprivate / */
+			if (mount("none", mp, "none", MS_REC|MS_PRIVATE, NULL)) {
+				err("Can't remount %s with MS_PRIVATE", mp);
+				return -1;
+			}
+		}
 		fs_cnt++;
 	}
 
 	fclose(f);
 
+	if (!private) {
+		private = true;
+		goto again;
+	}
+
 	if (fs_cnt == 0)
 		goto done;
 
-- 
1.8.3.1



More information about the CRIU mailing list