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

Andrei Vagin avagin at openvz.org
Wed Nov 8 03:36:04 MSK 2017


From: Andrei Vagin <avagin at virtuozzo.com>

v2: and move it upper, because it is going to be used in ppb_alloc()
Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 criu/page-pipe.c | 65 ++++++++++++++++++++++++++++++++------------------------
 1 file changed, 37 insertions(+), 28 deletions(-)

diff --git a/criu/page-pipe.c b/criu/page-pipe.c
index 4eabb5ed5..0f5e39ee2 100644
--- a/criu/page-pipe.c
+++ b/criu/page-pipe.c
@@ -28,6 +28,41 @@ static inline void iov_init(struct iovec *iov, unsigned long addr)
 	iov->iov_len = PAGE_SIZE;
 }
 
+static int __ppb_resize_pipe(struct page_pipe_buf *ppb, unsigned long new_size)
+{
+	int ret;
+
+	ret = fcntl(ppb->p[0], F_SETPIPE_SZ, new_size * PAGE_SIZE);
+	if (ret < 0)
+		return -1;
+
+	ret /= PAGE_SIZE;
+	BUG_ON(ret < ppb->pipe_size);
+
+	pr_debug("Grow pipe %x -> %x\n", ppb->pipe_size, ret);
+	ppb->pipe_size = ret;
+
+	return 0;
+}
+
+static inline int ppb_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 struct page_pipe_buf *ppb_alloc(struct page_pipe *pp)
 {
 	struct page_pipe_buf *ppb;
@@ -69,23 +104,6 @@ static void ppb_init(struct page_pipe_buf *ppb, unsigned int pages_in,
 	ppb->iov = iov;
 }
 
-static int ppb_resize_pipe(struct page_pipe_buf *ppb, unsigned long new_size)
-{
-	int ret;
-
-	ret = fcntl(ppb->p[0], F_SETPIPE_SZ, new_size * PAGE_SIZE);
-	if (ret < 0)
-		return -1;
-
-	ret /= PAGE_SIZE;
-	BUG_ON(ret < ppb->pipe_size);
-
-	pr_debug("Grow pipe %x -> %x\n", ppb->pipe_size, ret);
-	ppb->pipe_size = ret;
-
-	return 0;
-}
-
 static int page_pipe_grow(struct page_pipe *pp, unsigned int flags)
 {
 	struct page_pipe_buf *ppb;
@@ -195,17 +213,8 @@ static inline int try_add_page_to(struct page_pipe *pp, struct page_pipe_buf *pp
 	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 (ppb_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