[CRIU] [PATCH] pp: Introduce page pipe flags

Pavel Emelyanov xemul at virtuozzo.com
Tue Jul 5 23:54:59 PDT 2016


We already have 3 bool-s on this struct and are going to
have the 4th %) Time to turn this into classical flags.

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>

---

 criu/include/page-pipe.h | 13 +++++++------
 criu/mem.c               |  8 ++++++--
 criu/page-pipe.c         | 28 +++++++++++++---------------
 criu/page-xfer.c         |  6 +++---
 criu/shmem.c             |  2 +-
 5 files changed, 30 insertions(+), 27 deletions(-)

diff --git a/criu/include/page-pipe.h b/criu/include/page-pipe.h
index f07afc8..03dd129 100644
--- a/criu/include/page-pipe.h
+++ b/criu/include/page-pipe.h
@@ -93,20 +93,21 @@ struct page_pipe {
 	unsigned int free_hole;	/* number of holes in use */
 	struct iovec *holes;	/* holes */
 
-	bool chunk_mode;	/* Restrict the maximum buffer size of pipes
-				   and dump memory for a few iterations */
-	bool compat_iov;	/* Use compatible iovs (struct compat_iovec) */
-	bool own_iovs;		/* create_page_pipe allocated IOVs memory */
+	unsigned flags;		/* PP_FOO flags below */
 };
 
+#define PP_CHUNK_MODE	0x1	/* Restrict the maximum buffer size of pipes
+				   and dump memory for a few iterations */
+#define PP_COMPAT	0x2	/* Use compatible iovs (struct compat_iovec) */
+#define PP_OWN_IOVS	0x4	/* create_page_pipe allocated IOVs memory */
+
 /* XXX: move to arch-depended file, when non-x86 add support for compat mode */
 struct iovec_compat {
 	u32	iov_base;
 	u32	iov_len;
 };
 
-extern struct page_pipe *create_page_pipe(unsigned int nr, struct iovec *,
-					bool chunk_mode, bool compat_iov);
+extern struct page_pipe *create_page_pipe(unsigned int nr, struct iovec *, unsigned flags);
 extern void destroy_page_pipe(struct page_pipe *p);
 extern int page_pipe_add_page(struct page_pipe *p, unsigned long addr,
 			      unsigned int flags);
diff --git a/criu/mem.c b/criu/mem.c
index 9e24951..03f9e21 100644
--- a/criu/mem.c
+++ b/criu/mem.c
@@ -273,6 +273,7 @@ static int __parasite_dump_pages_seized(struct parasite_ctl *ctl,
 	struct vma_area *vma_area;
 	struct page_xfer xfer = { .parent = NULL };
 	int ret = -1;
+	unsigned cpp_flags = 0;
 
 	pr_info("\n");
 	pr_info("Dumping pages (type: %d pid: %d)\n", CR_FD_PAGES, ctl->pid.real);
@@ -292,8 +293,11 @@ static int __parasite_dump_pages_seized(struct parasite_ctl *ctl,
 		return -1;
 
 	ret = -1;
-	pp = create_page_pipe(vma_area_list->priv_size, pargs_iovs(args),
-				pp_ret == NULL, !seized_native(ctl));
+	if (pp_ret == NULL)
+		cpp_flags |= PP_CHUNK_MODE;
+	if (!seized_native(ctl))
+		cpp_flags |= PP_COMPAT;
+	pp = create_page_pipe(vma_area_list->priv_size, pargs_iovs(args), cpp_flags);
 	if (!pp)
 		goto out;
 
diff --git a/criu/page-pipe.c b/criu/page-pipe.c
index c4a63d1..d2e9da5 100644
--- a/criu/page-pipe.c
+++ b/criu/page-pipe.c
@@ -119,7 +119,7 @@ static int page_pipe_grow(struct page_pipe *pp, unsigned int flags)
 		goto out;
 	}
 
-	if (pp->chunk_mode && pp->nr_pipes == NR_PIPES_PER_CHUNK)
+	if ((pp->flags & PP_CHUNK_MODE) && pp->nr_pipes == NR_PIPES_PER_CHUNK)
 		return -EAGAIN;
 
 	ppb = ppb_alloc(pp);
@@ -127,7 +127,7 @@ static int page_pipe_grow(struct page_pipe *pp, unsigned int flags)
 		return -1;
 
 out:
-	if (pp->compat_iov)
+	if (pp->flags & PP_COMPAT)
 		free_iov = (void*)&((struct iovec_compat*)pp->iovs)[pp->free_iov];
 	else
 		free_iov = &pp->iovs[pp->free_iov];
@@ -136,8 +136,7 @@ out:
 	return 0;
 }
 
