[23/28] files: Extract new_fle assignment from collect_fd() to separate func

Submitted by Kirill Tkhai on June 5, 2017, 5:26 p.m.

Details

Message ID 149668361176.25229.6310223527889340873.stgit@localhost.localdomain
State Accepted
Series "Support sockets leaked to child user_ns task"
Commit c7c7a8cbf155470ea24cb9d2dd90bfdd103d2219
Headers show

Commit Message

Kirill Tkhai June 5, 2017, 5:26 p.m.
The algorhythm of searching file master will be more complicated
in next patches. So, move current functionality in separate func.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/files.c |   23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/files.c b/criu/files.c
index fbf809641..a46dcf330 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -714,9 +714,21 @@  static struct fdinfo_list_entry *alloc_fle(int pid, FdinfoEntry *fe)
 	return fle;
 }
 
+static void collect_desc_fle(struct fdinfo_list_entry *new_le, struct file_desc *fdesc)
+{
+	struct fdinfo_list_entry *le;
+
+	new_le->desc = fdesc;
+
+	list_for_each_entry(le, &fdesc->fd_info_head, desc_list)
+		if (pid_rst_prio(new_le->pid, le->pid))
+			break;
+	list_add_tail(&new_le->desc_list, &le->desc_list);
+}
+
 int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info)
 {
-	struct fdinfo_list_entry *le, *new_le;
+	struct fdinfo_list_entry *new_le;
 	struct file_desc *fdesc;
 
 	pr_info("Collect fdinfo pid=%d fd=%d id=%#x\n",
@@ -731,16 +743,9 @@  int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info)
 		pr_err("No file for fd %d id %#x\n", e->fd, e->id);
 		return -1;
 	}
-	new_le->desc = fdesc;
-
-	list_for_each_entry(le, &fdesc->fd_info_head, desc_list)
-		if (pid_rst_prio(new_le->pid, le->pid))
-			break;
-
+	collect_desc_fle(new_le, fdesc);
 	collect_task_fd(new_le, rst_info);
 
-	list_add_tail(&new_le->desc_list, &le->desc_list);
-
 	return 0;
 }