[CRIU] [PATCH 32/37] mount: don't open the same root twise

Andrey Vagin avagin at openvz.org
Fri Apr 18 07:43:10 PDT 2014


Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 mount.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/mount.c b/mount.c
index d40a3b2..e3f0a59 100644
--- a/mount.c
+++ b/mount.c
@@ -1753,10 +1753,15 @@ out:
 
 int mntns_collect_root(pid_t pid)
 {
+	static int mntns_root_pid = -1;
+
 	int fd, pfd;
 	int ret;
 	char path[PATH_MAX + 1];
 
+	if (mntns_root_pid == pid) /* The required root is already opened */
+		return get_service_fd(ROOT_FD_OFF);
+
 	close_service_fd(ROOT_FD_OFF);
 
 	if (!(root_ns_mask & CLONE_NEWNS)) {
@@ -1805,6 +1810,8 @@ int mntns_collect_root(pid_t pid)
 
 set_root:
 	ret = install_service_fd(ROOT_FD_OFF, fd);
+	if (ret >= 0)
+		mntns_root_pid = pid;
 	close(fd);
 	return ret;
 }
-- 
1.8.5.3



More information about the CRIU mailing list