[v1,18/55] pstree: Read ids earlier in read_pstree_image()

Submitted by Kirill Tkhai on March 24, 2017, 2:58 p.m.

Details

Message ID 149036748824.21903.15003964417559461891.stgit@localhost.localdomain
State New
Series "Nested pid namespaces support"
Headers show

Commit Message

Kirill Tkhai March 24, 2017, 2:58 p.m.
Read ids before creation of item, then we'll know
pid_ns of the item, so later we will be able to
allocate item with right levels of pid (in next patches).

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/pstree.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/pstree.c b/criu/pstree.c
index 15aacceb..e12b358a 100644
--- a/criu/pstree.c
+++ b/criu/pstree.c
@@ -530,6 +530,7 @@  static int read_pstree_ids(pid_t pid, TaskKobjIdsEntry **ids)
 
 static int read_pstree_image(pid_t *pid_max)
 {
+	TaskKobjIdsEntry *ids;
 	int ret = 0, i;
 	struct cr_img *img;
 	struct pstree_item *pi;
@@ -547,12 +548,18 @@  static int read_pstree_image(pid_t *pid_max)
 		if (ret <= 0)
 			break;
 
+		ret = read_pstree_ids(e->pid, &ids);
+		if (ret < 0)
+			break;
+
 		ret = -1;
 		pi = lookup_create_item(e->pid);
 		if (pi == NULL)
 			break;
 		BUG_ON(pi->pid->state != TASK_UNDEF);
 
+		pi->ids = ids;
+
 		/*
 		 * All pids should be added in the tree to be able to find
 		 * free pid-s for helpers. pstree_item for these pid-s will
@@ -630,10 +637,6 @@  static int read_pstree_image(pid_t *pid_max)
 		task_entries->nr_tasks++;
 
 		pstree_entry__free_unpacked(e, NULL);
-
-		ret = read_pstree_ids(vpid(pi), &pi->ids);
-		if (ret < 0)
-			goto err;
 	}
 
 	if (ret == 0)