[CRIU] [PATCH v4 11/12] criu: page-pipe: add ability to allocate IOVs

Mike Rapoport rppt at linux.vnet.ibm.com
Sun Jun 5 23:27:44 PDT 2016


When collection of dumpee pages is followed by any parasite operation, we
cannot share iovs between parasite args area and page-pipe.

Signed-off-by: Mike Rapoport <rppt at linux.vnet.ibm.com>
---
 criu/include/page-pipe.h |  1 +
 criu/page-pipe.c         | 44 ++++++++++++++++++++++++++++----------------
 2 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/criu/include/page-pipe.h b/criu/include/page-pipe.h
index 696dc9f..ca129fd 100644
--- a/criu/include/page-pipe.h
+++ b/criu/include/page-pipe.h
@@ -95,6 +95,7 @@ struct page_pipe {
 
 	bool chunk_mode;	/* Restrict the maximum buffer size of pipes
 				   and dump memory for a few iterations */
+	bool own_iovs;		/* create_page_pipe allocated IOVs memory */
 };
 
 extern struct page_pipe *create_page_pipe(unsigned int nr,
diff --git a/criu/page-pipe.c b/criu/page-pipe.c
index 5faf155..2b58aa9 100644
--- a/criu/page-pipe.c
+++ b/criu/page-pipe.c
@@ -132,25 +132,35 @@ struct page_pipe *create_page_pipe(unsigned int nr_segs,
 
 	pr_debug("Create page pipe for %u segs\n", nr_segs);
 
-	pp = xmalloc(sizeof(*pp));
-	if (pp) {
-		pp->nr_pipes = 0;
-		INIT_LIST_HEAD(&pp->bufs);
-		INIT_LIST_HEAD(&pp->free_bufs);
-		pp->nr_iovs = nr_segs;
-		pp->iovs = iovs;
-		pp->free_iov = 0;
-
-		pp->nr_holes = 0;
-		pp->free_hole = 0;
-		pp->holes = NULL;
-
-		pp->chunk_mode = chunk_mode;
-
-		if (page_pipe_grow(pp, 0))
+	pp = xzalloc(sizeof(*pp));
+	if (!pp)
+		return NULL;
+
+	if (!iovs) {
+		iovs = xmalloc(sizeof(*iovs) * nr_segs);
+		if (!iovs) {
+			xfree(pp);
 			return NULL;
+		}
+		pp->own_iovs = true;
 	}
 
+	pp->nr_pipes = 0;
+	INIT_LIST_HEAD(&pp->bufs);
+	INIT_LIST_HEAD(&pp->free_bufs);
+	pp->nr_iovs = nr_segs;
+	pp->iovs = iovs;
+	pp->free_iov = 0;
+
+	pp->nr_holes = 0;
+	pp->free_hole = 0;
+	pp->holes = NULL;
+
+	pp->chunk_mode = chunk_mode;
+
+	if (page_pipe_grow(pp, 0))
+		return NULL;
+
 	return pp;
 }
 
@@ -164,6 +174,8 @@ void destroy_page_pipe(struct page_pipe *pp)
 	list_for_each_entry_safe(ppb, n, &pp->bufs, l)
 		ppb_destroy(ppb);
 
+	if (pp->own_iovs)
+		xfree(pp->iovs);
 	xfree(pp);
 }
 
-- 
1.9.1



More information about the CRIU mailing list