[CRIU] [PATCH 4/4] files: Keep single sorted list of fds

Pavel Emelyanov xemul at virtuozzo.com
Fri Feb 10 04:06:00 PST 2017


After fds restore set merge we no longer need two lists.

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>

---
 criu/eventpoll.c        |  2 +-
 criu/files.c            | 20 ++++++++------------
 criu/include/files.h    |  1 -
 criu/include/rst_info.h |  1 -
 4 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/criu/eventpoll.c b/criu/eventpoll.c
index e8831c1..3aaae4a 100644
--- a/criu/eventpoll.c
+++ b/criu/eventpoll.c
@@ -153,7 +153,7 @@ static int epoll_not_ready_tfd(EventpollTfdEntry *tdefe)
 {
 	struct fdinfo_list_entry *fle;
 
-	list_for_each_entry(fle, &rsti(current)->used, used_list) {
+	list_for_each_entry(fle, &rsti(current)->fds, ps_list) {
 		if (tdefe->tfd != fle->fe->fd)
 			continue;
 
diff --git a/criu/files.c b/criu/files.c
index 6240062..f2ade30 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -103,8 +103,8 @@ struct fdinfo_list_entry *find_used_fd(struct pstree_item *task, int fd)
 	struct list_head *head;
 	struct fdinfo_list_entry *fle;
 
-	head = &rsti(task)->used;
-	list_for_each_entry_reverse(fle, head, used_list) {
+	head = &rsti(task)->fds;
+	list_for_each_entry_reverse(fle, head, ps_list) {
 		if (fle->fe->fd == fd)
 			return fle;
 		/* List is ordered, so let's stop */
@@ -118,16 +118,13 @@ 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) {
+	/* fles in fds list are ordered by fd */
+	list_for_each_entry(fle, &ri->fds, ps_list) {
 		if (new_fle->fe->fd < fle->fe->fd)
 			break;
 	}
 
-	list_add_tail(&new_fle->used_list, &fle->used_list);
+	list_add_tail(&new_fle->ps_list, &fle->ps_list);
 }
 
 unsigned int find_unused_fd(struct pstree_item *task, int hint_fd)
@@ -142,9 +139,9 @@ unsigned int find_unused_fd(struct pstree_item *task, int hint_fd)
 	}
 
 	prev_fd = service_fd_min_fd() - 1;
-	head = &rsti(task)->used;
+	head = &rsti(task)->fds;
 
-	list_for_each_entry_reverse(fle, head, used_list) {
+	list_for_each_entry_reverse(fle, head, ps_list) {
 		fd = fle->fe->fd;
 		if (prev_fd > fd) {
 			fd++;
@@ -788,7 +785,6 @@ int prepare_fd_pid(struct pstree_item *item)
 	pid_t pid = item->pid->ns[0].virt;
 	struct rst_info *rst_info = rsti(item);
 
-	INIT_LIST_HEAD(&rst_info->used);
 	INIT_LIST_HEAD(&rst_info->fds);
 
 	if (item->ids == NULL) /* zombie */
@@ -876,7 +872,7 @@ static bool task_fle(struct pstree_item *task, struct fdinfo_list_entry *fle)
 {
 	struct fdinfo_list_entry *tmp;
 
-	list_for_each_entry(tmp, &rsti(task)->used, used_list)
+	list_for_each_entry(tmp, &rsti(task)->fds, ps_list)
 		if (fle == tmp)
 			return true;
 	return false;
diff --git a/criu/include/files.h b/criu/include/files.h
index 036b9e6..2ec5a53 100644
--- a/criu/include/files.h
+++ b/criu/include/files.h
@@ -74,7 +74,6 @@ struct fdinfo_list_entry {
 	struct list_head	desc_list;	/* To chain on  @fd_info_head */
 	struct file_desc	*desc;		/* Associated file descriptor */
 	struct list_head	ps_list;	/* To chain  per-task files */
-	struct list_head	used_list;	/* To chain per-task used fds */
 	int			pid;
 	FdinfoEntry		*fe;
 	u8			received:1;
diff --git a/criu/include/rst_info.h b/criu/include/rst_info.h
index 82fbd56..92dfc9d 100644
--- a/criu/include/rst_info.h
+++ b/criu/include/rst_info.h
@@ -26,7 +26,6 @@ struct fdt {
 struct _MmEntry;
 
 struct rst_info {
-	struct list_head	used;
 	struct list_head	fds;
 
 	void			*premmapped_addr;
-- 
2.5.0



More information about the CRIU mailing list