[CRIU] [PATCH v2 19/30] files: Add fake fle flag and close such fles after restore files

Kirill Tkhai ktkhai at virtuozzo.com
Wed Jun 7 14:29:01 MSK 2017


Allow to mark some fles as "fake" and close them, when they are not needed.

v2: Cache fake file in separate list, when they are restored,
to do not iterate over files list again.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/files.c         |   21 ++++++++++++++++++++-
 criu/include/files.h |    1 +
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/criu/files.c b/criu/files.c
index a2b57ca01..2b3d2a8f1 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -710,6 +710,7 @@ static struct fdinfo_list_entry *alloc_fle(int pid, FdinfoEntry *fe)
 	fle->pid = pid;
 	fle->fe = fe;
 	fle->received = 0;
+	fle->fake = 0;
 	fle->stage = FLE_INITIALIZED;
 	fle->task = pstree_item_by_virt(pid);
 	if (!fle->task) {
@@ -1156,11 +1157,20 @@ static int receive_fd(struct fdinfo_list_entry *fle)
 	return 0;
 }
 
+static void close_fdinfos(struct list_head *list)
+{
+	struct fdinfo_list_entry *fle;
+
+	list_for_each_entry(fle, list, ps_list)
+		close(fle->fe->fd);
+}
+
 static int open_fdinfos(struct pstree_item *me)
 {
 	struct list_head *list = &rsti(me)->fds;
 	struct fdinfo_list_entry *fle, *tmp;
 	LIST_HEAD(completed);
+	LIST_HEAD(fake);
 	bool progress, again;
 	int st, ret = 0;
 
@@ -1183,7 +1193,10 @@ static int open_fdinfos(struct pstree_item *me)
 				 * and reduce number of fles in their checks.
 				 */
 				list_del(&fle->ps_list);
-				list_add(&fle->ps_list, &completed);
+				if (!fle->fake)
+					list_add(&fle->ps_list, &completed);
+				else
+					list_add(&fle->ps_list, &fake);
 			}
 			if (ret == 1)
 			       again = true;
@@ -1193,7 +1206,13 @@ static int open_fdinfos(struct pstree_item *me)
 	} while (again || progress);
 
 	BUG_ON(!list_empty(list));
+	/*
+	 * Fake fles may be used for restore other
+	 * file types, so their closing is delayed.
+	 */
+	close_fdinfos(&fake);
 splice:
+	list_splice(&fake, list);
 	list_splice(&completed, list);
 
 	return ret;
diff --git a/criu/include/files.h b/criu/include/files.h
index fd2d20761..fb47eb879 100644
--- a/criu/include/files.h
+++ b/criu/include/files.h
@@ -80,6 +80,7 @@ struct fdinfo_list_entry {
 	FdinfoEntry		*fe;
 	u8			received:1;
 	u8			stage:3;
+	u8			fake:1;
 };
 
 /* reports whether fd_a takes prio over fd_b */



More information about the CRIU mailing list