lazy-pages: don't close page_read when a parent process exits

Submitted by Mike Rapoport on Sept. 7, 2017, 7:15 a.m.

Details

Message ID 1504768517-30824-1-git-send-email-rppt@linux.vnet.ibm.com
State New
Series "lazy-pages: don't close page_read when a parent process exits"
Headers show

Commit Message

Mike Rapoport Sept. 7, 2017, 7:15 a.m.
If there were fork()'s during lazy-restore we create a shallow copy of the
parent process' page-read. Since all the copies reference the same open
files, we cannot close the page-read until we finish restore of all the
processes that share the page-read.

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
---
Fixes faulure at Jenkins build 421
https://ci.openvz.org/job/CRIU/job/CRIU-lazy/job/criu-dev/421/

 criu/uffd.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/criu/uffd.c b/criu/uffd.c
index 494da85..bd5d2b9 100644
--- a/criu/uffd.c
+++ b/criu/uffd.c
@@ -109,6 +109,7 @@  struct lazy_pages_info {
 	struct list_head reqs;
 
 	struct lazy_pages_info *parent;
+	unsigned num_children;
 
 	struct page_read pr;
 
@@ -176,7 +177,9 @@  static void lpi_fini(struct lazy_pages_info *lpi)
 	free_vmas(lpi);
 	if (lpi->lpfd.fd > 0)
 		close(lpi->lpfd.fd);
-	if (!lpi->parent && lpi->pr.close)
+	if (lpi->parent)
+		lpi->parent->num_children--;
+	if (!lpi->parent && !lpi->num_children && lpi->pr.close)
 		lpi->pr.close(&lpi->pr);
 	free(lpi);
 }
@@ -1175,6 +1178,8 @@  static int handle_fork(struct lazy_pages_info *parent_lpi, struct uffd_msg *msg)
 
 	dup_page_read(&lpi->parent->pr, &lpi->pr);
 
+	lpi->parent->num_children++;
+
 	return 1;
 
 out: