[CRIU] [PATCH] remap: don't allocate dead pids in wrong context

Tycho Andersen tycho.andersen at canonical.com
Sat Nov 21 08:41:16 PST 2015


Closes #87

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
CC: Andrew Vagin <avagin at virtuozzo.com>
---
 cr-restore.c        |  5 +++++
 files-reg.c         | 28 +++++++++++++++++++++++++++-
 include/files-reg.h |  2 ++
 3 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/cr-restore.c b/cr-restore.c
index 482b8e7..60a53c2 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -132,6 +132,11 @@ static int crtools_prepare_shared(void)
 	if (collect_remaps_and_regfiles())
 		return -1;
 
+	if (prepare_procfs_remaps())
+		return -1;
+
+	/* dead pid remap needs to allocate task helpers which all tasks need
+	 * to see */
 	/* Connections are unlocked from criu */
 	if (collect_inet_sockets())
 		return -1;
diff --git a/files-reg.c b/files-reg.c
index 1e2daa9..b617ee9 100644
--- a/files-reg.c
+++ b/files-reg.c
@@ -361,7 +361,8 @@ static int prepare_one_remap(struct remap_info *ri)
 		ret = open_remap_ghost(rfi, rfe);
 		break;
 	case REMAP_TYPE__PROCFS:
-		ret = open_remap_dead_process(rfi, rfe);
+		/* handled earlier by prepare_procfs_remaps */
+		ret = 0;
 		break;
 	default:
 		pr_err("unknown remap type %u\n", rfe->remap_type);
@@ -372,6 +373,31 @@ out:
 	return ret;
 }
 
+/* We separate the prepartion 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/include/files-reg.h b/include/files-reg.h
index 72f7390..e2f6115 100644
--- a/include/files-reg.h
+++ b/include/files-reg.h
@@ -54,4 +54,6 @@ extern void try_clean_remaps(int ns_fd);
 
 extern int strip_deleted(struct fd_link *link);
 
+extern int prepare_procfs_remaps(void);
+
 #endif /* __CR_FILES_REG_H__ */
-- 
2.6.2



More information about the CRIU mailing list