[CRIU] [PATCH 10/12] dump: files tree - compare callbacks introduced

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


From: Stanislav Kinsbursky <skinsbursky at openvz.org>

Kcmp syscall doesnt' suits vma files. Looks like currently generating ID is
enough. Thus no additonal check required in case of mapping files.

Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
---
 file-ids.c |   23 ++++++++++++++++++++---
 1 files changed, 20 insertions(+), 3 deletions(-)
-------------- next part --------------
diff --git a/file-ids.c b/file-ids.c
index 3d5711d..149f846 100644
--- a/file-ids.c
+++ b/file-ids.c
@@ -77,6 +77,16 @@ struct fd_id_entry {
 
 static struct rb_root dump_file_forest[FD_INFO_MAX];
 
+static int compare_map_files(pid_t pid1, pid_t pid2, u8 fd1, u8 fd2)
+{
+	return 0;
+}
+
+static int compare_open_files(pid_t pid1, pid_t pid2, u8 fd1, u8 fd2)
+{
+	return sys_kcmp(pid1, pid2, KCMP_FILE, fd1, fd2);
+}
+
 static struct fd_id_entry *alloc_fd_id_entry(struct fd_id_entry *parent, u32 genid,
 					     pid_t pid, int fd, u8 *new_entry)
 {
@@ -107,7 +117,8 @@ err:
 
 static struct fd_id_entry *
 lookup_alloc_subtree(struct fd_id_entry *e, u32 genid,
-		     pid_t pid, int fd, u8 *new_entry)
+		     pid_t pid, int fd, u8 *new_entry,
+		     int (*compare)(pid_t , pid_t , u8 , u8 ))
 {
 	struct rb_node *node = e->subtree_root.rb_node;
 	struct fd_id_entry *sub = NULL;
@@ -117,7 +128,7 @@ lookup_alloc_subtree(struct fd_id_entry *e, u32 genid,
 
 	while (node) {
 		struct fd_id_entry *this = rb_entry(node, struct fd_id_entry, subtree_node);
-		int ret = sys_kcmp(this->info.pid, pid, KCMP_FILE, this->info.fd, fd);
+		int ret = compare(this->info.pid, pid, this->info.fd, fd);
 
 		parent = *new;
 		if (ret < 0)
@@ -146,11 +157,16 @@ static struct fd_id_entry *lookup_alloc_node(u8 type, u64 genid,
 
 	struct rb_node **new;
 	struct rb_node *parent = NULL;
+	int (*compare)(pid_t , pid_t , u8 , u8 );
 
 	fd_root = &dump_file_forest[type];
 	node = fd_root->rb_node;
 	new = &fd_root->rb_node;
 
+	compare = compare_open_files;
+	if (type == FDINFO_MAP)
+		compare = compare_map_files;
+
 	while (node) {
 		struct fd_id_entry *this = rb_entry(node, struct fd_id_entry, node);
 
@@ -160,7 +176,8 @@ static struct fd_id_entry *lookup_alloc_node(u8 type, u64 genid,
 		else if (genid > this->u.key.genid)
 			node = node->rb_right, new = &((*new)->rb_right);
 		else
-			return lookup_alloc_subtree(this, genid, pid, fd, new_entry);
+			return lookup_alloc_subtree(this, genid, pid, fd,
+						    new_entry, compare);
 	}
 
 	e = alloc_fd_id_entry(e, genid, pid, fd, new_entry);


More information about the CRIU mailing list