[CRIU] [PATCH v6 12/13] files: Merge collect_gen_fd() and collect_used_fd(), and call it unconditionally

Kirill Tkhai ktkhai at virtuozzo.com
Wed Jan 18 03:59:14 PST 2017


Since we keep files of all types in a single list (fds), it's possible
to use only function for that and to call it unconditionally.

v4: New

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/autofs.c        |    4 +---
 criu/fifo.c          |    1 -
 criu/files-reg.c     |    7 -------
 criu/files.c         |   10 ++++++----
 criu/include/files.h |    7 +------
 5 files changed, 8 insertions(+), 21 deletions(-)

diff --git a/criu/autofs.c b/criu/autofs.c
index c8237dba9..3ce84af2a 100644
--- a/criu/autofs.c
+++ b/criu/autofs.c
@@ -875,9 +875,7 @@ static int autofs_create_fle(struct pstree_item *task, FdinfoEntry *fe,
 
 	fle_init(le, task->pid.virt, fe);
 
-	collect_gen_fd(le, rst_info);
-
-	collect_used_fd(le, rst_info);
+	collect_task_fd(le, rst_info);
 
 	list_add_tail(&le->desc_list, &desc->fd_info_head);
 	le->desc = desc;
diff --git a/criu/fifo.c b/criu/fifo.c
index cb642befc..5e2b44ff5 100644
--- a/criu/fifo.c
+++ b/criu/fifo.c
@@ -126,7 +126,6 @@ static void collect_fifo_fd(struct file_desc *d,
 	info = container_of(d, struct fifo_info, d);
 	info->reg_d = collect_special_file(info->fe->id);
 	BUG_ON(info->reg_d == NULL);
-	collect_gen_fd(fle, ri);
 }
 
 static struct file_desc_ops fifo_desc_ops = {
diff --git a/criu/files-reg.c b/criu/files-reg.c
index 6e488e898..79a811e1f 100644
--- a/criu/files-reg.c
+++ b/criu/files-reg.c
@@ -1653,12 +1653,6 @@ int collect_filemap(struct vma_area *vma)
 	return 0;
 }
 
-static void collect_reg_fd(struct file_desc *fdesc,
-		struct fdinfo_list_entry *fle, struct rst_info *ri)
-{
-	collect_gen_fd(fle, ri);
-}
-
 static int open_fe_fd(struct file_desc *fd, int *new_fd)
 {
 	int tmp;
@@ -1681,7 +1675,6 @@ static char *reg_file_path(struct file_desc *d, char *buf, size_t s)
 static struct file_desc_ops reg_desc_ops = {
 	.type = FD_TYPES__REG,
 	.open = open_fe_fd,
-	.collect_fd = collect_reg_fd,
 	.name = reg_file_path,
 };
 
diff --git a/criu/files.c b/criu/files.c
index 7e48fcfbf..3d12532ac 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -112,10 +112,14 @@ struct fdinfo_list_entry *find_used_fd(struct list_head *head, int fd)
 	return NULL;
 }
 
-void collect_used_fd(struct fdinfo_list_entry *new_fle, struct rst_info *ri)
+void collect_task_fd(struct fdinfo_list_entry *new_fle, struct rst_info *ri)
 {
 	struct fdinfo_list_entry *fle;
 
+	/* fles in fds list are disordered */
+	list_add_tail(&new_fle->ps_list, &ri->fds);
+
+	/* fles in used list are ordered by fd */
 	list_for_each_entry(fle, &ri->used, used_list) {
 		if (new_fle->fe->fd < fle->fe->fd)
 			break;
@@ -705,10 +709,8 @@ static int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info)
 
 	if (fdesc->ops->collect_fd)
 		fdesc->ops->collect_fd(fdesc, new_le, rst_info);
-	else
-		collect_gen_fd(new_le, rst_info);
 
-	collect_used_fd(new_le, rst_info);
+	collect_task_fd(new_le, rst_info);
 
 	list_add_tail(&new_le->desc_list, &le->desc_list);
 	new_le->desc = fdesc;
diff --git a/criu/include/files.h b/criu/include/files.h
index cd7c4608d..39ef23b77 100644
--- a/criu/include/files.h
+++ b/criu/include/files.h
@@ -115,12 +115,7 @@ struct file_desc_ops {
 	char *			(*name)(struct file_desc *, char *b, size_t s);
 };
 
-extern void collect_used_fd(struct fdinfo_list_entry *new_fle, struct rst_info *ri);
-
-static inline void collect_gen_fd(struct fdinfo_list_entry *fle, struct rst_info *ri)
-{
-	list_add_tail(&fle->ps_list, &ri->fds);
-}
+void collect_task_fd(struct fdinfo_list_entry *new_fle, struct rst_info *ri);
 
 unsigned int find_unused_fd(struct list_head *head, int hint_fd);
 struct fdinfo_list_entry *find_used_fd(struct list_head *head, int fd);



More information about the CRIU mailing list