|
|
9ae3a8 |
From 2efca7904a7a71d44bdf715208899e3bb29711df Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
Date: Thu, 10 Mar 2016 04:00:51 +0100
|
|
|
9ae3a8 |
Subject: [PATCH 2/5] nbd: Always call "close_fn" in nbd_client_new
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1457582453-13835-2-git-send-email-famz@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 69757
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.3 qemu-kvm PATCH v2 1/3] nbd: Always call "close_fn" in nbd_client_new
|
|
|
9ae3a8 |
Bugzilla: 1285453
|
|
|
9ae3a8 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Rename the parameter "close" to "close_fn" to disambiguous with
|
|
|
9ae3a8 |
close(2).
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
This unifies error handling paths of NBDClient allocation:
|
|
|
9ae3a8 |
nbd_client_new will shutdown the socket and call the "close_fn" callback
|
|
|
9ae3a8 |
if negotiation failed, so the caller don't need a different path than
|
|
|
9ae3a8 |
the normal close.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
The returned pointer is never used, make it void in preparation for the
|
|
|
9ae3a8 |
next patch.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
Message-Id: <1452760863-25350-2-git-send-email-famz@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit ee7d7aabdaea4484e069cb99c9fc54e8cb24b56f)
|
|
|
9ae3a8 |
Signed-off-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Conflicts:
|
|
|
9ae3a8 |
include/block/nbd.h
|
|
|
9ae3a8 |
nbd.c
|
|
|
9ae3a8 |
qemu-nbd.c
|
|
|
9ae3a8 |
* nbd_update_server_fd_handler not in downstream;
|
|
|
9ae3a8 |
* Context around the changed line is different.
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
include/block/nbd.h | 3 +--
|
|
|
9ae3a8 |
nbd.c | 11 +++++------
|
|
|
9ae3a8 |
qemu-nbd.c | 4 ++--
|
|
|
9ae3a8 |
3 files changed, 8 insertions(+), 10 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/include/block/nbd.h b/include/block/nbd.h
|
|
|
9ae3a8 |
index c90f5e4..92e360e 100644
|
|
|
9ae3a8 |
--- a/include/block/nbd.h
|
|
|
9ae3a8 |
+++ b/include/block/nbd.h
|
|
|
9ae3a8 |
@@ -92,8 +92,7 @@ NBDExport *nbd_export_find(const char *name);
|
|
|
9ae3a8 |
void nbd_export_set_name(NBDExport *exp, const char *name);
|
|
|
9ae3a8 |
void nbd_export_close_all(void);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-NBDClient *nbd_client_new(NBDExport *exp, int csock,
|
|
|
9ae3a8 |
- void (*close)(NBDClient *));
|
|
|
9ae3a8 |
+void nbd_client_new(NBDExport *exp, int csock, void (*close_fn)(NBDClient *));
|
|
|
9ae3a8 |
void nbd_client_close(NBDClient *client);
|
|
|
9ae3a8 |
void nbd_client_get(NBDClient *client);
|
|
|
9ae3a8 |
void nbd_client_put(NBDClient *client);
|
|
|
9ae3a8 |
diff --git a/nbd.c b/nbd.c
|
|
|
9ae3a8 |
index f258cdd..ba97270 100644
|
|
|
9ae3a8 |
--- a/nbd.c
|
|
|
9ae3a8 |
+++ b/nbd.c
|
|
|
9ae3a8 |
@@ -1232,8 +1232,7 @@ static void nbd_restart_write(void *opaque)
|
|
|
9ae3a8 |
qemu_coroutine_enter(client->send_coroutine, NULL);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-NBDClient *nbd_client_new(NBDExport *exp, int csock,
|
|
|
9ae3a8 |
- void (*close)(NBDClient *))
|
|
|
9ae3a8 |
+void nbd_client_new(NBDExport *exp, int csock, void (*close_fn)(NBDClient *))
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
NBDClient *client;
|
|
|
9ae3a8 |
client = g_malloc0(sizeof(NBDClient));
|
|
|
9ae3a8 |
@@ -1241,10 +1240,11 @@ NBDClient *nbd_client_new(NBDExport *exp, int csock,
|
|
|
9ae3a8 |
client->exp = exp;
|
|
|
9ae3a8 |
client->sock = csock;
|
|
|
9ae3a8 |
if (nbd_send_negotiate(client) < 0) {
|
|
|
9ae3a8 |
- g_free(client);
|
|
|
9ae3a8 |
- return NULL;
|
|
|
9ae3a8 |
+ shutdown(client->sock, 2);
|
|
|
9ae3a8 |
+ close_fn(client);
|
|
|
9ae3a8 |
+ return;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
- client->close = close;
|
|
|
9ae3a8 |
+ client->close = close_fn;
|
|
|
9ae3a8 |
qemu_co_mutex_init(&client->send_lock);
|
|
|
9ae3a8 |
qemu_set_fd_handler2(csock, nbd_can_read, nbd_read, NULL, client);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -1252,5 +1252,4 @@ NBDClient *nbd_client_new(NBDExport *exp, int csock,
|
|
|
9ae3a8 |
QTAILQ_INSERT_TAIL(&exp->clients, client, next);
|
|
|
9ae3a8 |
nbd_export_get(exp);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
- return client;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
diff --git a/qemu-nbd.c b/qemu-nbd.c
|
|
|
9ae3a8 |
index ff792ef..047dd49 100644
|
|
|
9ae3a8 |
--- a/qemu-nbd.c
|
|
|
9ae3a8 |
+++ b/qemu-nbd.c
|
|
|
9ae3a8 |
@@ -297,9 +297,9 @@ static void nbd_accept(void *opaque)
|
|
|
9ae3a8 |
close(fd);
|
|
|
9ae3a8 |
return;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (fd >= 0 && nbd_client_new(exp, fd, nbd_client_closed)) {
|
|
|
9ae3a8 |
+ if (fd >= 0) {
|
|
|
9ae3a8 |
nb_fds++;
|
|
|
9ae3a8 |
+ nbd_client_new(exp, fd, nbd_client_closed);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.8.3.1
|
|
|
9ae3a8 |
|