Blame SOURCES/kvm-QIOChannelSocket-Introduce-assert-and-reduce-ifdefs-.patch

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