[CRIU] [PATCH 3/5] restore: collect cores and save them on pstree_item

Andrey Vagin avagin at openvz.org
Tue Dec 25 08:10:09 EST 2012


They are used for determining shared fd tables.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-restore.c     | 15 ++-------------
 include/pstree.h |  3 +++
 pstree.c         | 14 +++++++++++++-
 3 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/cr-restore.c b/cr-restore.c
index a2d8911..b3e9572 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -732,18 +732,8 @@ out:
 
 static int restore_one_task(int pid)
 {
-	int fd, ret;
-	CoreEntry *core;
-
-	fd = open_image_ro(CR_FD_CORE, pid);
-	if (fd < 0)
-		return -1;
-
-	ret = pb_read_one(fd, &core, PB_CORE);
-	close(fd);
-
-	if (ret < 0)
-		return -1;
+	int ret;
+	CoreEntry *core = current->core;
 
 	if (check_core(core)) {
 		ret = -1;
@@ -764,7 +754,6 @@ static int restore_one_task(int pid)
 	}
 
 out:
-	core_entry__free_unpacked(core, NULL);
 	return ret;
 }
 
diff --git a/include/pstree.h b/include/pstree.h
index ff0bd11..e9e01ce 100644
--- a/include/pstree.h
+++ b/include/pstree.h
@@ -2,6 +2,7 @@
 #define __CR_PSTREE_H__
 #include "list.h"
 #include "crtools.h"
+#include "../protobuf/core.pb-c.h"
 
 /*
  * That's the init process which usually inherit
@@ -40,6 +41,8 @@ struct pstree_item {
 	int			nr_threads;	/* number of threads */
 	struct pid		*threads;	/* array of threads */
 
+	CoreEntry		*core;
+
 	struct rst_info		rst[0];
 };
 
diff --git a/pstree.c b/pstree.c
index 3ba645e..c9a402e 100644
--- a/pstree.c
+++ b/pstree.c
@@ -177,7 +177,7 @@ static int prepare_pstree_for_shell_job(void)
 
 static int read_pstree_image(void)
 {
-	int ret = 0, i, ps_fd;
+	int ret = 0, i, ps_fd, core_fd;
 	struct pstree_item *pi, *parent = NULL;
 
 	pr_info("Reading image tree\n");
@@ -260,6 +260,18 @@ static int read_pstree_image(void)
 		task_entries->nr_tasks++;
 
 		pstree_entry__free_unpacked(e, NULL);
+
+		ret = -1;
+		core_fd = open_image_ro(CR_FD_CORE, pi->pid.virt);
+		if (core_fd < 0)
+			break;
+
+		ret = pb_read_one(core_fd, &pi->core, PB_CORE);
+		close(core_fd);
+		if (ret < 0)
+			break;
+
+		pi->state = pi->core->tc->task_state;
 	}
 err:
 	close(ps_fd);
-- 
1.7.11.7



More information about the CRIU mailing list