[CRIU] [PATCH RFC 17/30] files: Merge states iteration into open_fdinfos()

Kirill Tkhai ktkhai at virtuozzo.com
Tue Nov 1 07:33:10 PDT 2016


TTY masters and slaves have no post_open stage,
so these two blocks may be safely merged together.

The third is eventpoll, but two above do not depend
on it (unix sockets would be, but this isn't implemented yet).

So, we may safely execute all stages for different
file types separatelly.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/files.c |   62 +++++++++++++++++++++++-----------------------------------
 1 file changed, 25 insertions(+), 37 deletions(-)

diff --git a/criu/files.c b/criu/files.c
index 7de9f61..29ff9d1 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -1063,15 +1063,17 @@ static int open_fdinfo(int pid, struct fdinfo_list_entry *fle, int state)
 	return states[state].cb(pid, fle);
 }
 
-static int open_fdinfos(int pid, struct list_head *list, int state)
+static int open_fdinfos(int pid, struct list_head *list)
 {
-	int ret = 0;
+	int state, ret = 0;
 	struct fdinfo_list_entry *fle;
 
-	list_for_each_entry(fle, list, ps_list) {
-		ret = open_fdinfo(pid, fle, state);
-		if (ret)
-			break;
+	for (state = 0; state < ARRAY_SIZE(states); state++) {
+		list_for_each_entry(fle, list, ps_list) {
+			ret = open_fdinfo(pid, fle, state);
+			if (ret)
+				break;
+		}
 	}
 
 	return ret;
@@ -1115,7 +1117,6 @@ static int open_transport_socket(pid_t pid);
 int prepare_fds(struct pstree_item *me)
 {
 	u32 ret = 0;
-	int state;
 
 	pr_info("Opening fdinfo-s\n");
 
@@ -1149,41 +1150,28 @@ int prepare_fds(struct pstree_item *me)
 	if (open_transport_socket(me->pid.virt))
 		return -1;
 
-	for (state = 0; state < ARRAY_SIZE(states); state++) {
-		ret = open_fdinfos(me->pid.virt, &rsti(me)->fds, state);
-		if (ret)
-			break;
-
-		/*
-		 * Now handle TTYs. Slaves are delayed to be sure masters
-		 * are already opened.
-		 */
-		ret = open_fdinfos(me->pid.virt, &rsti(me)->tty_slaves, state);
-		if (ret)
-			break;
+	ret = open_fdinfos(me->pid.virt, &rsti(me)->fds);
+	if (ret)
+		goto out_w;
 
-		/*
-		 * The eventpoll descriptors require all the other ones
-		 * to be already restored, thus we store them in a separate
-		 * list and restore at the very end.
-		 */
-		ret = open_fdinfos(me->pid.virt, &rsti(me)->eventpoll, state);
-		if (ret)
-			break;
-	}
+	/*
+	 * Now handle TTYs. Slaves are delayed to be sure masters
+	 * are already opened.
+	 */
+	ret = open_fdinfos(me->pid.virt, &rsti(me)->tty_slaves);
+	if (ret)
+		goto out_w;
 
+	/*
+	 * The eventpoll descriptors require all the other ones
+	 * to be already restored, thus we store them in a separate
+	 * list and restore at the very end.
+	 */
+	ret = open_fdinfos(me->pid.virt, &rsti(me)->eventpoll);
 	if (ret)
 		goto out_w;
 
-	for (state = 0; state < ARRAY_SIZE(states); state++) {
-		/*
-		 * Opening current TTYs require session to be already set up,
-		 * thus slave peers already handled now it's time for cttys,
-		 */
-		ret = open_fdinfos(me->pid.virt, &rsti(me)->tty_ctty, state);
-		if (ret)
-			break;
-	}
+	ret = open_fdinfos(me->pid.virt, &rsti(me)->tty_ctty);
 out_w:
 	if (rsti(me)->fdt)
 		futex_inc_and_wake(&rsti(me)->fdt->fdt_lock);



More information about the CRIU mailing list