[CRIU] [PATCH 2/2] pipe: dump all data from a pipe

Andrei Vagin avagin at openvz.org
Sat Dec 2 00:05:50 MSK 2017


From: Andrei Vagin <avagin at virtuozzo.com>

Currently we use an additional pipe to steal data from a pipe, but we
don't check that we steal all data. And the additional pipe can have a
smaller size.

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 criu/pipes.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/criu/pipes.c b/criu/pipes.c
index f1a66bf5d..a5856d429 100644
--- a/criu/pipes.c
+++ b/criu/pipes.c
@@ -168,6 +168,16 @@ int restore_pipe_data(int img_type, int pfd, u32 id, struct pipe_data_rst **hash
 		return -1;
 	}
 
+	if (pd->pde->has_size) {
+		pr_info("Restoring size %#x for %#x\n",
+				pd->pde->size, pd->pde->pipe_id);
+		ret = fcntl(pfd, F_SETPIPE_SZ, pd->pde->size);
+		if (ret < 0)
+			pr_perror("Can't restore pipe size");
+		else
+			ret = 0;
+	}
+
 	iov.iov_base = pd->data;
 	iov.iov_len = pd->pde->bytes;
 
@@ -203,15 +213,6 @@ int restore_pipe_data(int img_type, int pfd, u32 id, struct pipe_data_rst **hash
 	pd->data = NULL;
 out:
 	ret = 0;
-	if (pd->pde->has_size) {
-		pr_info("Restoring size %#x for %#x\n",
-				pd->pde->size, pd->pde->pipe_id);
-		ret = fcntl(pfd, F_SETPIPE_SZ, pd->pde->size);
-		if (ret < 0)
-			pr_perror("Can't restore pipe size");
-		else
-			ret = 0;
-	}
 err:
 	return ret;
 }
@@ -442,6 +443,12 @@ int dump_one_pipe_data(struct pipe_data_dump *pd, int lfd, const struct fd_parms
 		goto err;
 	}
 
+	/* steal_pipe has to be able to fit all data from a target pipe */
+	if (fcntl(steal_pipe[1], F_SETPIPE_SZ, pipe_size) < 0) {
+		pr_perror("Unable to set a pipe size");
+		goto err;
+	}
+
 	bytes = tee(lfd, steal_pipe[1], pipe_size, SPLICE_F_NONBLOCK);
 	if (bytes < 0) {
 		if (errno != EAGAIN) {
-- 
2.13.6



More information about the CRIU mailing list