[CRIU] [PATCH 5/6] pstree: use rbtree to find a specified pid (v2)
Andrey Vagin
avagin at openvz.org
Mon Mar 14 23:37:16 PDT 2016
From: Andrew Vagin <avagin at virtuozzo.com>
v2: rename lookup_pid to pstree_pid_by_virt
use pstree_pid_by_virt in pstree_item_by_virt
Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
---
criu/pstree.c | 32 +++++++++++++++-----------------
1 file changed, 15 insertions(+), 17 deletions(-)
diff --git a/criu/pstree.c b/criu/pstree.c
index 3274f56..3a278fa 100644
--- a/criu/pstree.c
+++ b/criu/pstree.c
@@ -678,18 +678,15 @@ static int prepare_pstree_ids(void)
/* Add a process group leader if it is absent */
for_each_pstree_item(item) {
- struct pstree_item *gleader;
+ struct pid *pid;
if (!item->pgid || item->pid.virt == item->pgid)
continue;
- for_each_pstree_item(gleader) {
- if (gleader->pid.virt == item->pgid)
- break;
- }
-
- if (gleader) {
- rsti(item)->pgrp_leader = gleader;
+ pid = pstree_pid_by_virt(item->pgid);
+ if (pid->state != TASK_UNDEF) {
+ BUG_ON(pid->state == TASK_THREAD);
+ rsti(item)->pgrp_leader = container_of(pid, struct pstree_item, pid);
continue;
}
@@ -701,9 +698,9 @@ static int prepare_pstree_ids(void)
if (current_pgid == item->pgid)
continue;
- helper = alloc_pstree_helper();
- if (helper == NULL)
- return -1;
+ helper = container_of(pid, struct pstree_item, pid);
+ init_pstree_helper(helper);
+
helper->sid = item->sid;
helper->pgid = item->pgid;
helper->pid.virt = item->pgid;
@@ -948,13 +945,14 @@ bool restore_before_setsid(struct pstree_item *child)
struct pstree_item *pstree_item_by_virt(pid_t virt)
{
- struct pstree_item *item;
+ struct pid *pid;
- for_each_pstree_item(item) {
- if (item->pid.virt == virt)
- return item;
- }
- return NULL;
+ pid = pstree_pid_by_virt(virt);
+ if (pid == NULL)
+ return NULL;
+ BUG_ON(pid->state == TASK_THREAD);
+
+ return container_of(pid, struct pstree_item, pid);
}
struct pstree_item *pstree_item_by_real(pid_t real)
--
2.5.0
More information about the CRIU
mailing list