From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48387) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wk8gx-0000hp-Ko for qemu-devel@nongnu.org; Tue, 13 May 2014 05:08:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wk8gr-0007Ml-9Y for qemu-devel@nongnu.org; Tue, 13 May 2014 05:08:07 -0400 Sender: Paolo Bonzini Message-ID: <5371E0EC.5000406@redhat.com> Date: Tue, 13 May 2014 11:07:56 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1399937716-6086-1-git-send-email-kroosec@gmail.com> In-Reply-To: <1399937716-6086-1-git-send-email-kroosec@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/2] nbd: Close socket on negotiation failure. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Hani Benhabiles , qemu-devel@nongnu.org Cc: qemu-trivial@nongnu.org, kwolf@redhat.com, stefanha@redhat.com Il 13/05/2014 01:35, Hani Benhabiles ha scritto: > Otherwise, the nbd client may hang waiting for the server response. > > Signed-off-by: Hani Benhabiles > --- > > Quick method to trigger such behaviour: > > (qemu) nbd_server_start localhost:10809 > (qemu) nbd_server_add sd0 > $ nbd-client localhost 10809 -name AAAA /dev/nbd0 > Negotiation: .. > > (Client will hang indefinitely.) > > blockdev-nbd.c | 4 ++-- > qemu-nbd.c | 4 +++- > 2 files changed, 5 insertions(+), 3 deletions(-) > > diff --git a/blockdev-nbd.c b/blockdev-nbd.c > index 922cf56..b60b66d 100644 > --- a/blockdev-nbd.c > +++ b/blockdev-nbd.c > @@ -27,8 +27,8 @@ static void nbd_accept(void *opaque) > socklen_t addr_len = sizeof(addr); > > int fd = accept(server_fd, (struct sockaddr *)&addr, &addr_len); > - if (fd >= 0) { > - nbd_client_new(NULL, fd, nbd_client_put); > + if (fd >= 0 && !nbd_client_new(NULL, fd, nbd_client_put)) { > + close(fd); > } > } > > diff --git a/qemu-nbd.c b/qemu-nbd.c > index eed79fa..f70e4b0 100644 > --- a/qemu-nbd.c > +++ b/qemu-nbd.c > @@ -369,8 +369,10 @@ static void nbd_accept(void *opaque) > return; > } > > - if (fd >= 0 && nbd_client_new(exp, fd, nbd_client_closed)) { > + if (nbd_client_new(exp, fd, nbd_client_closed)) { > nb_fds++; > + } else { > + close(fd); > } > } > > Acked-by: Paolo Bonzini Michael, can you queue this yourself? Paolo