[CRIU] [PATCH 27/27] mount: add a fast path for mntns_collect_root

Andrey Vagin avagin at openvz.org
Thu Apr 10 04:04:10 PDT 2014


Don't open the save root in a second time.
mntns_collect_root is called for each file, but ussually files of one
process belongs to one mount namespace.

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 870c774..28470cc 100644
--- a/mount.c
+++ b/mount.c
@@ -1781,10 +1781,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 0;
+
 	close_service_fd(ROOT_FD_OFF);
 
 	if (!(root_ns_mask & CLONE_NEWNS)) {
@@ -1836,6 +1841,8 @@ set_root:
 	ret = 0;
 	if (install_service_fd(ROOT_FD_OFF, fd) < 0)
 		ret = -1;
+	else
+		mntns_root_pid = pid;
 	close(fd);
 	return ret;
 }
-- 
1.8.5.3



More information about the CRIU mailing list