nbd: Shutdown socket before closing.
This forces finishing data sending to client before closing the socket like in
exports listing or replying with NBD_REP_ERR_UNSUP cases.
Signed-off-by: Hani Benhabiles <kroosec@gmail.com>
Cc: qemu-stable@nongnu.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
diff --git a/blockdev-nbd.c b/blockdev-nbd.c
index 18dc528..b3a2474 100644
--- a/blockdev-nbd.c
+++ b/blockdev-nbd.c
@@ -28,6 +28,7 @@
int fd = accept(server_fd, (struct sockaddr *)&addr, &addr_len);
if (fd >= 0 && !nbd_client_new(NULL, fd, nbd_client_put)) {
+ shutdown(fd, 2);
close(fd);
}
}
diff --git a/qemu-nbd.c b/qemu-nbd.c
index ba60436..626e584 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -372,6 +372,7 @@
if (nbd_client_new(exp, fd, nbd_client_closed)) {
nb_fds++;
} else {
+ shutdown(fd, 2);
close(fd);
}
}