0727d3
From cbfaf86331c2b2e01a2083303b7554672bf991b7 Mon Sep 17 00:00:00 2001
0727d3
From: Leonardo Bras <leobras@redhat.com>
0727d3
Date: Mon, 20 Jun 2022 02:39:42 -0300
0727d3
Subject: [PATCH 24/37] QIOChannelSocket: Introduce assert and reduce ifdefs to
0727d3
 improve readability
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: 191: MSG_ZEROCOPY + Multifd @ rhel8.7
0727d3
RH-Commit: [24/26] b50e2e65307149f247155a7f7a032dc99e57718d
0727d3
RH-Bugzilla: 2072049
0727d3
RH-Acked-by: Peter Xu <peterx@redhat.com>
0727d3
RH-Acked-by: Daniel P. Berrangé <berrange@redhat.com>
0727d3
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
0727d3
0727d3
During implementation of MSG_ZEROCOPY feature, a lot of #ifdefs were
0727d3
introduced, particularly at qio_channel_socket_writev().
0727d3
0727d3
Rewrite some of those changes so it's easier to read.
0727d3
0727d3
Also, introduce an assert to help detect incorrect zero-copy usage is when
0727d3
it's disabled on build.
0727d3
0727d3
Signed-off-by: Leonardo Bras <leobras@redhat.com>
0727d3
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
0727d3
Reviewed-by: Juan Quintela <quintela@redhat.com>
0727d3
Reviewed-by: Peter Xu <peterx@redhat.com>
0727d3
Signed-off-by: Juan Quintela <quintela@redhat.com>
0727d3
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
0727d3
  dgilbert: Fixed up thinko'd g_assert_unreachable->g_assert_not_reached
0727d3
(cherry picked from commit 803ca43e4c7fcf32f9f68c118301ccd0c83ece3f)
0727d3
Signed-off-by: Leonardo Bras <leobras@redhat.com>
0727d3
---
0727d3
 io/channel-socket.c | 14 +++++++++-----
0727d3
 1 file changed, 9 insertions(+), 5 deletions(-)
0727d3
0727d3
diff --git a/io/channel-socket.c b/io/channel-socket.c
0727d3
index 38a46ba213..7d37b39de7 100644
0727d3
--- a/io/channel-socket.c
0727d3
+++ b/io/channel-socket.c
0727d3
@@ -579,11 +579,17 @@ static ssize_t qio_channel_socket_writev(QIOChannel *ioc,
0727d3
         memcpy(CMSG_DATA(cmsg), fds, fdsize);
0727d3
     }
0727d3
 
0727d3
-#ifdef QEMU_MSG_ZEROCOPY
0727d3
     if (flags & QIO_CHANNEL_WRITE_FLAG_ZERO_COPY) {
0727d3
+#ifdef QEMU_MSG_ZEROCOPY
0727d3
         sflags = MSG_ZEROCOPY;
0727d3
-    }
0727d3
+#else
0727d3
+        /*
0727d3
+         * We expect QIOChannel class entry point to have
0727d3
+         * blocked this code path already
0727d3
+         */
0727d3
+        g_assert_not_reached();
0727d3
 #endif
0727d3
+    }
0727d3
 
0727d3
  retry:
0727d3
     ret = sendmsg(sioc->fd, &msg, sflags);
0727d3
@@ -593,15 +599,13 @@ static ssize_t qio_channel_socket_writev(QIOChannel *ioc,
0727d3
             return QIO_CHANNEL_ERR_BLOCK;
0727d3
         case EINTR:
0727d3
             goto retry;
0727d3
-#ifdef QEMU_MSG_ZEROCOPY
0727d3
         case ENOBUFS:
0727d3
-            if (sflags & MSG_ZEROCOPY) {
0727d3
+            if (flags & QIO_CHANNEL_WRITE_FLAG_ZERO_COPY) {
0727d3
                 error_setg_errno(errp, errno,
0727d3
                                  "Process can't lock enough memory for using MSG_ZEROCOPY");
0727d3
                 return -1;
0727d3
             }
0727d3
             break;
0727d3
-#endif
0727d3
         }
0727d3
 
0727d3
         error_setg_errno(errp, errno,
0727d3
-- 
0727d3
2.35.3
0727d3