qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/2] nbd: Close socket on negotiation failure.
@ 2014-05-12 23:35 Hani Benhabiles
  2014-05-12 23:35 ` [Qemu-devel] [PATCH 2/2] nbd: Miscellaneous typo fixes Hani Benhabiles
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Hani Benhabiles @ 2014-05-12 23:35 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, pbonzini, kwolf, stefanha

Otherwise, the nbd client may hang waiting for the server response.

Signed-off-by: Hani Benhabiles <hani@linux.com>
---

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);
     }
 }
 
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-05-17  8:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-12 23:35 [Qemu-devel] [PATCH 1/2] nbd: Close socket on negotiation failure Hani Benhabiles
2014-05-12 23:35 ` [Qemu-devel] [PATCH 2/2] nbd: Miscellaneous typo fixes Hani Benhabiles
2014-05-13  9:08   ` Paolo Bonzini
2014-05-14 12:46   ` Stefan Hajnoczi
2014-05-17  8:02   ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2014-05-13  9:07 ` [Qemu-devel] [PATCH 1/2] nbd: Close socket on negotiation failure Paolo Bonzini
2014-05-17  8:02 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).