nbd: Close socket on negotiation failure.
PATCH 1/2 nbd: Close socket on negotiation failure.
Otherwise, the nbd client may hang waiting for the server response.
---
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(-)
blockdev-nbd.c +2 -2
@@ -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); } }
qemu-nbd.c +3 -1
@@ -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); } }
Signature · 1 line
1.8.3.2
PATCH 2/2 nbd: Miscellaneous typo fixes.
--- nbd.c | 2 +- qemu-nbd.c | 2 +- qemu-nbd.texi | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
nbd.c +1 -1
@@ -306,7 +306,7 @@ static int nbd_send_negotiate(NBDClient *client) [ 8 .. 15] magic (NBD_CLIENT_MAGIC) [16 .. 23] size [24 .. 25] server flags (0) - [24 .. 27] export flags + [26 .. 27] export flags [28 .. 151] reserved (0) Negotiation header with options, part 1:
qemu-nbd.c +1 -1
@@ -294,7 +294,7 @@ static void *nbd_client_thread(void *arg) fd =open (device,O_RDWR );if (fd <0 ) {/* Linux-only, we can use %m in printf. */ -fprintf (stderr,"Failed to open %s: %m" , device); +fprintf (stderr,"Failed to open %s: %m\n" , device); goto out_socket; }
qemu-nbd.texi +1 -1
@@ -15,7 +15,7 @@ Export QEMU disk image using NBD protocol. @item @var{filename} is a disk image filename @item -p, --port=@var{port} - port to listen on (default @samp{1024}) + port to listen on (default @samp{10809}) @item -o, --offset=@var{offset} offset into the image @item -b, --bind=@var{iface}
Signature · 1 line
1.8.3.2
Il 13/05/2014 01:35, Hani Benhabiles ha scritto:
Quoted 40 lines
Otherwise, the nbd client may hang waiting for the server response.
Signed-off-by Hani Benhabiles <[email protected]>---
Quick method to trigger such behaviour:
(qemu)
nbd_server_startlocalhost:10809
(qemu)nbd_server_addsd0$ 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(-)blockdev-nbd.c +2
-2@@ -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); } }qemu-nbd.c +0
-0@@ -369,8 +369,10 @@ static void nbd_accept(void *opaque)return ;
qemu-nbd.c static void nbd_accept(void *opaque) · line 378
Quoted 10 lines
qemu-nbd.c +3
-1} -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); } }
Michael, can you queue this yourself?
Paolo
Re: [Qemu-devel] [PATCH 2/2] nbd: Miscellaneous typo fixes.
In reply to Hani BenhabilesIl 13/05/2014 01:35, Hani Benhabiles ha scritto:
Quoted 39 lines
Signed-off-by Hani Benhabiles <[email protected]>--- nbd.c | 2 +- qemu-nbd.c | 2 +- qemu-nbd.texi | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)nbd.c +1
-1@@ -306,7 +306,7 @@ static int nbd_send_negotiate(NBDClient *client) [ 8 .. 15] magic (NBD_CLIENT_MAGIC) [16 .. 23] size [24 .. 25] server flags (0) - [24 .. 27] export flags + [26 .. 27] export flags [28 .. 151] reserved (0) Negotiation header with options, part 1:qemu-nbd.c +1
-1@@ -294,7 +294,7 @@ static void *nbd_client_thread(void *arg) fd =open (device,O_RDWR );if (fd <0 ) {/* Linux-only, we can use %m in printf. */ -fprintf (stderr,"Failed to open %s: %m" , device); +fprintf (stderr,"Failed to open %s: %m\n" , device); goto out_socket; }qemu-nbd.texi +0
-0
qemu-nbd.texi Export QEMU disk image using NBD protocol. · line 21
Quoted 8 lines
qemu-nbd.texi +1
-1@@ -15,7 +15,7 @@ Export QEMU disk image using NBD protocol. @item @var{filename} is a disk image filename @item -p, --port=@var{port} - port to listen on (default @samp{1024}) + port to listen on (default @samp{10809}) @item -o, --offset=@var{offset} offset into the image @item -b, --bind=@var{iface}
Re: [Qemu-devel] [PATCH 2/2] nbd: Miscellaneous typo fixes.
In reply to Hani BenhabilesQuoted 6 lines · Hani Benhabiles
Signed-off-by Hani Benhabiles <[email protected]>--- nbd.c | 2 +- qemu-nbd.c | 2 +- qemu-nbd.texi | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
Michael Tokarev
AppliedQuoted 1 line · Hani Benhabiles
Otherwise, the nbd client may hang waiting for the server response.
Applied to -trivial, thanks!
/mjt
Michael Tokarev
AppliedRe: [Qemu-devel] [Qemu-trivial] [PATCH 2/2] nbd: Miscellaneous typo fixes.
In reply to Hani BenhabilesApplied to -trivial, thanks!
/mjt