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

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