From 2cc7e90d5bb88ea5da5a9968d606d15e3389c707 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Wed, 14 Jun 2017 13:15:06 +0300 Subject: [PATCH] page-server: Merge async and sync read API calls Now these two look exactly the same and we can have only one call with additional sync/async (flags) arg. Signed-off-by: Pavel Emelyanov Acked-by: Mike Rapoport Signed-off-by: Andrei Vagin --- criu/include/page-xfer.h | 6 ++---- criu/page-xfer.c | 13 +++++++++++-- criu/pagemap.c | 10 ++++------ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/criu/include/page-xfer.h b/criu/include/page-xfer.h index 41d904152..2b806c797 100644 --- a/criu/include/page-xfer.h +++ b/criu/include/page-xfer.h @@ -57,9 +57,7 @@ extern int check_parent_page_xfer(int fd_type, long id); extern int request_remote_pages(int pid, unsigned long addr, int nr_pages); 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, - ps_async_read_complete complete, void *priv); +extern int page_server_start_read(void *buf, int nr_pages, + ps_async_read_complete complete, void *priv, unsigned flags); #endif /* __CR_PAGE_XFER__H__ */ diff --git a/criu/page-xfer.c b/criu/page-xfer.c index b021e59ee..977d7fc14 100644 --- a/criu/page-xfer.c +++ b/criu/page-xfer.c @@ -1069,7 +1069,7 @@ struct ps_async_read { static LIST_HEAD(async_reads); -int page_server_start_async_read(void *buf, int nr_pages, +static int page_server_start_async_read(void *buf, int nr_pages, ps_async_read_complete complete, void *priv) { struct ps_async_read *ar; @@ -1201,7 +1201,7 @@ static int receive_remote_pages(int len, void *buf) return 0; } -int page_server_start_sync_read(void *buf, int nr, +static int page_server_start_sync_read(void *buf, int nr, ps_async_read_complete complete, void *priv) { int ret, pid, new_nr; @@ -1223,3 +1223,12 @@ int page_server_start_sync_read(void *buf, int nr, return ret; } + +int page_server_start_read(void *buf, int nr, + ps_async_read_complete complete, void *priv, unsigned flags) +{ + if (flags & PR_ASYNC) + return page_server_start_async_read(buf, nr, complete, priv); + else + return page_server_start_sync_read(buf, nr, complete, priv); +} diff --git a/criu/pagemap.c b/criu/pagemap.c index c148df6e3..ef13220e7 100644 --- a/criu/pagemap.c +++ b/criu/pagemap.c @@ -438,12 +438,10 @@ static int maybe_read_page_remote(struct page_read *pr, unsigned long vaddr, /* We always do PR_ASAP mode here (FIXME?) */ ret = request_remote_pages(pr->pid, vaddr, nr); - if (ret < 0) - return ret; - if (flags & PR_ASYNC) - return page_server_start_async_read(buf, nr, read_page_complete, pr); - else - return page_server_start_sync_read(buf, nr, read_page_complete, pr); + if (!ret) + ret = page_server_start_read(buf, nr, + read_page_complete, pr, flags); + return ret; } static int read_pagemap_page(struct page_read *pr, unsigned long vaddr, int nr,