-struct page_pipe *create_page_pipe(unsigned int nr_segs, struct iovec *iovs,
-		bool chunk_mode, bool compat_iov)
+struct page_pipe *create_page_pipe(unsigned int nr_segs, struct iovec *iovs, unsigned flags)
 {
 	struct page_pipe *pp;
 
@@ -147,11 +146,13 @@ struct page_pipe *create_page_pipe(unsigned int nr_segs, struct iovec *iovs,
 	if (!pp)
 		return NULL;
 
+	pp->flags = flags;
+
 	if (!iovs) {
 		iovs = xmalloc(sizeof(*iovs) * nr_segs);
 		if (!iovs)
 			goto err_free_pp;
-		pp->own_iovs = true;
+		pp->flags |= PP_OWN_IOVS;
 	}
 
 	pp->nr_pipes = 0;
@@ -165,16 +166,13 @@ struct page_pipe *create_page_pipe(unsigned int nr_segs, struct iovec *iovs,
 	pp->free_hole = 0;
 	pp->holes = NULL;
 
-	pp->chunk_mode = chunk_mode;
-	pp->compat_iov = compat_iov;
-
 	if (page_pipe_grow(pp, 0))
 		goto err_free_iovs;
 
 	return pp;
 
 err_free_iovs:
-	if (pp->own_iovs)
+	if (pp->flags & PP_OWN_IOVS)
 		xfree(iovs);
 err_free_pp:
 	xfree(pp);
@@ -191,7 +189,7 @@ 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)
+	if (pp->flags & PP_OWN_IOVS)
 		xfree(pp->iovs);
 	xfree(pp);
 }
@@ -200,7 +198,7 @@ void page_pipe_reinit(struct page_pipe *pp)
 {
 	struct page_pipe_buf *ppb, *n;
 
-	BUG_ON(!pp->chunk_mode);
+	BUG_ON(!(pp->flags & PP_CHUNK_MODE));
 
 	pr_debug("Clean up page pipe\n");
 
@@ -242,7 +240,7 @@ static inline int try_add_page_to(struct page_pipe *pp, struct page_pipe_buf *pp
 
 	pr_debug("Add iov to page pipe (%u iovs, %u/%u total)\n",
 			ppb->nr_segs, pp->free_iov, pp->nr_iovs);
-	if (pp->compat_iov) {
+	if (pp->flags & PP_COMPAT) {
 		struct iovec_compat *iovs = (void *)ppb->iov;
 
 		iov_init_compat(&iovs[ppb->nr_segs++], addr);
@@ -298,7 +296,7 @@ int page_pipe_add_hole(struct page_pipe *pp, unsigned long addr)
 			iov_grow_page(&pp->holes[pp->free_hole - 1], addr))
 		goto out;
 
-	if (pp->compat_iov) {
+	if (pp->flags & PP_COMPAT) {
 		struct iovec_compat *iovs = (void *)pp->holes;
 
 		iov_init_compat(&iovs[pp->free_hole++], addr);
@@ -487,7 +485,7 @@ void debug_show_page_pipe(struct page_pipe *pp)
 		pr_debug("\tbuf %u pages, %u iovs, flags: %x :\n",
 			 ppb->pages_in, ppb->nr_segs, ppb->flags);
 		for (i = 0; i < ppb->nr_segs; i++) {
-			if (pp->compat_iov) {
+			if (pp->flags & PP_COMPAT) {
 				iov_c = (void *)ppb->iov;
 				pr_debug("\t\t%x %lu\n", iov_c[i].iov_base,
 						iov_c[i].iov_len / PAGE_SIZE);
@@ -501,7 +499,7 @@ void debug_show_page_pipe(struct page_pipe *pp)
 
 	pr_debug("* %u holes:\n", pp->free_hole);
 	for (i = 0; i < pp->free_hole; i++) {
-		if (pp->compat_iov) {
+		if (pp->flags & PP_COMPAT) {
 			iov_c = (void *)pp->holes;
 			pr_debug("\t%x %lu\n", iov_c[i].iov_base,
 					iov_c[i].iov_len / PAGE_SIZE);
diff --git a/criu/page-xfer.c b/criu/page-xfer.c
index 967a587..b998511 100644
--- a/criu/page-xfer.c
+++ b/criu/page-xfer.c
@@ -364,11 +364,11 @@ int page_xfer_dump_pages(struct page_xfer *xfer, struct page_pipe *pp,
 		pr_debug("\tbuf %d/%d\n", ppb->pages_in, ppb->nr_segs);
 
 		for (i = 0; i < ppb->nr_segs; i++) {
-			struct iovec iov = get_iov(ppb->iov, i, pp->compat_iov);
+			struct iovec iov = get_iov(ppb->iov, i, pp->flags & PP_COMPAT);
 
 			for (; cur_hole < pp->free_hole ; cur_hole++) {
 				struct iovec hole = get_iov(pp->holes, cur_hole,
-						pp->compat_iov);
+						pp->flags & PP_COMPAT);
 
 				if (hole.iov_base >= iov.iov_base)
 					break;
@@ -390,7 +390,7 @@ int page_xfer_dump_pages(struct page_xfer *xfer, struct page_pipe *pp,
 	}
 
 	for (; cur_hole < pp->free_hole ; cur_hole++) {
-		struct iovec hole = get_iov(pp->holes, cur_hole, pp->compat_iov);
+		struct iovec hole = get_iov(pp->holes, cur_hole, pp->flags & PP_COMPAT);
 
 		ret = page_xfer_dump_hole(xfer, &hole, off);
 		if (ret)
diff --git a/criu/shmem.c b/criu/shmem.c
index 9fe76ef..c4a58e5 100644
--- a/criu/shmem.c
+++ b/criu/shmem.c
@@ -564,7 +564,7 @@ static int dump_one_shmem(struct shmem_info *si)
 	if (err)
 		goto err_unmap;
 
-	pp = create_page_pipe((nrpages + 1) / 2, NULL, true, false);
+	pp = create_page_pipe((nrpages + 1) / 2, NULL, PP_CHUNK_MODE);
 	if (!pp)
 		goto err_unmap;
 
-- 
2.5.0


More information about the CRIU mailing list