[CRIU] [PATCH 12/12] dump: files tree - few cleanups

Kinsbursky Stanislav skinsbursky at openvz.org
Fri Mar 23 12:24:25 EDT 2012


From: Stanislav Kinsbursky <skinsbursky at openvz.org>

1) Use u8 instead of int for fd number.
2) Use genid from parent node while lookup subtree - one less parameter to
pass.
3) Redundant NULL assigment for pointer removed.
4) Use parent instead on *new during tree walk.

Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
---
 file-ids.c |   28 ++++++++++++----------------
 1 files changed, 12 insertions(+), 16 deletions(-)
-------------- next part --------------
diff --git a/file-ids.c b/file-ids.c
index aef7ffd..cb5dbbf 100644
--- a/file-ids.c
+++ b/file-ids.c
@@ -88,7 +88,7 @@ static int compare_open_files(pid_t pid1, pid_t pid2, u8 fd1, u8 fd2)
 }
 
 static struct file_node *alloc_file_node(struct file_node *parent, u32 genid,
-					 pid_t pid, int fd, u8 *new_entry)
+					 pid_t pid, u8 fd, u8 *new_entry)
 {
 	struct file_node *e;
 
@@ -116,8 +116,8 @@ err:
 }
 
 static struct file_node *
-lookup_alloc_subtree(struct file_node *e, u32 genid,
-		     pid_t pid, int fd, u8 *new_entry,
+lookup_alloc_subtree(struct file_node *e,
+		     pid_t pid, u8 fd, u8 *new_entry,
 		     int (*compare)(pid_t , pid_t , u8 , u8 ))
 {
 	struct rb_node *node = e->subtree_root.rb_node;
@@ -139,7 +139,7 @@ lookup_alloc_subtree(struct file_node *e, u32 genid,
 			return this;
 	}
 
-	sub = alloc_file_node(NULL, genid, pid, fd, new_entry);
+	sub = alloc_file_node(e, e->u.key.genid, pid, fd, new_entry);
 	if (!sub)
 		goto err;
 
@@ -153,7 +153,7 @@ static struct file_node *lookup_alloc_node(u8 type, u64 genid,
 {
 	struct rb_root *fd_root;
 	struct rb_node *node;
-	struct file_node *e = NULL;
+	struct file_node *e;
 
 	struct rb_node **new;
 	struct rb_node *parent = NULL;
@@ -170,22 +170,18 @@ static struct file_node *lookup_alloc_node(u8 type, u64 genid,
 	while (node) {
 		struct file_node *this = rb_entry(node, struct file_node, node);
 
-		parent = *new;
+		parent = node;
 		if (genid < this->u.key.genid)
-			node = node->rb_left, new = &((*new)->rb_left);
+			node = node->rb_left, new = &parent->rb_left;
 		else if (genid > this->u.key.genid)
-			node = node->rb_right, new = &((*new)->rb_right);
+			node = node->rb_right, new = &parent->rb_right;
 		else
-			return lookup_alloc_subtree(this, genid, pid, fd,
+			return lookup_alloc_subtree(this, pid, fd,
 						    new_entry, compare);
 	}
-
-	e = alloc_file_node(e, genid, pid, fd, new_entry);
-	if (!e)
-		goto err;
-
-	rb_link_and_balance(fd_root, &e->node, parent, new);
-err:
+	e = alloc_file_node(NULL, genid, pid, fd, new_entry);
+	if (e)
+		rb_link_and_balance(fd_root, &e->node, parent, new);
 	return e;
 }
 


More information about the CRIU mailing list