From c8717da44cad4942f2f1e17e7d32010bbd111ee9 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Wed, 14 Jun 2017 13:15:42 +0300 Subject: [PATCH] page-server: Make sync-read re-use the async reading code 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 Signed-off-by: Andrei Vagin --- 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 c9f55c9e4..e653623bd 100644 --- a/criu/page-xfer.c +++ b/criu/page-xfer.c @@ -1186,56 +1186,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; }