On 2/5/21 1:55 PM, Nir Soffer wrote: > On Fri, Feb 5, 2021 at 8:57 PM Eric Blake <ebl...@redhat.com> wrote: >> >> Our default of a backlog of 1 connection is rather puny, particularly >> for scenarios where we expect multiple listeners to connect (such as >> qemu-nbd -e X). This is especially important for Unix sockets, as a >> definite benefit to clients: at least on Linux, a client trying to >> connect to a Unix socket with a backlog gets an EAGAIN failure with no >> way to poll() for when the backlog is no longer present short of >> sleeping an arbitrary amount of time before retrying. >> >> See https://bugzilla.redhat.com/1925045 for a demonstration of where >> our low backlog prevents libnbd from connecting as many parallel >> clients as it wants. >> >> Reported-by: Richard W.M. Jones <rjo...@redhat.com> >> Signed-off-by: Eric Blake <ebl...@redhat.com> >> --- >> >> v2: target the correct API used by qemu-nbd, rather than an unrelated >> legacy wrapper [Dan] >> >> qemu-nbd.c | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/qemu-nbd.c b/qemu-nbd.c >> index 608c63e82a25..cd20ee73be19 100644 >> --- a/qemu-nbd.c >> +++ b/qemu-nbd.c >> @@ -965,7 +965,8 @@ int main(int argc, char **argv) >> server = qio_net_listener_new(); >> if (socket_activation == 0) { >> saddr = nbd_build_socket_address(sockpath, bindto, port); >> - if (qio_net_listener_open_sync(server, saddr, 1, &local_err) < 0) { >> + if (qio_net_listener_open_sync(server, saddr, SOMAXCONN, > > Shouldn't we use value based on --shared=N?
That's a possibility. I don't know how many resources we tie up if we allow more clients to try to connect() than what we will ultimately accept when --shared is small. But there's also the issue that for qemu-nbd, we default to 1 client unless you pass -e/--shared on the command line, whereas starting an NBD server in qemu via QMP (including via qemu-storage-daemon) defaults max-connections to 0 meaning unlimited. > > Using maximum value makes sense for generic server expecting to handle many > connections from different clients. qemu-nbd is typically used by one > client, and we > need to make it possible to connect a known number of connections quickly. At any rate, when max-connections is specified to something smaller than SOMAXCONN, listen()ing to a smaller number of connections seems reasonable, so I'll play with that for v3. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org