[CRIU] [PATCH RESEND v1 30/55] pid: Implement populate_ns_pids() helper

Kirill Tkhai ktkhai at virtuozzo.com
Fri Mar 24 08:13:45 PDT 2017


Assign pids in separate function. Just a refactoring,
which will be used in next patches.

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

diff --git a/criu/cr-dump.c b/criu/cr-dump.c
index 5e4f2dfa..cb25c357 100644
--- a/criu/cr-dump.c
+++ b/criu/cr-dump.c
@@ -586,6 +586,22 @@ static int get_task_personality(pid_t pid, u32 *personality)
 	return ret;
 }
 
+static int populate_ns_pids(pid_t real_pid, pid_t real_tid,
+			    struct pid **pid, struct pid **sid, struct pid **pgid,
+			    pid_t parasite_pid, pid_t parasite_sid, pid_t parasite_pgid)
+{
+	if (list_empty(&top_pid_ns->children)) {
+		(*pid)->ns[0].virt = parasite_pid;
+		if (real_tid < 0) {
+			(*sid)->ns[0].virt = parasite_sid;
+			(*pgid)->ns[0].virt = parasite_pgid;
+		}
+		return 0;
+	}
+
+	return -1;
+}
+
 static DECLARE_KCMP_TREE(vm_tree, KCMP_VM);
 static DECLARE_KCMP_TREE(fs_tree, KCMP_FS);
 static DECLARE_KCMP_TREE(files_tree, KCMP_FILES);
@@ -841,8 +857,13 @@ static int dump_task_thread(struct parasite_ctl *parasite_ctl,
 		pr_err("Can't dump thread for pid %d\n", pid);
 		goto err;
 	}
-	tid->ns[0].virt = parasite_tid;
 
+	if (populate_ns_pids(item->pid->real, tid->real, &tid, NULL, NULL,
+							 parasite_tid, -1, -1) < 0) {
+		pr_err("Can't get ns pids\n");
+		goto err;
+	}
+	item->threads[id] = tid;
 	pstree_insert_pid(tid, item->ids->pid_ns_id);
 
 	img = open_image(CR_FD_CORE, O_DUMP, tid->ns[0].virt);
@@ -1181,7 +1202,11 @@ static int pre_dump_one_task(struct pstree_item *item)
 		goto err_cure;
 	}
 
-	item->pid->ns[0].virt = misc.pid;
+	if (populate_ns_pids(pid, -1, &item->pid, &item->sid, &item->pgid,
+			     misc.pid, misc.sid, misc.pgid) < 0) {
+		pr_err("Can't get ns pids\n");
+		goto err_cure;
+	}
 
 	mdc.pre_dump = true;
 	mdc.lazy = false;
@@ -1311,9 +1336,11 @@ static int dump_one_task(struct pstree_item *item)
 		goto err_cure_imgset;
 	}
 
-	item->pid->ns[0].virt = misc.pid;
-	item->sid->ns[0].virt = misc.sid;
-	item->pgid->ns[0].virt = misc.pgid;
+	if (populate_ns_pids(pid, -1, &item->pid, &item->sid, &item->pgid,
+			     misc.pid, misc.sid, misc.pgid) < 0) {
+		pr_err("Can't get ns pids\n");
+		goto err_cure_imgset;
+	}
 	pstree_insert_pid(item->pid, item->ids->pid_ns_id);
 
 	pr_info("sid=%d pgid=%d pid=%d\n",



More information about the CRIU mailing list