0727d3
From 905cc8032fc63619efb3f0a8c9754b7190bcc43a Mon Sep 17 00:00:00 2001
0727d3
From: Leonardo Bras <leobras@redhat.com>
0727d3
Date: Mon, 11 Jul 2022 18:11:11 -0300
0727d3
Subject: [PATCH 3/9] QIOChannelSocket: Fix zero-copy flush returning code 1
0727d3
 when nothing sent
0727d3
MIME-Version: 1.0
0727d3
Content-Type: text/plain; charset=UTF-8
0727d3
Content-Transfer-Encoding: 8bit
0727d3
0727d3
RH-Author: Leonardo Brás <leobras@redhat.com>
0727d3
RH-MergeRequest: 201: Zero-copy-send fixes + improvements
0727d3
RH-Commit: [3/8] 1ad707702fa26cd4d0fa1870c21f5f26ae93ff97
0727d3
RH-Bugzilla: 2110203
0727d3
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
0727d3
RH-Acked-by: Peter Xu <peterx@redhat.com>
0727d3
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
0727d3
0727d3
If flush is called when no buffer was sent with MSG_ZEROCOPY, it currently
0727d3
returns 1. This return code should be used only when Linux fails to use
0727d3
MSG_ZEROCOPY on a lot of sendmsg().
0727d3
0727d3
Fix this by returning early from flush if no sendmsg(...,MSG_ZEROCOPY)
0727d3
was attempted.
0727d3
0727d3
Fixes: 2bc58ffc2926 ("QIOChannelSocket: Implement io_writev zero copy flag & io_flush for CONFIG_LINUX")
0727d3
Signed-off-by: Leonardo Bras <leobras@redhat.com>
0727d3
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
0727d3
Acked-by: Daniel P. Berrangé <berrange@redhat.com>
0727d3
Reviewed-by: Juan Quintela <quintela@redhat.com>
0727d3
Reviewed-by: Peter Xu <peterx@redhat.com>
0727d3
Message-Id: <20220711211112.18951-2-leobras@redhat.com>
0727d3
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
0727d3
(cherry picked from commit 927f93e099c4f9184e60a1bc61624ac2d04d0223)
0727d3
Signed-off-by: Leonardo Bras <leobras@redhat.com>
0727d3
---
0727d3
 io/channel-socket.c | 8 +++++++-
0727d3
 1 file changed, 7 insertions(+), 1 deletion(-)
0727d3
0727d3
diff --git a/io/channel-socket.c b/io/channel-socket.c
0727d3
index df858da924..cf0d67c51b 100644
0727d3
--- a/io/channel-socket.c
0727d3
+++ b/io/channel-socket.c
0727d3
@@ -717,12 +717,18 @@ static int qio_channel_socket_flush(QIOChannel *ioc,
0727d3
     struct cmsghdr *cm;
0727d3
     char control[CMSG_SPACE(sizeof(*serr))];
0727d3
     int received;
0727d3
-    int ret = 1;
0727d3
+    int ret;
0727d3
+
0727d3
+    if (sioc->zero_copy_queued == sioc->zero_copy_sent) {
0727d3
+        return 0;
0727d3
+    }
0727d3
 
0727d3
     msg.msg_control = control;
0727d3
     msg.msg_controllen = sizeof(control);
0727d3
     memset(control, 0, sizeof(control));
0727d3
 
0727d3
+    ret = 1;
0727d3
+
0727d3
     while (sioc->zero_copy_sent < sioc->zero_copy_queued) {
0727d3
         received = recvmsg(sioc->fd, &msg, MSG_ERRQUEUE);
0727d3
         if (received < 0) {
0727d3
-- 
0727d3
2.31.1
0727d3