[CRIU] [PATCH v5 14/42] pstree: Pre-dump ns ids before tasks

Kirill Tkhai ktkhai at virtuozzo.com
Fri May 5 09:14:50 PDT 2017


We need to know root_item's pid_ns nesting level
(if its pid_ns is similar to criu's, or not)
before collect_tasks(). Thus we populate
pstree_item::pid::level correctly.

v4: New

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/cr-dump.c |   21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/criu/cr-dump.c b/criu/cr-dump.c
index ed5cd1227..8ee1efa28 100644
--- a/criu/cr-dump.c
+++ b/criu/cr-dump.c
@@ -786,9 +786,8 @@ static int dump_task_core_all(struct parasite_ctl *ctl,
 	return ret;
 }
 
-static int collect_pstree_ids_predump(void)
+static int predump_criu_ns_ids(void)
 {
-	struct pstree_item *item;
 	struct pid pid;
 	struct {
 		struct pstree_item i;
@@ -803,8 +802,12 @@ static int collect_pstree_ids_predump(void)
 	crt.i.pid->state = TASK_ALIVE;
 	crt.i.pid->real = getpid();
 
-	if (predump_task_ns_ids(&crt.i))
-		return -1;
+	return predump_task_ns_ids(&crt.i);
+}
+
+static int collect_pstree_ids_predump()
+{
+	struct pstree_item *item;
 
 	for_each_pstree_item(item) {
 		if (item->pid->state == TASK_DEAD)
@@ -1579,9 +1582,17 @@ int cr_pre_dump_tasks(pid_t pid)
 	if (setup_alarm_handler())
 		goto err;
 
+	/*
+	 * Pre-dump criu's and root_item's ns ids, as they are need
+	 * to discover root_item's pid_ns nesting.
+	 */
+	if (predump_criu_ns_ids() || predump_task_ns_ids(root_item))
+		goto err;
+
 	if (collect_pstree())
 		goto err;
 
+	/* Pre-dump other tasks ns ids */
 	if (collect_pstree_ids_predump())
 		goto err;
 
@@ -1781,6 +1792,8 @@ int cr_dump_tasks(pid_t pid)
 	if (setup_alarm_handler())
 		goto err;
 
+	if (predump_task_ns_ids(root_item))
+		goto err;
 	/*
 	 * The collect_pstree will also stop (PTRACE_SEIZE) the tasks
 	 * thus ensuring that they don't modify anything we collect



More information about the CRIU mailing list