[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 27/33] block/nbd: split nbd_co_do_establish_connection out of
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v3 27/33] block/nbd: split nbd_co_do_establish_connection out of nbd_reconnect_attempt |
Date: |
Fri, 16 Apr 2021 11:09:05 +0300 |
Split out part, that we want to reuse for nbd_open().
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
block/nbd.c | 79 +++++++++++++++++++++++++++--------------------------
1 file changed, 41 insertions(+), 38 deletions(-)
diff --git a/block/nbd.c b/block/nbd.c
index 15b5921725..59971bfba8 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -361,11 +361,49 @@ static int nbd_handle_updated_info(BlockDriverState *bs,
Error **errp)
return 0;
}
-static coroutine_fn void nbd_reconnect_attempt(BDRVNBDState *s)
+static int nbd_co_do_establish_connection(BlockDriverState *bs, Error **errp)
{
+ BDRVNBDState *s = (BDRVNBDState *)bs->opaque;
int ret;
- AioContext *aio_context = bdrv_get_aio_context(s->bs);
+ assert(!s->ioc);
+
+ s->ioc = nbd_co_establish_connection(s->conn, &s->info, errp);
+ if (!s->ioc) {
+ return -ECONNREFUSED;
+ }
+
+ 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 };
+
+ nbd_send_request(s->ioc, &request);
+
+ object_unref(OBJECT(s->ioc));
+ s->ioc = NULL;
+
+ return ret;
+ }
+
+ qio_channel_set_blocking(s->ioc, false, NULL);
+ qio_channel_attach_aio_context(s->ioc, bdrv_get_aio_context(bs));
+
+ yank_register_function(BLOCKDEV_YANK_INSTANCE(s->bs->node_name), nbd_yank,
+ bs);
+
+ /* successfully connected */
+ s->state = NBD_CLIENT_CONNECTED;
+ qemu_co_queue_restart_all(&s->free_sema);
+
+ return 0;
+}
+
+static coroutine_fn void nbd_reconnect_attempt(BDRVNBDState *s)
+{
if (!nbd_client_connecting(s)) {
return;
}
@@ -403,42 +441,7 @@ static coroutine_fn void
nbd_reconnect_attempt(BDRVNBDState *s)
s->ioc = NULL;
}
- s->ioc = nbd_co_establish_connection(s->conn, &s->info, NULL);
- if (!s->ioc) {
- ret = -ECONNREFUSED;
- goto out;
- }
-
- qio_channel_set_blocking(QIO_CHANNEL(s->ioc), false, NULL);
- qio_channel_attach_aio_context(QIO_CHANNEL(s->ioc), aio_context);
-
- yank_register_function(BLOCKDEV_YANK_INSTANCE(s->bs->node_name), nbd_yank,
- 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 };
-
- nbd_send_request(s->ioc, &request);
-
- yank_unregister_function(BLOCKDEV_YANK_INSTANCE(s->bs->node_name),
- nbd_yank, s->bs);
- object_unref(OBJECT(s->ioc));
- s->ioc = NULL;
-
- return;
- }
-
-out:
- if (ret >= 0) {
- /* successfully connected */
- s->state = NBD_CLIENT_CONNECTED;
- qemu_co_queue_restart_all(&s->free_sema);
- }
+ nbd_co_do_establish_connection(s->bs, NULL);
}
static coroutine_fn void nbd_co_reconnect_loop(BDRVNBDState *s)
--
2.29.2
- Re: [PATCH v3 15/33] nbd/client-connection: use QEMU_LOCK_GUARD, (continued)
- [PATCH v3 16/33] nbd/client-connection: add possibility of negotiation, Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 23/33] block/nbd: nbd_teardown_connection() don't touch s->sioc, Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 17/33] nbd/client-connection: implement connection retry, 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 14/33] nbd: move connection code from block/nbd to nbd/client-connection, 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 <=
- [PATCH v3 18/33] nbd/client-connection: shutdown connection on release, Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 24/33] block/nbd: drop BDRVNBDState::sioc, 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 28/33] nbd/client-connection: do qio_channel_set_delay(false), 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
- [PATCH v3 26/33] block-coroutine-wrapper: allow non bdrv_ prefix, Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 29/33] nbd/client-connection: add option for non-blocking connection attempt, Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 22/33] block/nbd: pass monitor directly to connection thread, Vladimir Sementsov-Ogievskiy, 2021/04/16