page-xfer: Handle partial splicing

Submitted by Cyrill Gorcunov on Aug. 10, 2018, 3 p.m.

Details

Message ID 20180810150051.21418-1-gorcunov@gmail.com
State New
Series "page-xfer: Handle partial splicing"
Headers show

Commit Message

Cyrill Gorcunov Aug. 10, 2018, 3 p.m.
In case if pipe buffers are full the splicing
may wakeup reader first with incomplete data
transfer. Thus splice data in cycle.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
---
 criu/page-xfer.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/page-xfer.c b/criu/page-xfer.c
index e653de5b3..81a7dfd4a 100644
--- a/criu/page-xfer.c
+++ b/criu/page-xfer.c
@@ -147,11 +147,19 @@  static inline int send_psi(int sk, struct page_server_iov *pi)
 static int write_pages_to_server(struct page_xfer *xfer,
 		int p, unsigned long len)
 {
+	ssize_t ret, left = len;
+
 	pr_debug("Splicing %lu bytes / %lu pages into socket\n", len, len / PAGE_SIZE);
 
-	if (splice(p, NULL, xfer->sk, NULL, len, SPLICE_F_MOVE) != len) {
-		pr_perror("Can't write pages to socket");
-		return -1;
+	while (left > 0) {
+		ret = splice(p, NULL, xfer->sk, NULL, left, SPLICE_F_MOVE);
+		if (ret < 0) {
+			pr_perror("Can't write pages to socket");
+			return -1;
+		}
+
+		pr_debug("\tSpliced: %lu bytes sent\n", (unsigned long)ret);
+		left -= ret;
 	}
 
 	return 0;

Comments

Mike Rapoport Aug. 13, 2018, 2:13 p.m.
On Fri, Aug 10, 2018 at 06:00:51PM +0300, Cyrill Gorcunov wrote:
> In case if pipe buffers are full the splicing
> may wakeup reader first with incomplete data
> transfer. Thus splice data in cycle.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>

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

> ---
>  criu/page-xfer.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/criu/page-xfer.c b/criu/page-xfer.c
> index e653de5b3..81a7dfd4a 100644
> --- a/criu/page-xfer.c
> +++ b/criu/page-xfer.c
> @@ -147,11 +147,19 @@ static inline int send_psi(int sk, struct page_server_iov *pi)
>  static int write_pages_to_server(struct page_xfer *xfer,
>  		int p, unsigned long len)
>  {
> +	ssize_t ret, left = len;
> +
>  	pr_debug("Splicing %lu bytes / %lu pages into socket\n", len, len / PAGE_SIZE);
> 
> -	if (splice(p, NULL, xfer->sk, NULL, len, SPLICE_F_MOVE) != len) {
> -		pr_perror("Can't write pages to socket");
> -		return -1;
> +	while (left > 0) {
> +		ret = splice(p, NULL, xfer->sk, NULL, left, SPLICE_F_MOVE);
> +		if (ret < 0) {
> +			pr_perror("Can't write pages to socket");
> +			return -1;
> +		}
> +
> +		pr_debug("\tSpliced: %lu bytes sent\n", (unsigned long)ret);
> +		left -= ret;
>  	}
> 
>  	return 0;
> -- 
> 2.14.4
> 
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
>