2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-31 22:35:33 +00:00

pstree: Split lookup_create_pid()

Extract the function, which seaches for existing pid.
In next patches we will use it.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
This commit is contained in:
Kirill Tkhai
2017-04-10 11:18:55 +03:00
committed by Andrei Vagin
parent c9aa6f3548
commit e051f842a9

View File

@@ -408,6 +408,29 @@ static int prepare_pstree_for_shell_job(void)
return 0; return 0;
} }
static struct pid *find_pid_or_place_in_hier(struct rb_node **root, pid_t pid, int level,
struct rb_node **ret_parent, struct rb_node ***ret_place)
{
struct rb_node *node = *root;
struct rb_node **new = root;
struct rb_node *parent = NULL;
while (node) {
struct pid *this = rb_entry(node, struct pid, ns[level].node);
parent = *new;
if (pid < this->ns[level].virt)
node = node->rb_left, new = &((*new)->rb_left);
else if (pid > this->ns[level].virt)
node = node->rb_right, new = &((*new)->rb_right);
else
return this;
}
*ret_parent = parent;
*ret_place = new;
return NULL;
}
/* /*
* Try to find a pid node in the tree and insert a new one, * Try to find a pid node in the tree and insert a new one,
* it is not there yet. If pid_node isn't set, pstree_item * it is not there yet. If pid_node isn't set, pstree_item
@@ -415,21 +438,12 @@ static int prepare_pstree_for_shell_job(void)
*/ */
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)
{ {
struct rb_node *node = pid_root_rb.rb_node; struct rb_node **new = NULL, *parent = NULL;
struct rb_node **new = &pid_root_rb.rb_node; struct pid *found;
struct rb_node *parent = NULL;
while (node) { found = find_pid_or_place_in_hier(&pid_root_rb.rb_node, pid, 0, &parent, &new);
struct pid *this = rb_entry(node, struct pid, ns[0].node); if (found)
return found;
parent = *new;
if (pid < this->ns[0].virt)
node = node->rb_left, new = &((*new)->rb_left);
else if (pid > this->ns[0].virt)
node = node->rb_right, new = &((*new)->rb_right);
else
return this;
}
if (!pid_node) { if (!pid_node) {
struct pstree_item *item; struct pstree_item *item;