[CRIU] [PATCH 4/5] page-server: Split the code doing async page-read (v2)

Mike Rapoport rppt at linux.vnet.ibm.com
Thu Jun 15 12:52:40 MSK 2017


On Thu, Jun 15, 2017 at 12:33:17PM +0300, Pavel Emelyanov wrote:
> This is prerequisite for the next patch.
> 
> v2: spellchecks, code reshuffle
> 
> Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>

Acked-by: Mike Rapoport <rppt at linux.vnet.ibm.com>

> ---
>  criu/page-xfer.c | 47 +++++++++++++++++++++++++++++++----------------
>  1 file changed, 31 insertions(+), 16 deletions(-)
> 
> diff --git a/criu/page-xfer.c b/criu/page-xfer.c
> index dd1c6d0..5139033 100644
> --- a/criu/page-xfer.c
> +++ b/criu/page-xfer.c
> @@ -1072,6 +1072,16 @@ struct ps_async_read {
> 
>  static LIST_HEAD(async_reads);
> 
> +static void init_ps_async_read(struct ps_async_read *ar, void *buf,
> +		int nr_pages, ps_async_read_complete complete, void *priv)
> +{
> +	ar->pages = buf;
> +	ar->rb = 0;
> +	ar->goal = sizeof(ar->pi) + nr_pages * PAGE_SIZE;
> +	ar->complete = complete;
> +	ar->priv = priv;
> +}
> +
>  static int page_server_start_async_read(void *buf, int nr_pages,
>  		ps_async_read_complete complete, void *priv)
>  {
> @@ -1081,12 +1091,7 @@ static int page_server_start_async_read(void *buf, int nr_pages,
>  	if (ar == NULL)
>  		return -1;
> 
> -	ar->pages = buf;
> -	ar->rb = 0;
> -	ar->goal = sizeof(ar->pi) + nr_pages * PAGE_SIZE;
> -	ar->complete = complete;
> -	ar->priv = priv;
> -
> +	init_ps_async_read(ar, buf, nr_pages, complete, priv);
>  	list_add_tail(&ar->l, &async_reads);
>  	return 0;
>  }
> @@ -1100,15 +1105,11 @@ static int page_server_start_async_read(void *buf, int nr_pages,
>   * for sure the next time socket event will occur we'll get page data
>   * related to info we've just received
>   */
> -static int page_server_async_read(struct epoll_rfd *f)
> +static int page_server_read(struct ps_async_read *ar, int flags)
>  {
> -	struct ps_async_read *ar;
>  	int ret, need;
>  	void *buf;
> 
> -	BUG_ON(list_empty(&async_reads));
> -	ar = list_first_entry(&async_reads, struct ps_async_read, l);
> -
>  	if (ar->rb < sizeof(ar->pi)) {
>  		/* Header */
>  		buf = ((void *)&ar->pi) + ar->rb;
> @@ -1119,7 +1120,7 @@ static int page_server_async_read(struct epoll_rfd *f)
>  		need = ar->goal - ar->rb;
>  	}
> 
> -	ret = recv(page_server_sk, buf, need, MSG_DONTWAIT);
> +	ret = recv(page_server_sk, buf, need, flags);
>  	if (ret < 0) {
>  		pr_perror("Error reading async data from page server");
>  		return -1;
> @@ -1127,17 +1128,31 @@ static int page_server_async_read(struct epoll_rfd *f)
> 
>  	ar->rb += ret;
>  	if (ar->rb < ar->goal)
> -		return 0;
> +		return 1;
> 
>  	/*
>  	 * IO complete -- notify the caller and drop the request
>  	 */
>  	BUG_ON(ar->rb > ar->goal);
> -	ret = ar->complete((int)ar->pi.dst_id, (unsigned long)ar->pi.vaddr,
> +	return ar->complete((int)ar->pi.dst_id, (unsigned long)ar->pi.vaddr,
>  				(int)ar->pi.nr_pages, ar->priv);
> +}
> 
> -	list_del(&ar->l);
> -	xfree(ar);
> +static int page_server_async_read(struct epoll_rfd *f)
> +{
> +	struct ps_async_read *ar;
> +	int ret;
> +
> +	BUG_ON(list_empty(&async_reads));
> +	ar = list_first_entry(&async_reads, struct ps_async_read, l);
> +	ret = page_server_read(ar, MSG_DONTWAIT);
> +
> +	if (ret > 0)
> +		return 0;
> +	if (!ret) {
> +		list_del(&ar->l);
> +		xfree(ar);
> +	}
> 
>  	return ret;
>  }
> -- 
> 2.1.4
> 



More information about the CRIU mailing list