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

Submitted by Pavel Emelianov on June 14, 2017, 10:15 a.m.

Details

Message ID f9da6dd9-a89a-d676-171d-496e75aaa2a0@virtuozzo.com
State Accepted
Series "Unify sync and async page-server read code"
Commit 06a52ebc56561e66acf7b4d70100a504fce440c0
Headers show

Commit Message

Pavel Emelianov June 14, 2017, 10:15 a.m.
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@virtuozzo.com>
---
 criu/page-xfer.c | 51 +++++----------------------------------------------
 1 file changed, 5 insertions(+), 46 deletions(-)

Patch hide | download patch | download mbox

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;
 }