diff options
-rw-r--r-- | blockdev-nbd.c | 5 | ||||
-rw-r--r-- | include/block/nbd.h | 3 | ||||
-rw-r--r-- | nbd.c | 11 | ||||
-rw-r--r-- | qemu-nbd.c | 10 |
4 files changed, 11 insertions, 18 deletions
diff --git a/blockdev-nbd.c b/blockdev-nbd.c index bcdd18b3f6..4a758ac314 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -27,9 +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)) { - shutdown(fd, 2); - close(fd); + if (fd >= 0) { + nbd_client_new(NULL, fd, nbd_client_put); } } diff --git a/include/block/nbd.h b/include/block/nbd.h index 65f409d804..7eccb41da8 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -98,8 +98,7 @@ NBDExport *nbd_export_find(const char *name); void nbd_export_set_name(NBDExport *exp, const char *name); void nbd_export_close_all(void); -NBDClient *nbd_client_new(NBDExport *exp, int csock, - void (*close)(NBDClient *)); +void nbd_client_new(NBDExport *exp, int csock, void (*close_fn)(NBDClient *)); void nbd_client_get(NBDClient *client); void nbd_client_put(NBDClient *client); @@ -1475,8 +1475,7 @@ static void nbd_update_can_read(NBDClient *client) } } -NBDClient *nbd_client_new(NBDExport *exp, int csock, - void (*close)(NBDClient *)) +void nbd_client_new(NBDExport *exp, int csock, void (*close_fn)(NBDClient *)) { NBDClient *client; client = g_malloc0(sizeof(NBDClient)); @@ -1485,10 +1484,11 @@ NBDClient *nbd_client_new(NBDExport *exp, int csock, client->sock = csock; client->can_read = true; if (nbd_send_negotiate(client)) { - g_free(client); - return NULL; + shutdown(client->sock, 2); + close_fn(client); + return; } - client->close = close; + client->close = close_fn; qemu_co_mutex_init(&client->send_lock); nbd_set_handlers(client); @@ -1496,5 +1496,4 @@ NBDClient *nbd_client_new(NBDExport *exp, int csock, QTAILQ_INSERT_TAIL(&exp->clients, client, next); nbd_export_get(exp); } - return client; } diff --git a/qemu-nbd.c b/qemu-nbd.c index a4cf847976..ede4a54d4e 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -333,13 +333,9 @@ static void nbd_accept(void *opaque) return; } - if (nbd_client_new(exp, fd, nbd_client_closed)) { - nb_fds++; - nbd_update_server_fd_handler(server_fd); - } else { - shutdown(fd, 2); - close(fd); - } + nb_fds++; + nbd_update_server_fd_handler(server_fd); + nbd_client_new(exp, fd, nbd_client_closed); } static void nbd_update_server_fd_handler(int fd) |