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

Andrey Vagin avagin at openvz.org
Tue Apr 8 16:35:08 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 | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/mount.c b/mount.c
index bcc89cd..b0508a1 100644
--- a/mount.c
+++ b/mount.c
@@ -38,6 +38,7 @@ static struct mount_info *mntinfo;
  * for umounting or path resolution.
  */
 static struct mount_info *mntinfo_tree;
+int mntns_root_pid = -1;
 int mntns_root = -1;
 
 static DIR *open_mountpoint(struct mount_info *pm);
@@ -1775,6 +1776,9 @@ int mntns_collect_root(pid_t pid)
 	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)) {
@@ -1824,6 +1828,7 @@ int mntns_collect_root(pid_t pid)
 
 set_root:
 	mntns_root = install_service_fd(ROOT_FD_OFF, fd);
+	mntns_root_pid = pid;
 	close(fd);
 	return mntns_root >= 0 ? 0 : -1;
 }
-- 
1.8.5.3



More information about the CRIU mailing list