[5/6] mem: Split draning pages from xfer-ing them

Submitted by Pavel Emelianov on Sept. 19, 2016, 11:18 a.m.

Details

Message ID 57DFC96C.9020706@virtuozzo.com
State Accepted
Series "Try to sanitize mem dump and pages xfer mess a bit"
Commit 508a408c00ffec96f15cabc5353fd207935f681a
Headers show

Commit Message

Pavel Emelianov Sept. 19, 2016, 11:18 a.m.
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 criu/mem.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/mem.c b/criu/mem.c
index c38f793..09a225d 100644
--- a/criu/mem.c
+++ b/criu/mem.c
@@ -233,9 +233,8 @@  static struct parasite_dump_pages_args *prep_dump_pages_args(struct parasite_ctl
 	return args;
 }
 
-static int dump_pages(struct page_pipe *pp, struct parasite_ctl *ctl,
-		      struct parasite_dump_pages_args *args,
-		      struct page_xfer *xfer, bool lazy)
+static int drain_pages(struct page_pipe *pp, struct parasite_ctl *ctl,
+		      struct parasite_dump_pages_args *args)
 {
 	struct page_pipe_buf *ppb;
 	int ret = 0;
@@ -263,15 +262,20 @@  static int dump_pages(struct page_pipe *pp, struct parasite_ctl *ctl,
 		args->off += args->nr_segs;
 	}
 
+	return 0;
+}
+
+static int xfer_pages(struct page_pipe *pp, struct page_xfer *xfer, bool lazy)
+{
+	int ret;
+
 	/*
 	 * Step 3 -- write pages into image (or delay writing for
 	 *           pre-dump action (see pre_dump_one_task)
 	 */
-	if (xfer) {
-		timing_start(TIME_MEMWRITE);
-		ret = page_xfer_dump_pages(xfer, pp, 0, !lazy);
-		timing_stop(TIME_MEMWRITE);
-	}
+	timing_start(TIME_MEMWRITE);
+	ret = page_xfer_dump_pages(xfer, pp, 0, !lazy);
+	timing_stop(TIME_MEMWRITE);
 
 	return ret;
 }
@@ -363,7 +367,9 @@  again:
 			if (ret == -EAGAIN) {
 				BUG_ON(mdc->delayed_dump);
 
-				ret = dump_pages(pp, ctl, args, &xfer, false);
+				ret = drain_pages(pp, ctl, args);
+				if (!ret)
+					ret = xfer_pages(pp, &xfer, false);
 				if (!ret) {
 					page_pipe_reinit(pp);
 					goto again;
@@ -377,7 +383,9 @@  again:
 	if (mdc->lazy)
 		memcpy(pargs_iovs(args), pp->iovs,
 		       sizeof(struct iovec) * pp->nr_iovs);
-	ret = dump_pages(pp, ctl, args, should_xfer ? &xfer : NULL, mdc->lazy);
+	ret = drain_pages(pp, ctl, args);
+	if (!ret && should_xfer)
+		ret = xfer_pages(pp, &xfer, mdc->lazy);
 	if (ret)
 		goto out_xfer;