[CRIU] [PATCH 3/6] pstree: prepare to store all pid-s in rb-tree
Pavel Emelyanov
xemul at virtuozzo.com
Fri Mar 11 07:41:08 PST 2016
> +static struct pid *insert_pid(pid_t pid, struct pid *pid_node)
You ignored my request to give this routine some more descriptive name.
Please.
(one more comment below)
> +{
> + struct rb_node *node = pid_root_rb.rb_node;
> + struct rb_node **new = &pid_root_rb.rb_node;
> + struct rb_node *parent = NULL;
> +
> + while (node) {
> + struct pid *this = rb_entry(node, struct pid, node);
> +
> + parent = *new;
> + if (pid < this->virt)
> + node = node->rb_left, new = &((*new)->rb_left);
> + else if (pid > this->virt)
> + node = node->rb_right, new = &((*new)->rb_right);
> + else
> + return this;
> + }
> +
> + if (!pid_node) {
> + struct pstree_item *item;
> +
> + item = alloc_pstree_item_with_rst();
> + if (item == NULL)
> + return NULL;
> +
> + item->pid.virt = pid;
> + pid_node = &item->pid;
> + }
> + rb_link_and_balance(&pid_root_rb, &pid_node->node, parent, new);
> + return pid_node;
> +}
> +
> +struct pstree_item *insert_item(pid_t pid)
> +{
> + struct pid *node;;
> +
> + node = insert_pid(pid, NULL);
> + if (!node)
> + return NULL;
> + BUG_ON(node->state == TASK_THREAD);
> +
> + return container_of(node, struct pstree_item, pid);
> +}
This routine returns NULL in two cases -- an error has occurred and pid
was not found.
More information about the CRIU
mailing list