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>
This commit is contained in:
Hani Benhabiles 2014-05-13 00:35:15 +01:00 committed by Michael Tokarev
parent aef553fdca
commit 36af599417
2 changed files with 5 additions and 3 deletions

View File

@ -27,8 +27,8 @@ static void nbd_accept(void *opaque)
socklen_t addr_len = sizeof(addr); socklen_t addr_len = sizeof(addr);
int fd = accept(server_fd, (struct sockaddr *)&addr, &addr_len); int fd = accept(server_fd, (struct sockaddr *)&addr, &addr_len);
if (fd >= 0) { if (fd >= 0 && !nbd_client_new(NULL, fd, nbd_client_put)) {
nbd_client_new(NULL, fd, nbd_client_put); close(fd);
} }
} }

View File

@ -369,8 +369,10 @@ static void nbd_accept(void *opaque)
return; return;
} }
if (fd >= 0 && nbd_client_new(exp, fd, nbd_client_closed)) { if (nbd_client_new(exp, fd, nbd_client_closed)) {
nb_fds++; nb_fds++;
} else {
close(fd);
} }
} }