[CRIU] [PATCH 06/12] dump: files tree - return id upon collect instead on inner structure

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


From: Stanislav Kinsbursky <skinsbursky at openvz.org>

Hide the structure - it's not required.

Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
---
 cr-dump.c          |   14 ++++----------
 file-ids.c         |   31 ++++++++++++++++++++++++++++++-
 include/file-ids.h |   19 +------------------
 3 files changed, 35 insertions(+), 29 deletions(-)
-------------- next part --------------
diff --git a/cr-dump.c b/cr-dump.c
index 35c2887..abc3671 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -121,20 +121,14 @@ 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))) {
-		struct fd_id_entry *entry;
+		long id;
 
-		/*
-		 * Make sure the union is still correlate with structure
-		 * we write to disk.
-		 */
-		BUILD_BUG_ON(sizeof(entry->u.key) != sizeof(e.fde.id));
-
-		entry = fd_id_entry_collect((u32)p->id, pid, target_fd);
-		if (!entry)
+		id = fd_id_entry_collect((u32)p->id, pid, target_fd);
+		if (id < 0)
 			goto err;
 
 		/* Now it might have completely new ID here */
-		e.fde.id = entry->u.id;
+		e.fde.id = id;
 	}
 
 	pr_info("fdinfo: type: %2x len: %2x flags: %4x pos: %8lx addr: %16lx\n",
diff --git a/file-ids.c b/file-ids.c
index 9bb7b96..c5cc29f 100644
--- a/file-ids.c
+++ b/file-ids.c
@@ -58,6 +58,24 @@
  * in one pass.
  */
 
+struct fd_id_entry {
+	struct rb_node	node;
+
+	struct rb_root	subtree_root;
+	struct rb_node	subtree_node;
+
+	union {
+		struct {
+			u32		genid;	/* generic id, may have duplicates */
+			u32		subid;	/* subid is always unique */
+		} key;
+		u64			id;
+	} u;
+
+	struct file_info	info;
+} __aligned(sizeof(long));
+
+
 struct rb_root fd_id_root;
 static unsigned long fd_id_entries_subid = 1;
 
@@ -115,7 +133,7 @@ err:
 	return sub;
 }
 
-struct fd_id_entry *fd_id_entry_collect(u32 genid, pid_t pid, int fd)
+static struct fd_id_entry *lookup_alloc_node(u64 genid, pid_t pid, int fd)
 {
 	struct rb_node *node = fd_id_root.rb_node;
 	struct fd_id_entry *e = NULL;
@@ -142,4 +160,15 @@ struct fd_id_entry *fd_id_entry_collect(u32 genid, pid_t pid, int fd)
 	rb_link_and_balance(&fd_id_root, &e->node, parent, new);
 err:
 	return e;
+
+}
+
+long fd_id_entry_collect(u64 genid, pid_t pid, int fd)
+{
+	struct fd_id_entry *e = NULL;
+
+	e = lookup_alloc_node(genid, pid, fd);
+	if (e == NULL)
+		return -ENOMEM;
+	return e->u.id;
 }
diff --git a/include/file-ids.h b/include/file-ids.h
index dc36cbc..1725545 100644
--- a/include/file-ids.h
+++ b/include/file-ids.h
@@ -13,26 +13,9 @@ struct file_info {
 	int			pid;
 };
 
-struct fd_id_entry {
-	struct rb_node	node;
-
-	struct rb_root	subtree_root;
-	struct rb_node	subtree_node;
-
-	union {
-		struct {
-			u32		genid;	/* generic id, may have duplicates */
-			u32		subid;	/* subid is always unique */
-		} key;
-		u64			id;
-	} u;
-
-	struct file_info	info;
-} __aligned(sizeof(long));
-
 #define MAKE_FD_GENID(dev, ino, pos) \
 	(((u32)(dev) ^ (u32)(ino) ^ (u32)(pos)))
 
-extern struct fd_id_entry *fd_id_entry_collect(u32 genid, pid_t pid, int fd);
+extern long fd_id_entry_collect(u64 genid, pid_t pid, int fd);
 
 #endif /* FILE_IDS_H__ */


More information about the CRIU mailing list