[CRIU] [PATCH 15/21] pstree: Dump threads pid_for_children_ns

Kirill Tkhai ktkhai at virtuozzo.com
Tue May 23 05:40:38 PDT 2017


It may differ from group leader's pid_for_children_ns,
so dump it separate.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/cr-dump.c            |   22 +++++++++++++++++++++-
 criu/cr-restore.c         |    2 +-
 criu/include/namespaces.h |    2 ++
 criu/namespaces.c         |    8 ++++++++
 4 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/criu/cr-dump.c b/criu/cr-dump.c
index b3df881dc..ccd651970 100644
--- a/criu/cr-dump.c
+++ b/criu/cr-dump.c
@@ -662,6 +662,18 @@ int get_task_ids(struct pstree_item *item)
 	return -1;
 }
 
+static int get_thread_ids(struct pstree_item *item, int id)
+{
+	CoreEntry *core = item->core[id];
+	core->ids = xmalloc(sizeof(*core->ids));
+	if (!core->ids)
+		return -1;
+
+	task_kobj_ids_entry__init(core->ids);
+
+	return dump_thread_ids(item->threads[id]->real, core->ids);
+}
+
 static int do_dump_task_ids(const struct pstree_item *item, struct cr_img *img)
 {
 	return pb_write_one(img, item->ids, PB_IDS);
@@ -846,10 +858,18 @@ static int collect_pstree_ids_predump()
 int collect_pstree_ids(void)
 {
 	struct pstree_item *item;
+	int i;
 
-	for_each_pstree_item(item)
+	for_each_pstree_item(item) {
 		if (get_task_ids(item))
 			return -1;
+		for (i = 0; i < item->nr_threads; i++) {
+			if (item->threads[i]->real == item->pid->real)
+				continue;
+			if (get_thread_ids(item, i))
+				return -1;
+		}
+	}
 
 	return set_top_pid_ns();
 }
diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 238b05b18..944230941 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -3466,7 +3466,7 @@ static int sigreturn_restore(pid_t pid, struct task_restore_args *task_args, uns
 				blkset = (void *)&tcore->thread_core->blk_sigset;
 		}
 
-		if ((tcore->tc || tcore->ids) && thread_args[i].pid[0] != pid) {
+		if ((tcore->tc) && thread_args[i].pid[0] != pid) {
 			pr_err("Thread has optional fields present %d\n",
 			       thread_args[i].pid[0]);
 			ret = -1;
diff --git a/criu/include/namespaces.h b/criu/include/namespaces.h
index 1f5783317..cafb10992 100644
--- a/criu/include/namespaces.h
+++ b/criu/include/namespaces.h
@@ -7,6 +7,7 @@
 #include "files.h"
 #include "common/list.h"
 #include "images/ns.pb-c.h"
+#include "images/core.pb-c.h"
 #include "images/netdev.pb-c.h"
 
 #ifndef CLONE_NEWNS
@@ -200,6 +201,7 @@ extern int restore_ns(int rst, struct ns_desc *nd);
 
 extern int dump_task_ns_ids(struct pstree_item *);
 extern int predump_task_ns_ids(struct pstree_item *);
+extern int dump_thread_ids(pid_t pid, TaskKobjIdsEntry *ids);
 extern struct ns_id *rst_new_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd, enum ns_type t);
 extern int rst_add_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd);
 extern struct ns_id *lookup_ns_by_id(unsigned int id, struct ns_desc *nd);
diff --git a/criu/namespaces.c b/criu/namespaces.c
index 880da2836..521764a1b 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -794,6 +794,14 @@ int dump_task_ns_ids(struct pstree_item *item)
 	return 0;
 }
 
+int dump_thread_ids(pid_t pid, TaskKobjIdsEntry *ids)
+{
+	if (get_pid_for_children_ns_id(pid, ids) < 0)
+		return -1;
+
+	return 0;
+}
+
 static int set_ns_opt(int ns_fd, unsigned ioc, struct ns_id **ns, struct ns_desc *nd)
 {
 	int opt_fd, ret = -1;



More information about the CRIU mailing list