summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHani Benhabiles <kroosec@gmail.com>2014-05-13 00:35:15 +0100
committerMichael Roth <mdroth@linux.vnet.ibm.com>2014-07-15 19:28:01 -0500
commit25351f6a9ad55990d5140a928fd6ea29e48943af (patch)
treef39c2e85c73e55cef2bfb176412694c1ca02a0a9
parentcf392d2c7c0f10adc5d9d4f740e034b646605fff (diff)
downloadqemu-25351f6a9ad55990d5140a928fd6ea29e48943af.tar.gz
nbd: Close socket on negotiation failure.
Otherwise, the nbd client may hang waiting for the server response. Signed-off-by: Hani Benhabiles <hani@linux.com> Acked-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru> (cherry picked from commit 36af599417dde11747a27dc8550ff2281657a8ff) Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
-rw-r--r--blockdev-nbd.c4
-rw-r--r--qemu-nbd.c4
2 files changed, 5 insertions, 3 deletions
diff --git a/blockdev-nbd.c b/blockdev-nbd.c
index a700d52d71..18dc528761 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 c26c98ef1d..7a2cff92c2 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -299,8 +299,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);
}
}