[3/6] pageserver: Merge page_server_add with page_server_hole

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

Details

Message ID 57DFC948.8050907@virtuozzo.com
State Accepted
Series "Try to sanitize mem dump and pages xfer mess a bit"
Commit 58ccde2690d2ef2bd735677d46d98c2351528990
Headers show

Commit Message

Pavel Emelianov Sept. 19, 2016, 11:17 a.m.
Do the same here, the flags is now enough to tell hole
from pagemap.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 criu/page-xfer.c | 32 ++++++++------------------------
 1 file changed, 8 insertions(+), 24 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/page-xfer.c b/criu/page-xfer.c
index 3e61d65..548903a 100644
--- a/criu/page-xfer.c
+++ b/criu/page-xfer.c
@@ -582,12 +582,11 @@  static int prep_loc_xfer(struct page_server_iov *pi)
 		return 0;
 }
 
-static int page_server_add(int sk, struct page_server_iov *pi)
+static int page_server_add(int sk, struct page_server_iov *pi, u32 flags)
 {
 	size_t len;
 	struct page_xfer *lxfer = &cxfer.loc_xfer;
 	struct iovec iov;
-	u32 flags;
 
 	pr_debug("Adding %"PRIx64"/%u\n", pi->vaddr, pi->nr_pages);
 
@@ -595,10 +594,12 @@  static int page_server_add(int sk, struct page_server_iov *pi)
 		return -1;
 
 	psi2iovec(pi, &iov);
-	flags = decode_ps_flags(pi->cmd);
 	if (lxfer->write_pagemap(lxfer, &iov, flags))
 		return -1;
 
+	if (!(flags & PE_PRESENT))
+		return 0;
+
 	len = iov.iov_len;
 	while (len > 0) {
 		ssize_t chunk;
@@ -622,23 +623,6 @@  static int page_server_add(int sk, struct page_server_iov *pi)
 	return 0;
 }
 
-static int page_server_hole(int sk, struct page_server_iov *pi, u32 flags)
-{
-	struct page_xfer *lxfer = &cxfer.loc_xfer;
-	struct iovec iov;
-
-	pr_debug("Adding %"PRIx64"/%u hole\n", pi->vaddr, pi->nr_pages);
-
-	if (prep_loc_xfer(pi))
-		return -1;
-
-	psi2iovec(pi, &iov);
-	if (lxfer->write_pagemap(lxfer, &iov, flags))
-		return -1;
-
-	return 0;
-}
-
 static int page_server_get_pages(int sk, struct page_server_iov *pi)
 {
 	struct pstree_item *item;
@@ -734,16 +718,16 @@  static int page_server_serve(int sk)
 			ret = page_server_check_parent(sk, &pi);
 			break;
 		case PS_IOV_ADD:
-			ret = page_server_add(sk, &pi);
+			ret = page_server_add(sk, &pi, PE_PRESENT | decode_ps_flags(pi.cmd));
 			break;
 		case PS_IOV_HOLE:
-			ret = page_server_hole(sk, &pi, PE_PARENT);
+			ret = page_server_add(sk, &pi, PE_PARENT);
 			break;
 		case PS_IOV_ZERO:
-			ret = page_server_hole(sk, &pi, PE_ZERO);
+			ret = page_server_add(sk, &pi, PE_ZERO);
 			break;
 		case PS_IOV_LAZY:
-			ret = page_server_hole(sk, &pi, PE_LAZY);
+			ret = page_server_add(sk, &pi, PE_LAZY);
 			break;
 		case PS_IOV_FLUSH:
 		case PS_IOV_FLUSH_N_CLOSE: