[CRIU] [PATCH 5/5] page-server: Make sync-read re-use the async reading code

Pavel Emelyanov xemul at virtuozzo.com
Wed Jun 14 13:15:42 MSK 2017


Now we have two separate recv-calling routines, that receive
header and pages from page-server. These two can finally be
unified.

After this the sync-read code looks like -- start async one
and wait for it to finish right at once.

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/page-xfer.c | 51 +++++----------------------------------------------
 1 file changed, 5 insertions(+), 46 deletions(-)

diff --git a/criu/page-xfer.c b/criu/page-xfer.c
index b4979aa..c6565b0 100644
--- a/criu/page-xfer.c
+++ b/criu/page-xfer.c
@@ -1187,56 +1187,15 @@ int request_remote_pages(int pid, unsigned long addr, int nr_pages)
 	return 0;
 }
 
-static int receive_remote_pages_info(int *nr_pages, unsigned long *addr, int *pid)
-{
-	struct page_server_iov pi;
-
-	if (recv(page_server_sk, &pi, sizeof(pi), MSG_WAITALL) != sizeof(pi)) {
-		pr_perror("Failed to receive page metadata");
-		return -1;
-	}
-
-	if (pi.cmd == PS_IOV_ZERO)
-		pr_warn("Unexpected ZERO page received for %d.%lx\n",
-				(int)pi.dst_id, (unsigned long)pi.vaddr);
-
-	*nr_pages = pi.nr_pages;
-	*addr = pi.vaddr;
-	*pid = pi.dst_id;
-
-	return 0;
-}
-
-static int receive_remote_pages(int len, void *buf)
-{
-	if (recv(page_server_sk, buf, len, MSG_WAITALL) != len) {
-		pr_perror("Failed to receive page data");
-		return -1;
-	}
-
-	return 0;
-}
-
 static int page_server_start_sync_read(void *buf, int nr,
 		ps_async_read_complete complete, void *priv)
 {
-	int ret, pid, new_nr;
-	unsigned long vaddr;
-
-	/*
-	 * Note, that for async remote page_read, the actual
-	 * transfer happens in the lazy-pages daemon
-	 */
-	ret = receive_remote_pages_info(&new_nr, &vaddr, &pid);
-	if (ret == 0) {
-		if (new_nr < 0 || new_nr > nr)
-			return -1;
-		ret = receive_remote_pages(nr * PAGE_SIZE, buf);
-	}
-
-	if (ret == 0)
-		ret = complete(pid, vaddr, nr, priv);
+	struct ps_async_read ar;
+	int ret = 1;
 
+	init_ps_async_read(&ar, buf, nr, complete, priv);
+	while (ret == 1)
+		ret = page_server_read(&ar, MSG_WAITALL);
 	return ret;
 }
 
-- 
2.1.4



More information about the CRIU mailing list