[CRIU] [PATCH cr 05/13] cr-dump: dump pstree after tasks

Andrey Vagin avagin at openvz.org
Tue Jun 19 07:53:09 EDT 2012


because a pid in a target pid ns is got from parasite.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-dump.c |   47 ++++++++++++++++++++++++++---------------------
 1 files changed, 26 insertions(+), 21 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index e5770ab..7136cd3 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -1489,7 +1489,7 @@ static int dump_task_thread(struct parasite_ctl *parasite_ctl, struct pid *tid)
 	core->tc.task_state = TASK_ALIVE;
 	core->tc.exit_code = 0;
 
-	fd_core = open_image(CR_FD_CORE, O_DUMP, pid);
+	fd_core = open_image(CR_FD_CORE, O_DUMP, tid->pid);
 	if (fd_core < 0)
 		goto err_free;
 
@@ -1582,11 +1582,6 @@ static int dump_one_task(struct pstree_item *item)
 	if (item->state == TASK_DEAD)
 		return dump_one_zombie(item, &pps_buf);
 
-	ret = -1;
-	cr_fdset = cr_task_fdset_open(item->pid.pid, O_DUMP);
-	if (!cr_fdset)
-		goto err;
-
 	ret = collect_mappings(pid, &vma_area_list);
 	if (ret) {
 		pr_err("Collect mappings (pid: %d) failed with %d\n", pid, ret);
@@ -1606,6 +1601,21 @@ static int dump_one_task(struct pstree_item *item)
 		goto err;
 	}
 
+	ret = parasite_dump_misc_seized(parasite_ctl, &misc);
+	if (ret) {
+		pr_err("Can't dump misc (pid: %d)\n", pid);
+		goto err_cure_fdset;
+	}
+
+	item->pid.pid = misc.pid;
+	item->sid = misc.sid;
+	item->pgid = misc.pgid;
+
+	ret = -1;
+	cr_fdset = cr_task_fdset_open(item->pid.pid, O_DUMP);
+	if (!cr_fdset)
+		goto err_cure;
+
 	ret = dump_task_files_seized(parasite_ctl, cr_fdset, fds, nr_fds);
 	if (ret) {
 		pr_err("Dump files (pid: %d) failed with %d\n", pid, ret);
@@ -1630,12 +1640,6 @@ static int dump_one_task(struct pstree_item *item)
 		goto err_cure;
 	}
 
-	ret = parasite_dump_misc_seized(parasite_ctl, &misc);
-	if (ret) {
-		pr_err("Can't dump misc (pid: %d)\n", pid);
-		goto err_cure;
-	}
-
 	ret = dump_task_core_all(pid, &pps_buf, &misc, parasite_ctl, cr_fdset);
 	if (ret) {
 		pr_err("Dump core (pid: %d) failed with %d\n", pid, ret);
@@ -1672,8 +1676,8 @@ static int dump_one_task(struct pstree_item *item)
 		goto err;
 	}
 
-err:
 	close_cr_fdset(&cr_fdset);
+err:
 	close_pid_proc();
 err_free:
 	free_mappings(&vma_area_list);
@@ -1681,6 +1685,8 @@ err_free:
 	return ret;
 
 err_cure:
+	close_cr_fdset(&cr_fdset);
+err_cure_fdset:
 	parasite_cure_seized(parasite_ctl);
 	goto err;
 }
@@ -1697,14 +1703,6 @@ int cr_dump_tasks(pid_t pid, const struct cr_options *opts)
 	if (collect_pstree(pid, opts))
 		goto err;
 
-	if (dump_pstree(root_item))
-		goto err;
-
-	if (opts->namespaces_flags) {
-		if (dump_namespaces(pid, opts->namespaces_flags) < 0)
-			goto err;
-	}
-
 	/*
 	 * Ignore collection errors by now since we may not want
 	 * to dump the missed sockets. But later, when we will start
@@ -1732,6 +1730,13 @@ int cr_dump_tasks(pid_t pid, const struct cr_options *opts)
 			break;
 	}
 
+	if (dump_pstree(root_item))
+		goto err;
+
+	if (opts->namespaces_flags)
+		if (dump_namespaces(pid, opts->namespaces_flags) < 0)
+			goto err;
+
 	ret = cr_dump_shmem();
 	if (ret)
 		goto err;
-- 
1.7.1



More information about the CRIU mailing list