[CRIU] [PATCH 3/4] page-pipe: move code to resize a pipe in a separate function

Andrei Vagin avagin at openvz.org
Tue Nov 7 03:02:36 MSK 2017


From: Andrei Vagin <avagin at virtuozzo.com>

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 criu/page-pipe.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/criu/page-pipe.c b/criu/page-pipe.c
index 4eabb5ed5..adad1819d 100644
--- a/criu/page-pipe.c
+++ b/criu/page-pipe.c
@@ -189,23 +189,32 @@ void page_pipe_reinit(struct page_pipe *pp)
 		BUG(); /* It can't fail, because ppb is in free_bufs */
 }
 
+static inline int resize_pipe(struct page_pipe_buf *ppb)
+{
+	unsigned long new_size = ppb->pipe_size << 1;
+	int ret;
+
+	if (ppb->pages_in < ppb->pipe_size)
+		return 0;
+
+	if (new_size > PIPE_MAX_SIZE)
+		return 1;
+
+	ret = ppb_resize_pipe(ppb, new_size);
+	if (ret < 0)
+		return 1; /* need to add another buf */
+
+	return 0;
+}
+
 static inline int try_add_page_to(struct page_pipe *pp, struct page_pipe_buf *ppb,
 		unsigned long addr, unsigned int flags)
 {
 	if (ppb->flags != flags)
 		return 1;
 
-	if (ppb->pages_in == ppb->pipe_size) {
-		unsigned long new_size = ppb->pipe_size << 1;
-		int ret;
-
-		if (new_size > PIPE_MAX_SIZE)
-			return 1;
-
-		ret = ppb_resize_pipe(ppb, new_size);
-		if (ret < 0)
-			return 1; /* need to add another buf */
-	}
+	if (resize_pipe(ppb) == 1)
+		return 1;
 
 	if (ppb->nr_segs && iov_grow_page(&ppb->iov[ppb->nr_segs - 1], addr))
 			goto out;
-- 
2.13.6



More information about the CRIU mailing list