[CRIU] [PATCH 12/18] fd: Split fdinfo collect routine

Pavel Emelyanov xemul at virtuozzo.com
Mon Jul 10 12:40:36 MSK 2017


In SCM code there will be the need to attach a newly created
FdinfoEntry to a particulat file desc object, then get the
created fdinfo helper object back.

Current code only allows this via two lookup calls -- first
one to attach entry to desc by ID (lookup #1), then get the
fdinfo helper by FD (lookup #2).

Fortunately, the exising code allows simple split that gives
us the optimized routine.

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/files.c         | 26 ++++++++++++++++++--------
 criu/include/files.h |  2 ++
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/criu/files.c b/criu/files.c
index bd137df..91f7c85 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -802,26 +802,36 @@ compare_pid:
 	list_add_tail(&new_le->desc_list, &le->desc_list);
 }
 
-int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info, bool fake)
+struct fdinfo_list_entry *collect_fd_to(int pid, FdinfoEntry *e,
+		struct rst_info *rst_info, struct file_desc *fdesc, bool fake)
 {
 	struct fdinfo_list_entry *new_le;
+
+	new_le = alloc_fle(pid, e);
+	if (new_le) {
+		new_le->fake = (!!fake);
+		collect_desc_fle(new_le, fdesc);
+		collect_task_fd(new_le, rst_info);
+	}
+
+	return new_le;
+}
+
+int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info, bool fake)
+{
 	struct file_desc *fdesc;
 
 	pr_info("Collect fdinfo pid=%d fd=%d id=%#x\n",
 		pid, e->fd, e->id);
 
-	new_le = alloc_fle(pid, e);
-	if (!new_le)
-		return -1;
-	new_le->fake = (!!fake);
-
 	fdesc = find_file_desc(e);
 	if (fdesc == NULL) {
 		pr_err("No file for fd %d id %#x\n", e->fd, e->id);
 		return -1;
 	}
-	collect_desc_fle(new_le, fdesc);
-	collect_task_fd(new_le, rst_info);
+
+	if (!collect_fd_to(pid, e, rst_info, fdesc, fake))
+		return -1;
 
 	return 0;
 }
diff --git a/criu/include/files.h b/criu/include/files.h
index eeae8e0..eb32065 100644
--- a/criu/include/files.h
+++ b/criu/include/files.h
@@ -109,6 +109,8 @@ struct file_desc_ops {
 };
 
 int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info, bool ghost);
+struct fdinfo_list_entry *collect_fd_to(int pid, FdinfoEntry *e,
+		struct rst_info *rst_info, struct file_desc *fdesc, bool fake);
 
 unsigned int find_unused_fd(struct pstree_item *, int hint_fd);
 struct fdinfo_list_entry *find_used_fd(struct pstree_item *, int fd);
-- 
2.1.4



More information about the CRIU mailing list