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

Submitted by Kirill Tkhai on June 7, 2017, 11:29 a.m.

Details

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

Commit Message

Kirill Tkhai June 7, 2017, 11:29 a.m.
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@virtuozzo.com>
---
 criu/files.c         |   21 ++++++++++++++++++++-
 criu/include/files.h |    1 +
 2 files changed, 21 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

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 */