[CRIU] [PATCH 08/12] dump: files tree - return new entry flag

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


From: Stanislav Kinsbursky <skinsbursky at openvz.org>

Will be required for regular files dumping (image for regular files will be
global and thus each file have to be dumped only once).

Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
---
 cr-dump.c          |    3 ++-
 file-ids.c         |   20 ++++++++++++--------
 include/file-ids.h |    3 ++-
 3 files changed, 16 insertions(+), 10 deletions(-)
-------------- next part --------------
diff --git a/cr-dump.c b/cr-dump.c
index d74efd7..204fc3b 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -121,9 +121,10 @@ static int dump_one_reg_file(const struct file_entry *p, pid_t pid,
 	e.fde.id	= FD_ID_INVALID;
 
 	if (likely(!fd_is_special(&e.fde))) {
+		u8 new;
 		long id;
 
-		id = fd_id_entry_collect(p, pid, target_fd);
+		id = fd_id_entry_collect(p, pid, target_fd, &new);
 		if (id < 0)
 			goto err;
 
diff --git a/file-ids.c b/file-ids.c
index 39caaad..0e69f39 100644
--- a/file-ids.c
+++ b/file-ids.c
@@ -78,7 +78,7 @@ struct fd_id_entry {
 static struct rb_root dump_file_forest[FD_INFO_MAX];
 static unsigned long fd_id_entries_subid = 1;
 
-static struct fd_id_entry *alloc_fd_id_entry(u32 genid, pid_t pid, int fd)
+static struct fd_id_entry *alloc_fd_id_entry(u32 genid, pid_t pid, int fd, u8 *new_entry)
 {
 	struct fd_id_entry *e;
 
@@ -94,6 +94,7 @@ static struct fd_id_entry *alloc_fd_id_entry(u32 genid, pid_t pid, int fd)
 	/* Make sure no overflow here */
 	BUG_ON(!e->u.key.subid);
 
+	*new_entry = 1;
 	rb_init_node(&e->node);
 	rb_init_node(&e->subtree_node);
 	rb_attach_node(&e->subtree_root, &e->subtree_node);
@@ -102,7 +103,8 @@ err:
 }
 
 static struct fd_id_entry *
-lookup_alloc_subtree(struct fd_id_entry *e, u32 genid, pid_t pid, int fd)
+lookup_alloc_subtree(struct fd_id_entry *e, u32 genid,
+		     pid_t pid, int fd, u8 *new_entry)
 {
 	struct rb_node *node = e->subtree_root.rb_node;
 	struct fd_id_entry *sub = NULL;
@@ -123,7 +125,7 @@ lookup_alloc_subtree(struct fd_id_entry *e, u32 genid, pid_t pid, int fd)
 			return this;
 	}
 
-	sub = alloc_fd_id_entry(genid, pid, fd);
+	sub = alloc_fd_id_entry(genid, pid, fd, new_entry);
 	if (!sub)
 		goto err;
 
@@ -132,7 +134,8 @@ err:
 	return sub;
 }
 
-static struct fd_id_entry *lookup_alloc_node(u8 type, u64 genid, pid_t pid, int fd)
+static struct fd_id_entry *lookup_alloc_node(u8 type, u64 genid,
+					     pid_t pid, int fd, u8 *new_entry)
 {
 	struct rb_root *fd_root;
 	struct rb_node *node;
@@ -154,10 +157,10 @@ static struct fd_id_entry *lookup_alloc_node(u8 type, u64 genid, pid_t pid, int
 		else if (genid > this->u.key.genid)
 			node = node->rb_right, new = &((*new)->rb_right);
 		else
-			return lookup_alloc_subtree(this, genid, pid, fd);
+			return lookup_alloc_subtree(this, genid, pid, fd, new_entry);
 	}
 
-	e = alloc_fd_id_entry(genid, pid, fd);
+	e = alloc_fd_id_entry(genid, pid, fd, new_entry);
 	if (!e)
 		goto err;
 
@@ -166,14 +169,15 @@ err:
 	return e;
 }
 
-long fd_id_entry_collect(const struct file_entry *p, pid_t pid, int fd)
+long fd_id_entry_collect(const struct file_entry *p, pid_t pid, int fd, u8 *new_entry)
 {
 	struct fd_id_entry *e = NULL;
 
 	if (p->type >= FD_INFO_MAX)
 		return -ENOTSUP;
 
-	e = lookup_alloc_node(p->type, p->id, pid, fd);
+	*new_entry = 0;
+	e = lookup_alloc_node(p->type, p->id, pid, fd, new_entry);
 	if (e == NULL)
 		return -ENOMEM;
 	return e->u.id;
diff --git a/include/file-ids.h b/include/file-ids.h
index 3b8993d..acf479b 100644
--- a/include/file-ids.h
+++ b/include/file-ids.h
@@ -17,6 +17,7 @@ struct file_info {
 	(((u32)(dev) ^ (u32)(ino) ^ (u32)(pos)))
 
 struct file_entry;
-extern long fd_id_entry_collect(const struct file_entry *p, pid_t pid, int fd);
+extern long fd_id_entry_collect(const struct file_entry *p, pid_t pid, int fd,
+				u8 *new_entry);
 
 #endif /* FILE_IDS_H__ */


More information about the CRIU mailing list