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

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