diff options
author | Fam Zheng <famz@redhat.com> | 2016-01-14 16:41:01 +0800 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2016-01-15 18:58:01 +0100 |
commit | ee7d7aabdaea4484e069cb99c9fc54e8cb24b56f (patch) | |
tree | da85bcfd0c1092c266629d6afd9d75d59c98eea0 /nbd.c | |
parent | e1dc68155cafabfd6a065391f7826d5d0992b46e (diff) |
nbd: Always call "close_fn" in nbd_client_new
Rename the parameter "close" to "close_fn" to disambiguous with
close(2).
This unifies error handling paths of NBDClient allocation:
nbd_client_new will shutdown the socket and call the "close_fn" callback
if negotiation failed, so the caller don't need a different path than
the normal close.
The returned pointer is never used, make it void in preparation for the
next patch.
Signed-off-by: Fam Zheng <famz@redhat.com>
Message-Id: <1452760863-25350-2-git-send-email-famz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'nbd.c')
-rw-r--r-- | nbd.c | 11 |
1 files changed, 5 insertions, 6 deletions
@@ -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; } |