[v2,27/57] pstree: Add pid_ns id argument to lookup_create_pid()

Submitted by Kirill Tkhai on March 28, 2017, 3:38 p.m.

Details

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

Commit Message

Kirill Tkhai March 28, 2017, 3:38 p.m.
Pass a namespace of item to the function.
This will allow to link the pid in correct ns::pid::root_rb
in next patches.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/cr-dump.c        |    4 ++--
 criu/files-reg.c      |    2 +-
 criu/include/pstree.h |    4 ++--
 criu/pstree.c         |   24 ++++++++++++------------
 4 files changed, 17 insertions(+), 17 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/cr-dump.c b/criu/cr-dump.c
index 8d7ed439..5e4f2dfa 100644
--- a/criu/cr-dump.c
+++ b/criu/cr-dump.c
@@ -843,7 +843,7 @@  static int dump_task_thread(struct parasite_ctl *parasite_ctl,
 	}
 	tid->ns[0].virt = parasite_tid;
 
-	pstree_insert_pid(tid);
+	pstree_insert_pid(tid, item->ids->pid_ns_id);
 
 	img = open_image(CR_FD_CORE, O_DUMP, tid->ns[0].virt);
 	if (!img)
@@ -1314,7 +1314,7 @@  static int dump_one_task(struct pstree_item *item)
 	item->pid->ns[0].virt = misc.pid;
 	item->sid->ns[0].virt = misc.sid;
 	item->pgid->ns[0].virt = misc.pgid;
-	pstree_insert_pid(item->pid);
+	pstree_insert_pid(item->pid, item->ids->pid_ns_id);
 
 	pr_info("sid=%d pgid=%d pid=%d\n",
 		item->sid->ns[0].virt, item->pgid->ns[0].virt, vpid(item));
diff --git a/criu/files-reg.c b/criu/files-reg.c
index 48f068d2..d59c825e 100644
--- a/criu/files-reg.c
+++ b/criu/files-reg.c
@@ -379,7 +379,7 @@  static int open_remap_dead_process(struct reg_file_info *rfi,
 {
 	struct pstree_item *helper;
 
-	helper = lookup_create_item(rfe->remap_id);
+	helper = lookup_create_item(rfe->remap_id, root_item->ids->pid_ns_id);
 	if (!helper)
 		return -1;
 
diff --git a/criu/include/pstree.h b/criu/include/pstree.h
index 0a62bfde..9978b8a7 100644
--- a/criu/include/pstree.h
+++ b/criu/include/pstree.h
@@ -90,8 +90,8 @@  extern struct pstree_item *__alloc_pstree_item(bool rst, int level);
 #define alloc_pstree_item() __alloc_pstree_item(false, 1)
 extern void init_pstree_helper(struct pstree_item *ret);
 
-extern struct pstree_item *lookup_create_item(pid_t pid);
-extern void pstree_insert_pid(struct pid *pid_node);
+extern struct pstree_item *lookup_create_item(pid_t pid, uint32_t ns_id);
+extern void pstree_insert_pid(struct pid *pid_node, uint32_t ns_id);
 extern struct pid *pstree_pid_by_virt(pid_t pid);
 
 extern struct pstree_item *root_item;
diff --git a/criu/pstree.c b/criu/pstree.c
index da2dc9fb..76672631 100644
--- a/criu/pstree.c
+++ b/criu/pstree.c
@@ -398,9 +398,9 @@  static int prepare_pstree_for_shell_job(void)
 			pi->sid->ns[0].virt = current_sid;
 	}
 
-	if (lookup_create_item(current_sid) == NULL)
+	if (lookup_create_item(current_sid, root_item->ids->pid_ns_id) == NULL)
 		return -1;
-	if (lookup_create_item(current_gid) == NULL)
+	if (lookup_create_item(current_gid, root_item->ids->pid_ns_id) == NULL)
 		return -1;
 
 	return 0;
@@ -434,7 +434,7 @@  static struct pid *find_pid_or_place_in_hier(struct rb_node **root, pid_t pid, i
  * it is not there yet. If pid_node isn't set, pstree_item
  * is inserted.
  */
-static struct pid *lookup_create_pid(pid_t pid, struct pid *pid_node)
+static struct pid *lookup_create_pid(pid_t pid, struct pid *pid_node, int ns_id)
 {
 	struct rb_node **new = NULL, *parent = NULL;
 	struct pid *found;
@@ -457,20 +457,20 @@  static struct pid *lookup_create_pid(pid_t pid, struct pid *pid_node)
 	return pid_node;
 }
 
-void pstree_insert_pid(struct pid *pid_node)
+void pstree_insert_pid(struct pid *pid_node, uint32_t ns_id)
 {
 	struct pid* n;
 
-	n = lookup_create_pid(pid_node->ns[0].virt, pid_node);
+	n = lookup_create_pid(pid_node->ns[0].virt, pid_node, ns_id);
 
 	BUG_ON(n != pid_node);
 }
 
-struct pstree_item *lookup_create_item(pid_t pid)
+struct pstree_item *lookup_create_item(pid_t pid, uint32_t ns_id)
 {
 	struct pid *node;;
 
-	node = lookup_create_pid(pid, NULL);
+	node = lookup_create_pid(pid, NULL, ns_id);
 	if (!node)
 		return NULL;
 	BUG_ON(node->state == TASK_THREAD);
@@ -597,7 +597,7 @@  static int read_pstree_image(pid_t *pid_max)
 			break;
 		}
 
-		pi = lookup_create_item(e->pid);
+		pi = lookup_create_item(e->pid, ids->pid_ns_id);
 		if (pi == NULL)
 			break;
 		BUG_ON(pi->pid->state != TASK_UNDEF);
@@ -610,9 +610,9 @@  static int read_pstree_image(pid_t *pid_max)
 		 * be initialized when we meet PstreeEntry with this pid or
 		 * we will create helpers for them.
 		 */
-		if (lookup_create_item(e->pgid) == NULL)
+		if (lookup_create_item(e->pgid, ids->pid_ns_id) == NULL)
 			break;
-		if (lookup_create_item(e->sid) == NULL)
+		if (lookup_create_item(e->sid, ids->pid_ns_id) == NULL)
 			break;
 
 		pi->pid->ns[0].virt = e->pid;
@@ -656,7 +656,7 @@  static int read_pstree_image(pid_t *pid_max)
 			pi->threads[i]->item = NULL;
 			if (i == 0)
 				continue; /* A thread leader is in a tree already */
-			node = lookup_create_pid(pi->threads[i]->ns[0].virt, pi->threads[i]);
+			node = lookup_create_pid(pi->threads[i]->ns[0].virt, pi->threads[i], ids->pid_ns_id);
 
 			BUG_ON(node == NULL);
 			if (node != pi->threads[i]) {
@@ -737,7 +737,7 @@  static int prepare_pstree_ids(void)
 			pid = get_free_pid();
 			if (pid < 0)
 				break;
-			helper = lookup_create_item(pid);
+			helper = lookup_create_item(pid, item->ids->pid_ns_id);
 			if (helper == NULL)
 				return -1;