From b801cd68d96944c2610136fc8c718a1ad934d49f Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Wed, 14 Jun 2017 13:14:28 +0300 Subject: [PATCH] page-server: Introduce page_server_start_sync_read There's no need in two API calls to read xfer header and pages themselves, so merge them into one single call. Signed-off-by: Pavel Emelyanov Signed-off-by: Andrei Vagin --- criu/include/page-xfer.h | 3 +-- criu/page-xfer.c | 22 ++++++++++++++++++++-- criu/pagemap.c | 14 ++------------ 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/criu/include/page-xfer.h b/criu/include/page-xfer.h index 1f59bdb03..3d65ebd0b 100644 --- a/criu/include/page-xfer.h +++ b/criu/include/page-xfer.h @@ -55,11 +55,10 @@ extern int check_parent_page_xfer(int fd_type, long id); /* async request/receive of remote pages */ extern int request_remote_pages(int pid, unsigned long addr, int nr_pages); -extern int receive_remote_pages_info(int *nr_pages, unsigned long *addr, int *pid); -extern int receive_remote_pages(int len, void *buf); typedef int (*ps_async_read_complete)(int pid, unsigned long vaddr, int nr_pages, void *); extern int page_server_start_async_read(void *buf, int nr_pages, ps_async_read_complete complete, void *priv); +extern int page_server_start_sync_read(void *buf, int nr_pages, unsigned long *vaddr); #endif /* __CR_PAGE_XFER__H__ */ diff --git a/criu/page-xfer.c b/criu/page-xfer.c index 603f77b53..77e2e00f8 100644 --- a/criu/page-xfer.c +++ b/criu/page-xfer.c @@ -1171,7 +1171,7 @@ int request_remote_pages(int pid, unsigned long addr, int nr_pages) return 0; } -int receive_remote_pages_info(int *nr_pages, unsigned long *addr, int *pid) +static int receive_remote_pages_info(int *nr_pages, unsigned long *addr, int *pid) { struct page_server_iov pi; @@ -1191,7 +1191,7 @@ int receive_remote_pages_info(int *nr_pages, unsigned long *addr, int *pid) return 0; } -int receive_remote_pages(int len, void *buf) +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"); @@ -1200,3 +1200,21 @@ int receive_remote_pages(int len, void *buf) return 0; } + +int page_server_start_sync_read(void *buf, int nr, unsigned long *vaddr) +{ + int ret, pid, new_nr; + + /* + * 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); + } + + return ret; +} diff --git a/criu/pagemap.c b/criu/pagemap.c index f4035042d..c590d9e1e 100644 --- a/criu/pagemap.c +++ b/criu/pagemap.c @@ -434,7 +434,7 @@ static int read_page_complete(int pid, unsigned long vaddr, int nr_pages, void * static int maybe_read_page_remote(struct page_read *pr, unsigned long vaddr, int nr, void *buf, unsigned flags) { - int ret, pid, new_nr; + int ret; /* We always do PR_ASAP mode here (FIXME?) */ ret = request_remote_pages(pr->pid, vaddr, nr); @@ -443,17 +443,7 @@ static int maybe_read_page_remote(struct page_read *pr, unsigned long vaddr, if (flags & PR_ASYNC) return page_server_start_async_read(buf, nr, read_page_complete, pr); - /* - * 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); - } - + ret = page_server_start_sync_read(buf, nr, &vaddr); if (ret == 0 && pr->io_complete) ret = pr->io_complete(pr, vaddr, nr);