[CRIU] [PATCH 3/5] [v2] parasite: remove restriction to a number of iovec-s

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


From: Andrei Vagin <avagin at virtuozzo.com>

vmsplice can't splice more than UIO_MAXIOV, but we can
call it a few times from a parasite.

v2: s/nr/nr_segs/

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 criu/page-pipe.c    |  8 +-------
 criu/pie/parasite.c | 29 +++++++++++++++++++++++++----
 2 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/criu/page-pipe.c b/criu/page-pipe.c
index 7da8bebc3..4eabb5ed5 100644
--- a/criu/page-pipe.c
+++ b/criu/page-pipe.c
@@ -207,15 +207,9 @@ static inline int try_add_page_to(struct page_pipe *pp, struct page_pipe_buf *pp
 			return 1; /* need to add another buf */
 	}
 
-	if (ppb->nr_segs) {
-		if (iov_grow_page(&ppb->iov[ppb->nr_segs - 1], addr))
+	if (ppb->nr_segs && iov_grow_page(&ppb->iov[ppb->nr_segs - 1], addr))
 			goto out;
 
-		if (ppb->nr_segs == UIO_MAXIOV)
-			/* XXX -- shrink pipe back? */
-			return 1;
-	}
-
 	pr_debug("Add iov to page pipe (%u iovs, %u/%u total)\n",
 			ppb->nr_segs, pp->free_iov, pp->nr_iovs);
 	iov_init(&ppb->iov[ppb->nr_segs++], addr);
diff --git a/criu/pie/parasite.c b/criu/pie/parasite.c
index db2a75f59..12b8cb981 100644
--- a/criu/pie/parasite.c
+++ b/criu/pie/parasite.c
@@ -6,6 +6,7 @@
 #include <sys/mount.h>
 #include <stdarg.h>
 #include <sys/ioctl.h>
+#include <sys/uio.h>
 
 #include "common/config.h"
 #include "int.h"
@@ -66,6 +67,7 @@ static int dump_pages(struct parasite_dump_pages_args *args)
 {
 	int p, ret, tsock;
 	struct iovec *iovs;
+	int off, nr_segs, nr_pages;
 
 	tsock = parasite_get_rpc_sock();
 	p = recv_fd(tsock);
@@ -73,11 +75,30 @@ static int dump_pages(struct parasite_dump_pages_args *args)
 		return -1;
 
 	iovs = pargs_iovs(args);
-	ret = sys_vmsplice(p, &iovs[args->off], args->nr_segs,
-				SPLICE_F_GIFT | SPLICE_F_NONBLOCK);
-	if (ret != PAGE_SIZE * args->nr_pages) {
+	nr_pages = 0;
+	off = 0;
+	nr_segs = args->nr_segs;
+	if (nr_segs > UIO_MAXIOV)
+		nr_segs = UIO_MAXIOV;
+	while (1) {
+		ret = sys_vmsplice(p, &iovs[args->off + off], nr_segs,
+					SPLICE_F_GIFT | SPLICE_F_NONBLOCK);
+		if (ret < 0) {
+			sys_close(p);
+			pr_err("Can't splice pages to pipe (%d/%d/%d)\n",
+						ret, nr_segs, args->off + off);
+			return -1;
+		}
+		nr_pages += ret;
+		off += nr_segs;
+		if (off == args->nr_segs)
+			break;
+		if (off + nr_segs > args->nr_segs)
+			nr_segs = args->nr_segs - off;
+	}
+	if (nr_pages != args->nr_pages * PAGE_SIZE) {
 		sys_close(p);
-		pr_err("Can't splice pages to pipe (%d/%d)\n", ret, args->nr_pages);
+		pr_err("Can't splice all pages to pipe (%d/%d)\n", nr_pages, args->nr_pages);
 		return -1;
 	}
 
-- 
2.13.6



More information about the CRIU mailing list