[CRIU] [PATCH v2 24/57] pstree: Dump pid and user ns ids for dead tasks

Kirill Tkhai ktkhai at virtuozzo.com
Tue Mar 28 08:37:46 PDT 2017


Dead task has them set, so we must dump and restore them.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/cr-dump.c    |   23 ++++++++++++++++++-----
 criu/namespaces.c |   18 +++++++++++-------
 2 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/criu/cr-dump.c b/criu/cr-dump.c
index 84139fe3..8d7ed439 100644
--- a/criu/cr-dump.c
+++ b/criu/cr-dump.c
@@ -647,12 +647,12 @@ int get_task_ids(struct pstree_item *item)
 		ret = dump_task_kobj_ids(item);
 		if (ret)
 			goto err_free;
-
-		ret = dump_task_ns_ids(item);
-		if (ret)
-			goto err_free;
 	}
 
+	ret = dump_task_ns_ids(item);
+	if (ret)
+		goto err_free;
+
 	return 0;
 
 err_free:
@@ -662,9 +662,14 @@ int get_task_ids(struct pstree_item *item)
 	return -1;
 }
 
+static int do_dump_task_ids(const struct pstree_item *item, struct cr_img *img)
+{
+	return pb_write_one(img, item->ids, PB_IDS);
+}
+
 static int dump_task_ids(struct pstree_item *item, const struct cr_imgset *cr_imgset)
 {
-	return pb_write_one(img_from_set(cr_imgset, CR_FD_IDS), item->ids, PB_IDS);
+	return do_dump_task_ids(item, img_from_set(cr_imgset, CR_FD_IDS));
 }
 
 int dump_thread_core(int pid, CoreEntry *core, const struct parasite_dump_thread *ti)
@@ -873,6 +878,14 @@ static int dump_one_zombie(const struct pstree_item *item,
 
 	ret = pb_write_one(img, core, PB_CORE);
 	close_image(img);
+	if (ret)
+		goto err;
+
+	img = open_image(CR_FD_IDS, O_DUMP, vpid(item));
+	if (!img)
+		goto err;
+	ret = do_dump_task_ids(item, img);
+	close_image(img);
 err:
 	core_entry_free(core);
 	return ret;
diff --git a/criu/namespaces.c b/criu/namespaces.c
index 793b8257..5a610668 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -707,6 +707,17 @@ int dump_task_ns_ids(struct pstree_item *item)
 		return -1;
 	}
 
+	ids->has_user_ns_id = true;
+	ids->user_ns_id = get_ns_id(pid, &user_ns_desc, NULL);
+	if (!ids->user_ns_id) {
+		pr_err("Can't make userns id\n");
+		return -1;
+	}
+
+	/* Below namespaces do not present in dead task */
+	if (item->pid->state == TASK_DEAD)
+		return 0;
+
 	ids->has_net_ns_id = true;
 	ids->net_ns_id = __get_ns_id(pid, &net_ns_desc, NULL, &dmpi(item)->netns);
 	if (!ids->net_ns_id) {
@@ -735,13 +746,6 @@ int dump_task_ns_ids(struct pstree_item *item)
 		return -1;
 	}
 
-	ids->has_user_ns_id = true;
-	ids->user_ns_id = get_ns_id(pid, &user_ns_desc, NULL);
-	if (!ids->user_ns_id) {
-		pr_err("Can't make userns id\n");
-		return -1;
-	}
-
 	ids->cgroup_ns_id = get_ns_id(pid, &cgroup_ns_desc, &ids->has_cgroup_ns_id);
 	if (!ids->cgroup_ns_id) {
 		pr_err("Can't make cgroup id\n");



More information about the CRIU mailing list