[CRIU] [PATCH 1/8] rst: Collect procfs remaps at once

Pavel Emelyanov xemul at virtuozzo.com
Thu May 18 02:35:19 PDT 2017


There's no need in separate call to prepare_procfs_remaps().
All remaps are collected one step earlier and we can do
open_remap_dead_process() right at once.

Also rename the latter routine.

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/cr-restore.c        |  5 -----
 criu/files-reg.c         | 42 +++++++++++++-----------------------------
 criu/include/files-reg.h |  1 -
 3 files changed, 13 insertions(+), 35 deletions(-)

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 3ee7dfc..e890025 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -231,11 +231,6 @@ static int crtools_prepare_shared(void)
 	if (collect_remaps_and_regfiles())
 		return -1;
 
-	/* dead pid remap needs to allocate task helpers which all tasks need
-	 * to see */
-	if (prepare_procfs_remaps())
-		return -1;
-
 	/* Connections are unlocked from criu */
 	if (collect_inet_sockets())
 		return -1;
diff --git a/criu/files-reg.c b/criu/files-reg.c
index 9c851f4..7dbf2b8 100644
--- a/criu/files-reg.c
+++ b/criu/files-reg.c
@@ -374,7 +374,7 @@ static int open_remap_linked(struct reg_file_info *rfi,
 	return 0;
 }
 
-static int open_remap_dead_process(struct reg_file_info *rfi,
+static int collect_remap_dead_process(struct reg_file_info *rfi,
 		RemapFilePathEntry *rfe)
 {
 	struct pstree_item *helper;
@@ -436,12 +436,21 @@ static int collect_one_remap(void *obj, ProtobufCMessage *msg, struct cr_img *i)
 
 	ri->rfi = container_of(fdesc, struct reg_file_info, d);
 
-	if (rfe->remap_type == REMAP_TYPE__GHOST) {
+	switch (rfe->remap_type) {
+	case REMAP_TYPE__GHOST:
 		if (collect_remap_ghost(ri->rfi, ri->rfe))
 			return -1;
-	} else if (rfe->remap_type == REMAP_TYPE__LINKED) {
+		break;
+	case REMAP_TYPE__LINKED:
 		if (collect_remap_linked(ri->rfi, ri->rfe))
 			return -1;
+		break;
+	case REMAP_TYPE__PROCFS:
+		if (collect_remap_dead_process(ri->rfi, rfe) < 0)
+			return -1;
+		break;
+	default:
+		break;
 	}
 
 	list_add_tail(&ri->list, &remaps);
@@ -465,7 +474,7 @@ static int prepare_one_remap(struct remap_info *ri)
 		ret = open_remap_ghost(rfi, rfe);
 		break;
 	case REMAP_TYPE__PROCFS:
-		/* handled earlier by prepare_procfs_remaps */
+		/* handled earlier by collect_remap_dead_process */
 		ret = 0;
 		break;
 	default:
@@ -477,31 +486,6 @@ out:
 	return ret;
 }
 
-/* We separate the preparation of PROCFS remaps because they allocate pstree
- * items, which need to be seen by the root task. We can't do all remaps here,
- * because the files haven't been loaded yet.
- */
-int prepare_procfs_remaps(void)
-{
-	struct remap_info *ri;
-
-	list_for_each_entry(ri, &remaps, list) {
-		RemapFilePathEntry *rfe = ri->rfe;
-		struct reg_file_info *rfi = ri->rfi;
-
-		switch (rfe->remap_type) {
-		case REMAP_TYPE__PROCFS:
-			if (open_remap_dead_process(rfi, rfe) < 0)
-				return -1;
-			break;
-		default:
-			continue;
-		}
-	}
-
-	return 0;
-}
-
 int prepare_remaps(void)
 {
 	struct remap_info *ri;
diff --git a/criu/include/files-reg.h b/criu/include/files-reg.h
index 5a6c691..ba2ad6c 100644
--- a/criu/include/files-reg.h
+++ b/criu/include/files-reg.h
@@ -53,7 +53,6 @@ extern int try_clean_remaps(bool only_ghosts);
 
 extern int strip_deleted(struct fd_link *link);
 
-extern int prepare_procfs_remaps(void);
 extern int dead_pid_conflict(void);
 
 #endif /* __CR_FILES_REG_H__ */
-- 
2.1.4



More information about the CRIU mailing list