[CRIU] [PATCH v3 23/55] pstree: Split lookup_create_pid()
Kirill Tkhai
ktkhai at virtuozzo.com
Mon Apr 10 01:18:55 PDT 2017
Extract the function, which seaches for existing pid.
In next patches we will use it.
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
criu/pstree.c | 36 +++++++++++++++++++++++++-----------
1 file changed, 25 insertions(+), 11 deletions(-)
diff --git a/criu/pstree.c b/criu/pstree.c
index 601bf1365..da2dc9fb8 100644
--- a/criu/pstree.c
+++ b/criu/pstree.c
@@ -406,28 +406,42 @@ static int prepare_pstree_for_shell_job(void)
return 0;
}
-/*
- * 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
- * is inserted.
- */
-static struct pid *lookup_create_pid(pid_t pid, struct pid *pid_node)
+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 = pid_root_rb.rb_node;
- struct rb_node **new = &pid_root_rb.rb_node;
+ 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[0].node);
+ struct pid *this = rb_entry(node, struct pid, ns[level].node);
parent = *new;
- if (pid < this->ns[0].virt)
+ if (pid < this->ns[level].virt)
node = node->rb_left, new = &((*new)->rb_left);
- else if (pid > this->ns[0].virt)
+ 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,
+ * 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)
+{
+ struct rb_node **new = NULL, *parent = NULL;
+ struct pid *found;
+
+ found = find_pid_or_place_in_hier(&pid_root_rb.rb_node, pid, 0, &parent, &new);
+ if (found)
+ return found;
if (!pid_node) {
struct pstree_item *item;
More information about the CRIU
mailing list