[Devel,criu] page-xfer: handle a case when splice returns zero

Submitted by Andrei Vagin on July 20, 2017, 2:33 a.m.

Details

Message ID 20170720023313.32404-1-avagin@openvz.org
State New
Series "page-xfer: handle a case when splice returns zero"
Headers show

Commit Message

Andrei Vagin July 20, 2017, 2:33 a.m.
From: Andrei Vagin <avagin@virtuozzo.com>

A return value of 0 means end of input, so we need to
stop reading from this descriptor.

https://jira.sw.ru/browse/PSBM-68732

Cc: Dmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
---
 criu/page-xfer.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Patch hide | download patch | download mbox

diff --git a/criu/page-xfer.c b/criu/page-xfer.c
index 6e64f2d..947487e 100644
--- a/criu/page-xfer.c
+++ b/criu/page-xfer.c
@@ -106,6 +106,11 @@  static int write_pages_to_server(struct page_xfer *xfer,
 			return -1;
 		}
 
+		if (ret == 0) {
+			pr_err("A pipe was closed unexpectedly\n");
+			return -1;
+		}
+
 		pr_debug("\tSpliced: %lu bytes sent\n", (unsigned long)ret);
 		left -= ret;
 	}
@@ -186,6 +191,10 @@  static int write_pages_loc(struct page_xfer *xfer,
 			pr_perror("Unable to spice data");
 			return -1;
 		}
+		if (ret == 0) {
+			pr_err("A pipe was closed unexpectedly");
+			return -1;
+		}
 		curr += ret;
 		if (curr == len)
 			break;
@@ -581,6 +590,10 @@  static int page_server_add(int sk, struct page_server_iov *pi)
 			pr_perror("Can't read from socket");
 			return -1;
 		}
+		if (chunk == 0) {
+			pr_err("The socket was closed unexpectedly\n");
+			return -1;
+		}
 
 		if (lxfer->write_pages(lxfer, cxfer.p[0], chunk))
 			return -1;

Comments

Dmitry Safonov July 20, 2017, 3:48 p.m.
On 07/20/2017 05:33 AM, Andrei Vagin wrote:
> From: Andrei Vagin <avagin@virtuozzo.com>
> 
> A return value of 0 means end of input, so we need to
> stop reading from this descriptor.
> 
> https://jira.sw.ru/browse/PSBM-68732
> 
> Cc: Dmitry Safonov <dsafonov@virtuozzo.com>
> Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>

Applied to vz-criu, released in criu-3.0.0.24-1.vz7

> ---
>   criu/page-xfer.c | 13 +++++++++++++
>   1 file changed, 13 insertions(+)
> 
> diff --git a/criu/page-xfer.c b/criu/page-xfer.c
> index 6e64f2d..947487e 100644
> --- a/criu/page-xfer.c
> +++ b/criu/page-xfer.c
> @@ -106,6 +106,11 @@ static int write_pages_to_server(struct page_xfer *xfer,
>   			return -1;
>   		}
>   
> +		if (ret == 0) {
> +			pr_err("A pipe was closed unexpectedly\n");
> +			return -1;
> +		}
> +
>   		pr_debug("\tSpliced: %lu bytes sent\n", (unsigned long)ret);
>   		left -= ret;
>   	}
> @@ -186,6 +191,10 @@ static int write_pages_loc(struct page_xfer *xfer,
>   			pr_perror("Unable to spice data");
>   			return -1;
>   		}
> +		if (ret == 0) {
> +			pr_err("A pipe was closed unexpectedly");
> +			return -1;
> +		}
>   		curr += ret;
>   		if (curr == len)
>   			break;
> @@ -581,6 +590,10 @@ static int page_server_add(int sk, struct page_server_iov *pi)
>   			pr_perror("Can't read from socket");
>   			return -1;
>   		}
> +		if (chunk == 0) {
> +			pr_err("The socket was closed unexpectedly\n");
> +			return -1;
> +		}
>   
>   		if (lxfer->write_pages(lxfer, cxfer.p[0], chunk))
>   			return -1;
>