aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNir Soffer <nirsof@gmail.com>2025-05-17 23:11:52 +0300
committerEric Blake <eblake@redhat.com>2025-05-29 16:37:15 -0500
commite2e360db7a55afd62e77577a965f6aa224132cef (patch)
tree8de90ca0c4f6f4c5b5e396cf87cecc9384885e6e
parentd2e9b78162e31b1eaf20f3a4f563da82da56908d (diff)
downloadqemu-e2e360db7a55afd62e77577a965f6aa224132cef.zip
qemu-e2e360db7a55afd62e77577a965f6aa224132cef.tar.gz
qemu-e2e360db7a55afd62e77577a965f6aa224132cef.tar.bz2
io: Add helper for setting socket send buffer size
Testing reading and writing from qemu-nbd using a unix domain socket shows that the platform default send buffer size is too low, leading to poor performance and hight cpu usage. Add a helper for setting socket send buffer size to be used in NBD code. It can also be used in other contexts. We don't need a helper for receive buffer size since it is not used with unix domain sockets. This is documented for Linux, and not documented for macOS. Failing to set the socket buffer size is not a fatal error, but the caller may want to warn about the failure. Signed-off-by: Nir Soffer <nirsof@gmail.com> Message-ID: <20250517201154.88456-2-nirsof@gmail.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Eric Blake <eblake@redhat.com>
-rw-r--r--include/io/channel-socket.h13
-rw-r--r--io/channel-socket.c11
2 files changed, 24 insertions, 0 deletions
diff --git a/include/io/channel-socket.h b/include/io/channel-socket.h
index ab15577..a88cf8b 100644
--- a/include/io/channel-socket.h
+++ b/include/io/channel-socket.h
@@ -261,5 +261,18 @@ QIOChannelSocket *
qio_channel_socket_accept(QIOChannelSocket *ioc,
Error **errp);
+/**
+ * qio_channel_socket_set_send_buffer:
+ * @ioc: the socket channel object
+ * @size: buffer size
+ * @errp: pointer to a NULL-initialized error object
+ *
+ * Set the underlying socket send buffer size.
+ *
+ * Retruns: 0 on success, or -1 on error.
+ */
+int qio_channel_socket_set_send_buffer(QIOChannelSocket *ioc,
+ size_t size,
+ Error **errp);
#endif /* QIO_CHANNEL_SOCKET_H */
diff --git a/io/channel-socket.c b/io/channel-socket.c
index 088b49f..3b7ca92 100644
--- a/io/channel-socket.c
+++ b/io/channel-socket.c
@@ -78,6 +78,17 @@ qio_channel_socket_new(void)
return sioc;
}
+int qio_channel_socket_set_send_buffer(QIOChannelSocket *ioc,
+ size_t size,
+ Error **errp)
+{
+ if (setsockopt(ioc->fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size)) < 0) {
+ error_setg_errno(errp, errno, "Unable to set socket send buffer size");
+ return -1;
+ }
+
+ return 0;
+}
static int
qio_channel_socket_set_fd(QIOChannelSocket *sioc,