[CRIU] [PATCH] bfd: bread: read in a loop when running with --remote

Pavel Emelyanov xemul at virtuozzo.com
Mon Jul 3 13:11:38 MSK 2017


On 07/01/2017 06:41 PM, Mike Rapoport wrote:
> From: Omri Kramer <omri.kramer at gmail.com>
> 
> When the --remote option is used, the file descriptor used in bread is a
> socket and read from it may return after only part of the data is received.
> Keep looping until all the data is received when --remote option is on.
> 
> Signed-off-by: Omri Kramer <omri.kramer at gmail.com>
> Signed-off-by: Lior Fisch <fischlior at gmail.com>
> Reviewed-by: Mike Rapoprot <rppt at linux.vnet.ibm.com>
> ---
>  criu/bfd.c | 24 ++++++++++++++++++++++--
>  1 file changed, 22 insertions(+), 2 deletions(-)
> 
> diff --git a/criu/bfd.c b/criu/bfd.c
> index 8269ab1..c03bc88 100644
> --- a/criu/bfd.c
> +++ b/criu/bfd.c
> @@ -298,9 +298,29 @@ int bread(struct bfd *bfd, void *buf, int size)
>  {
>  	struct xbuf *b = &bfd->b;
>  	int more = 1, filled = 0;
> +	int ret;
> +	size_t curr;
>  
> -	if (!bfd_buffered(bfd))
> -		return read(bfd->fd, buf, size);
> +	if (!bfd_buffered(bfd)) {
> +		if(!opts.remote)
> +			return read(bfd->fd, buf, size);
> +
> +		/*
> +		 * With '--remote' bfd->fd is a socket and we may get
> +		 * partial reads here. Keep reading until all the data
> +		 * is received from the socket
> +		 */
> +		while (1) {
> +			ret = read(bfd->fd, buf + curr, size - curr);
> +			if (ret < 0) {
> +				pr_perror("Can't read from buffer\n");
> +				return -1;
> +			}
> +
> +			curr += ret;
> +			if (curr == size || ret == 0)
> +				return curr;

I guess here the closing curly brace should go :)

> +	}
>  
>  	while (more > 0) {
>  		int chunk;
> 



More information about the CRIU mailing list