[CRIU] [PATCH v4 13/41] pstree: Pre-dump ns ids before tasks

Kirill Tkhai ktkhai at virtuozzo.com
Thu May 4 09:06:52 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 365f360f4..08976a941 100644
--- a/criu/cr-dump.c
+++ b/criu/cr-dump.c
@@ -776,9 +776,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;
@@ -793,8 +792,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)
@@ -1569,9 +1572,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;
 
@@ -1771,6 +1782,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