Richard W.M. Jones
2019-May-30 18:32 UTC
[Libguestfs] [PATCH nbdkit 1/2] nbd: Fix -Werror=maybe-uninitialized warning.
GCC is concerned that if we never go round the loop then fd will be uninitialized. By asserting that getaddrinfo set result != NULL we can avoid this. nbd.c: In function ‘nbd_open_handle’: nbd.c:974:5: error: ‘fd’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 974 | close (fd); | ^~~~~~~~~~ nbd.c:954:7: note: ‘fd’ was declared here 954 | int fd; | ^~ cc1: all warnings being treated as errors --- plugins/nbd/nbd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/nbd/nbd.c b/plugins/nbd/nbd.c index dba46f1..4d0a67c 100644 --- a/plugins/nbd/nbd.c +++ b/plugins/nbd/nbd.c @@ -960,6 +960,8 @@ nbd_connect_tcp (void) return -1; } + assert (result != NULL); + for (rp = result; rp; rp = rp->ai_next) { fd = socket (rp->ai_family, rp->ai_socktype, rp->ai_protocol); if (fd == -1) -- 2.21.0
Richard W.M. Jones
2019-May-30 18:32 UTC
[Libguestfs] [PATCH nbdkit 2/2] server: Disable Nagle's algorithm.
Unlike the equivalent change on the client side which caused a dramatic performance improvement, there is no noticable difference from this patch in my testing. --- server/sockets.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/server/sockets.c b/server/sockets.c index 2c71970..b25405c 100644 --- a/server/sockets.c +++ b/server/sockets.c @@ -37,13 +37,15 @@ #include <stdbool.h> #include <string.h> #include <unistd.h> +#include <poll.h> +#include <errno.h> +#include <assert.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> +#include <netinet/in.h> +#include <netinet/tcp.h> #include <netdb.h> -#include <poll.h> -#include <errno.h> -#include <assert.h> #ifdef HAVE_LIBSELINUX #include <selinux/selinux.h> @@ -273,6 +275,7 @@ accept_connection (int listen_sock) pthread_t thread; struct thread_data *thread_data; static size_t instance_num = 1; + const int flag = 1; thread_data = malloc (sizeof *thread_data); if (!thread_data) { @@ -293,6 +296,11 @@ accept_connection (int listen_sock) return; } + /* Disable Nagle's algorithm on this socket. However we don't want + * to fail if this doesn't work. + */ + setsockopt (thread_data->sock, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof flag); + /* Start a thread to handle this connection. Note we always do this * even for non-threaded plugins. There are mutexes in plugins.c * which ensure that non-threaded plugins are handled correctly. -- 2.21.0
Eric Blake
2019-May-30 19:13 UTC
Re: [Libguestfs] [PATCH nbdkit 2/2] server: Disable Nagle's algorithm.
On 5/30/19 1:32 PM, Richard W.M. Jones wrote:> Unlike the equivalent change on the client side which caused a > dramatic performance improvement, there is no noticable differencenoticeable ?> from this patch in my testing.Still worth doing, though. ACK series. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Reasonably Related Threads
- [nbdkit PATCH 0/4] thread-safety issues prior to parallel handling
- [PATCH nbdkit] server/locks: Allow lock_request to be called when there is no current conn.
- [nbdkit PATCH 0/8] fd leak safety
- [PATCH nbdkit 2/2] server: Disable Nagle's algorithm.
- [PATCH nbdkit] server: Remove useless thread local sockaddr.