[CRIU] [PATCH 09/16] servicefd: add a service fd for current root

Andrey Vagin avagin at openvz.org
Tue Apr 8 16:35:01 PDT 2014


It's already used for dumping files and it will be used for restoring,
so it should be service fd to avoid intersection with restored
descriptors.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-restore.c        | 3 +++
 include/servicefd.h | 1 +
 mount.c             | 7 +++++--
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/cr-restore.c b/cr-restore.c
index f0688b9..cf60c32 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -2543,6 +2543,9 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
 
 	close_image_dir();
 
+	close_service_fd(PROC_FD_OFF);
+	close_service_fd(ROOT_FD_OFF);
+
 	__gcov_flush();
 
 	pr_info("task_args: %p\n"
diff --git a/include/servicefd.h b/include/servicefd.h
index f855fe8..0e1992c 100644
--- a/include/servicefd.h
+++ b/include/servicefd.h
@@ -15,6 +15,7 @@ enum sfd_type {
 			 *  For dump -- target ns' proc
 			 *  For restore -- CRIU ns' proc
 			 */
+	ROOT_FD_OFF, /* paths are resolved relative to this root */
 
 	SERVICE_FD_MAX
 };
diff --git a/mount.c b/mount.c
index 3f90e0b..9b40903 100644
--- a/mount.c
+++ b/mount.c
@@ -1753,6 +1753,8 @@ int mntns_collect_root(pid_t pid)
 	int ret;
 	char path[PATH_MAX + 1];
 
+	close_service_fd(ROOT_FD_OFF);
+
 	if (!(root_ns_mask & CLONE_NEWNS)) {
 		/*
 		 * If criu and tasks we dump live in the same mount
@@ -1798,8 +1800,9 @@ int mntns_collect_root(pid_t pid)
 	}
 
 set_root:
-	mntns_root = fd;
-	return 0;
+	mntns_root = install_service_fd(ROOT_FD_OFF, fd);
+	close(fd);
+	return mntns_root >= 0 ? 0 : -1;
 }
 
 struct ns_desc mnt_ns_desc = NS_DESC_ENTRY(CLONE_NEWNS, "mnt");
-- 
1.8.5.3



More information about the CRIU mailing list