[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 20/33] block/nbd: use negotiation of NBDClientConnection
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v3 20/33] block/nbd: use negotiation of NBDClientConnection |
Date: |
Fri, 16 Apr 2021 11:08:58 +0300 |
Use a new possibility of negotiation in connect thread. Now we are on
the way of simplifying connection_co. We want to move the whole
reconnect code to NBDClientConnection. NBDClientConnection already
updated to support negotiation and retry. Use now the first thing.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
block/nbd.c | 44 ++++++++++++++++++++++++++++++--------------
1 file changed, 30 insertions(+), 14 deletions(-)
diff --git a/block/nbd.c b/block/nbd.c
index 03ffe95231..c1e61a2a52 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -365,6 +365,7 @@ static int nbd_handle_updated_info(BlockDriverState *bs,
Error **errp)
static coroutine_fn void nbd_reconnect_attempt(BDRVNBDState *s)
{
int ret;
+ AioContext *aio_context = bdrv_get_aio_context(s->bs);
if (!nbd_client_connecting(s)) {
return;
@@ -405,30 +406,44 @@ static coroutine_fn void
nbd_reconnect_attempt(BDRVNBDState *s)
s->ioc = NULL;
}
- s->sioc = nbd_co_establish_connection(s->conn, NULL, NULL, NULL);
+ s->sioc = nbd_co_establish_connection(s->conn, &s->info, &s->ioc, NULL);
if (!s->sioc) {
ret = -ECONNREFUSED;
goto out;
}
+ qio_channel_set_blocking(QIO_CHANNEL(s->sioc), false, NULL);
+ qio_channel_attach_aio_context(QIO_CHANNEL(s->sioc), aio_context);
+ if (s->ioc) {
+ qio_channel_set_blocking(QIO_CHANNEL(s->ioc), false, NULL);
+ qio_channel_attach_aio_context(QIO_CHANNEL(s->ioc), aio_context);
+ } else {
+ s->ioc = QIO_CHANNEL(s->sioc);
+ object_ref(OBJECT(s->ioc));
+ }
+
yank_register_function(BLOCKDEV_YANK_INSTANCE(s->bs->node_name), nbd_yank,
s->bs);
- bdrv_dec_in_flight(s->bs);
+ ret = nbd_handle_updated_info(s->bs, NULL);
+ if (ret < 0) {
+ /*
+ * We have connected, but must fail for other reasons.
+ * Send NBD_CMD_DISC as a courtesy to the server.
+ */
+ NBDRequest request = { .type = NBD_CMD_DISC };
- ret = nbd_client_handshake(s->bs, NULL);
+ nbd_send_request(s->ioc, &request);
- if (s->drained) {
- s->wait_drained_end = true;
- while (s->drained) {
- /*
- * We may be entered once from nbd_client_attach_aio_context_bh
- * and then from nbd_client_co_drain_end. So here is a loop.
- */
- qemu_coroutine_yield();
- }
+ yank_unregister_function(BLOCKDEV_YANK_INSTANCE(s->bs->node_name),
+ nbd_yank, s->bs);
+ object_unref(OBJECT(s->sioc));
+ s->sioc = NULL;
+ object_unref(OBJECT(s->ioc));
+ s->ioc = NULL;
+
+ return;
}
- bdrv_inc_in_flight(s->bs);
out:
if (ret >= 0) {
@@ -2048,7 +2063,8 @@ static int nbd_open(BlockDriverState *bs, QDict *options,
int flags,
goto fail;
}
- s->conn = nbd_client_connection_new(s->saddr, false, NULL, NULL, NULL);
+ s->conn = nbd_client_connection_new(s->saddr, true, s->export,
+ s->x_dirty_bitmap, s->tlscreds);
/*
* establish TCP connection, return error if it fails
--
2.29.2
- [PATCH v3 17/33] nbd/client-connection: implement connection retry, (continued)
- [PATCH v3 17/33] nbd/client-connection: implement connection retry, Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 24/33] block/nbd: drop BDRVNBDState::sioc, Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 13/33] block/nbd: introduce nbd_client_connection_release(), Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 27/33] block/nbd: split nbd_co_do_establish_connection out of nbd_reconnect_attempt, Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 18/33] nbd/client-connection: shutdown connection on release, Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 28/33] nbd/client-connection: do qio_channel_set_delay(false), Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 25/33] nbd/client-connection: return only one io channel, Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 22/33] block/nbd: pass monitor directly to connection thread, Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 20/33] block/nbd: use negotiation of NBDClientConnection,
Vladimir Sementsov-Ogievskiy <=
- [PATCH v3 29/33] nbd/client-connection: add option for non-blocking connection attempt, Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 19/33] block/nbd: split nbd_handle_updated_info out of nbd_client_handshake(), Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 26/33] block-coroutine-wrapper: allow non bdrv_ prefix, Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 30/33] block/nbd: reuse nbd_co_do_establish_connection() in nbd_open(), Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 31/33] block/nbd: add nbd_clinent_connected() helper, Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 33/33] block/nbd: drop connection_co, Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 21/33] qemu-socket: pass monitor link to socket_get_fd directly, Vladimir Sementsov-Ogievskiy, 2021/04/16