|
|
7711c0 |
From 44a47acaccb8455be42cb302885af0934c3360db Mon Sep 17 00:00:00 2001
|
|
|
7711c0 |
From: John Snow <jsnow@redhat.com>
|
|
|
7711c0 |
Date: Wed, 27 Mar 2019 17:22:59 +0100
|
|
|
7711c0 |
Subject: [PATCH 121/163] block/nbd: move connection code from block/nbd to
|
|
|
7711c0 |
block/nbd-client
|
|
|
7711c0 |
|
|
|
7711c0 |
RH-Author: John Snow <jsnow@redhat.com>
|
|
|
7711c0 |
Message-id: <20190327172308.31077-47-jsnow@redhat.com>
|
|
|
7711c0 |
Patchwork-id: 85218
|
|
|
7711c0 |
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 46/55] block/nbd: move connection code from block/nbd to block/nbd-client
|
|
|
7711c0 |
Bugzilla: 1691009
|
|
|
7711c0 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
7711c0 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
7711c0 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
7711c0 |
|
|
|
7711c0 |
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
|
|
|
7711c0 |
|
|
|
7711c0 |
Keep all connection code in one file, to be able to implement reconnect
|
|
|
7711c0 |
in further patches.
|
|
|
7711c0 |
|
|
|
7711c0 |
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
|
|
|
7711c0 |
Message-Id: <20190201130138.94525-3-vsementsov@virtuozzo.com>
|
|
|
7711c0 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
7711c0 |
[eblake: format tweak]
|
|
|
7711c0 |
Signed-off-by: Eric Blake <eblake@redhat.com>
|
|
|
7711c0 |
(cherry picked from commit d42f78e9400c51f1ae30dadd52995e4d6b052d89)
|
|
|
7711c0 |
Signed-off-by: John Snow <jsnow@redhat.com>
|
|
|
7711c0 |
|
|
|
7711c0 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
7711c0 |
---
|
|
|
7711c0 |
block/nbd-client.c | 38 ++++++++++++++++++++++++++++++++++++--
|
|
|
7711c0 |
block/nbd-client.h | 2 +-
|
|
|
7711c0 |
block/nbd.c | 40 ++--------------------------------------
|
|
|
7711c0 |
3 files changed, 39 insertions(+), 41 deletions(-)
|
|
|
7711c0 |
|
|
|
7711c0 |
diff --git a/block/nbd-client.c b/block/nbd-client.c
|
|
|
7711c0 |
index f5b9aaa..d86c412 100644
|
|
|
7711c0 |
--- a/block/nbd-client.c
|
|
|
7711c0 |
+++ b/block/nbd-client.c
|
|
|
7711c0 |
@@ -990,8 +990,29 @@ void nbd_client_close(BlockDriverState *bs)
|
|
|
7711c0 |
nbd_teardown_connection(bs);
|
|
|
7711c0 |
}
|
|
|
7711c0 |
|
|
|
7711c0 |
+static QIOChannelSocket *nbd_establish_connection(SocketAddress *saddr,
|
|
|
7711c0 |
+ Error **errp)
|
|
|
7711c0 |
+{
|
|
|
7711c0 |
+ QIOChannelSocket *sioc;
|
|
|
7711c0 |
+ Error *local_err = NULL;
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ sioc = qio_channel_socket_new();
|
|
|
7711c0 |
+ qio_channel_set_name(QIO_CHANNEL(sioc), "nbd-client");
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ qio_channel_socket_connect_sync(sioc, saddr, &local_err);
|
|
|
7711c0 |
+ if (local_err) {
|
|
|
7711c0 |
+ object_unref(OBJECT(sioc));
|
|
|
7711c0 |
+ error_propagate(errp, local_err);
|
|
|
7711c0 |
+ return NULL;
|
|
|
7711c0 |
+ }
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ qio_channel_set_delay(QIO_CHANNEL(sioc), false);
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ return sioc;
|
|
|
7711c0 |
+}
|
|
|
7711c0 |
+
|
|
|
7711c0 |
int nbd_client_init(BlockDriverState *bs,
|
|
|
7711c0 |
- QIOChannelSocket *sioc,
|
|
|
7711c0 |
+ SocketAddress *saddr,
|
|
|
7711c0 |
const char *export,
|
|
|
7711c0 |
QCryptoTLSCreds *tlscreds,
|
|
|
7711c0 |
const char *hostname,
|
|
|
7711c0 |
@@ -1001,6 +1022,16 @@ int nbd_client_init(BlockDriverState *bs,
|
|
|
7711c0 |
NBDClientSession *client = nbd_get_client_session(bs);
|
|
|
7711c0 |
int ret;
|
|
|
7711c0 |
|
|
|
7711c0 |
+ /*
|
|
|
7711c0 |
+ * establish TCP connection, return error if it fails
|
|
|
7711c0 |
+ * TODO: Configurable retry-until-timeout behaviour.
|
|
|
7711c0 |
+ */
|
|
|
7711c0 |
+ QIOChannelSocket *sioc = nbd_establish_connection(saddr, errp);
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ if (!sioc) {
|
|
|
7711c0 |
+ return -ECONNREFUSED;
|
|
|
7711c0 |
+ }
|
|
|
7711c0 |
+
|
|
|
7711c0 |
/* NBD handshake */
|
|
|
7711c0 |
logout("session init %s\n", export);
|
|
|
7711c0 |
qio_channel_set_blocking(QIO_CHANNEL(sioc), true, NULL);
|
|
|
7711c0 |
@@ -1016,6 +1047,7 @@ int nbd_client_init(BlockDriverState *bs,
|
|
|
7711c0 |
g_free(client->info.name);
|
|
|
7711c0 |
if (ret < 0) {
|
|
|
7711c0 |
logout("Failed to negotiate with the NBD server\n");
|
|
|
7711c0 |
+ object_unref(OBJECT(sioc));
|
|
|
7711c0 |
return ret;
|
|
|
7711c0 |
}
|
|
|
7711c0 |
if (x_dirty_bitmap && !client->info.base_allocation) {
|
|
|
7711c0 |
@@ -1041,7 +1073,6 @@ int nbd_client_init(BlockDriverState *bs,
|
|
|
7711c0 |
qemu_co_mutex_init(&client->send_mutex);
|
|
|
7711c0 |
qemu_co_queue_init(&client->free_sema);
|
|
|
7711c0 |
client->sioc = sioc;
|
|
|
7711c0 |
- object_ref(OBJECT(client->sioc));
|
|
|
7711c0 |
|
|
|
7711c0 |
if (!client->ioc) {
|
|
|
7711c0 |
client->ioc = QIO_CHANNEL(sioc);
|
|
|
7711c0 |
@@ -1067,6 +1098,9 @@ int nbd_client_init(BlockDriverState *bs,
|
|
|
7711c0 |
NBDRequest request = { .type = NBD_CMD_DISC };
|
|
|
7711c0 |
|
|
|
7711c0 |
nbd_send_request(client->ioc ?: QIO_CHANNEL(sioc), &request);
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ object_unref(OBJECT(sioc));
|
|
|
7711c0 |
+
|
|
|
7711c0 |
return ret;
|
|
|
7711c0 |
}
|
|
|
7711c0 |
}
|
|
|
7711c0 |
diff --git a/block/nbd-client.h b/block/nbd-client.h
|
|
|
7711c0 |
index cfc9055..2f047ba 100644
|
|
|
7711c0 |
--- a/block/nbd-client.h
|
|
|
7711c0 |
+++ b/block/nbd-client.h
|
|
|
7711c0 |
@@ -41,7 +41,7 @@ typedef struct NBDClientSession {
|
|
|
7711c0 |
NBDClientSession *nbd_get_client_session(BlockDriverState *bs);
|
|
|
7711c0 |
|
|
|
7711c0 |
int nbd_client_init(BlockDriverState *bs,
|
|
|
7711c0 |
- QIOChannelSocket *sock,
|
|
|
7711c0 |
+ SocketAddress *saddr,
|
|
|
7711c0 |
const char *export_name,
|
|
|
7711c0 |
QCryptoTLSCreds *tlscreds,
|
|
|
7711c0 |
const char *hostname,
|
|
|
7711c0 |
diff --git a/block/nbd.c b/block/nbd.c
|
|
|
7711c0 |
index f29c10f..838a8fe 100644
|
|
|
7711c0 |
--- a/block/nbd.c
|
|
|
7711c0 |
+++ b/block/nbd.c
|
|
|
7711c0 |
@@ -295,30 +295,6 @@ NBDClientSession *nbd_get_client_session(BlockDriverState *bs)
|
|
|
7711c0 |
return &s->client;
|
|
|
7711c0 |
}
|
|
|
7711c0 |
|
|
|
7711c0 |
-static QIOChannelSocket *nbd_establish_connection(SocketAddress *saddr,
|
|
|
7711c0 |
- Error **errp)
|
|
|
7711c0 |
-{
|
|
|
7711c0 |
- QIOChannelSocket *sioc;
|
|
|
7711c0 |
- Error *local_err = NULL;
|
|
|
7711c0 |
-
|
|
|
7711c0 |
- sioc = qio_channel_socket_new();
|
|
|
7711c0 |
- qio_channel_set_name(QIO_CHANNEL(sioc), "nbd-client");
|
|
|
7711c0 |
-
|
|
|
7711c0 |
- qio_channel_socket_connect_sync(sioc,
|
|
|
7711c0 |
- saddr,
|
|
|
7711c0 |
- &local_err);
|
|
|
7711c0 |
- if (local_err) {
|
|
|
7711c0 |
- object_unref(OBJECT(sioc));
|
|
|
7711c0 |
- error_propagate(errp, local_err);
|
|
|
7711c0 |
- return NULL;
|
|
|
7711c0 |
- }
|
|
|
7711c0 |
-
|
|
|
7711c0 |
- qio_channel_set_delay(QIO_CHANNEL(sioc), false);
|
|
|
7711c0 |
-
|
|
|
7711c0 |
- return sioc;
|
|
|
7711c0 |
-}
|
|
|
7711c0 |
-
|
|
|
7711c0 |
-
|
|
|
7711c0 |
static QCryptoTLSCreds *nbd_get_tls_creds(const char *id, Error **errp)
|
|
|
7711c0 |
{
|
|
|
7711c0 |
Object *obj;
|
|
|
7711c0 |
@@ -394,7 +370,6 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
7711c0 |
BDRVNBDState *s = bs->opaque;
|
|
|
7711c0 |
QemuOpts *opts = NULL;
|
|
|
7711c0 |
Error *local_err = NULL;
|
|
|
7711c0 |
- QIOChannelSocket *sioc = NULL;
|
|
|
7711c0 |
QCryptoTLSCreds *tlscreds = NULL;
|
|
|
7711c0 |
const char *hostname = NULL;
|
|
|
7711c0 |
int ret = -EINVAL;
|
|
|
7711c0 |
@@ -434,22 +409,11 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
7711c0 |
hostname = s->saddr->u.inet.host;
|
|
|
7711c0 |
}
|
|
|
7711c0 |
|
|
|
7711c0 |
- /* establish TCP connection, return error if it fails
|
|
|
7711c0 |
- * TODO: Configurable retry-until-timeout behaviour.
|
|
|
7711c0 |
- */
|
|
|
7711c0 |
- sioc = nbd_establish_connection(s->saddr, errp);
|
|
|
7711c0 |
- if (!sioc) {
|
|
|
7711c0 |
- ret = -ECONNREFUSED;
|
|
|
7711c0 |
- goto error;
|
|
|
7711c0 |
- }
|
|
|
7711c0 |
-
|
|
|
7711c0 |
/* NBD handshake */
|
|
|
7711c0 |
- ret = nbd_client_init(bs, sioc, s->export, tlscreds, hostname,
|
|
|
7711c0 |
+ ret = nbd_client_init(bs, s->saddr, s->export, tlscreds, hostname,
|
|
|
7711c0 |
qemu_opt_get(opts, "x-dirty-bitmap"), errp);
|
|
|
7711c0 |
+
|
|
|
7711c0 |
error:
|
|
|
7711c0 |
- if (sioc) {
|
|
|
7711c0 |
- object_unref(OBJECT(sioc));
|
|
|
7711c0 |
- }
|
|
|
7711c0 |
if (tlscreds) {
|
|
|
7711c0 |
object_unref(OBJECT(tlscreds));
|
|
|
7711c0 |
}
|
|
|
7711c0 |
--
|
|
|
7711c0 |
1.8.3.1
|
|
|
7711c0 |
|