[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 19/33] block/nbd: split nbd_handle_updated_info out of nbd_cli
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v3 19/33] block/nbd: split nbd_handle_updated_info out of nbd_client_handshake() |
Date: |
Fri, 16 Apr 2021 11:08:57 +0300 |
To be reused in the following patch.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
block/nbd.c | 99 ++++++++++++++++++++++++++++++-----------------------
1 file changed, 57 insertions(+), 42 deletions(-)
diff --git a/block/nbd.c b/block/nbd.c
index 5e63caaf4b..03ffe95231 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -318,6 +318,50 @@ static bool nbd_client_connecting_wait(BDRVNBDState *s)
return qatomic_load_acquire(&s->state) == NBD_CLIENT_CONNECTING_WAIT;
}
+/*
+ * Check s->info updated by negotiation process.
+ * Update @bs correspondingly to new options.
+ */
+static int nbd_handle_updated_info(BlockDriverState *bs, Error **errp)
+{
+ BDRVNBDState *s = (BDRVNBDState *)bs->opaque;
+ int ret;
+
+ if (s->x_dirty_bitmap) {
+ if (!s->info.base_allocation) {
+ error_setg(errp, "requested x-dirty-bitmap %s not found",
+ s->x_dirty_bitmap);
+ return -EINVAL;
+ }
+ if (strcmp(s->x_dirty_bitmap, "qemu:allocation-depth") == 0) {
+ s->alloc_depth = true;
+ }
+ }
+
+ if (s->info.flags & NBD_FLAG_READ_ONLY) {
+ ret = bdrv_apply_auto_read_only(bs, "NBD export is read-only", errp);
+ if (ret < 0) {
+ return ret;
+ }
+ }
+
+ if (s->info.flags & NBD_FLAG_SEND_FUA) {
+ bs->supported_write_flags = BDRV_REQ_FUA;
+ bs->supported_zero_flags |= BDRV_REQ_FUA;
+ }
+
+ if (s->info.flags & NBD_FLAG_SEND_WRITE_ZEROES) {
+ bs->supported_zero_flags |= BDRV_REQ_MAY_UNMAP;
+ if (s->info.flags & NBD_FLAG_SEND_FAST_ZERO) {
+ bs->supported_zero_flags |= BDRV_REQ_NO_FALLBACK;
+ }
+ }
+
+ trace_nbd_client_handshake_success(s->export);
+
+ return 0;
+}
+
static coroutine_fn void nbd_reconnect_attempt(BDRVNBDState *s)
{
int ret;
@@ -1579,49 +1623,13 @@ static int nbd_client_handshake(BlockDriverState *bs,
Error **errp)
s->sioc = NULL;
return ret;
}
- if (s->x_dirty_bitmap) {
- if (!s->info.base_allocation) {
- error_setg(errp, "requested x-dirty-bitmap %s not found",
- s->x_dirty_bitmap);
- ret = -EINVAL;
- goto fail;
- }
- if (strcmp(s->x_dirty_bitmap, "qemu:allocation-depth") == 0) {
- s->alloc_depth = true;
- }
- }
- if (s->info.flags & NBD_FLAG_READ_ONLY) {
- ret = bdrv_apply_auto_read_only(bs, "NBD export is read-only", errp);
- if (ret < 0) {
- goto fail;
- }
- }
- if (s->info.flags & NBD_FLAG_SEND_FUA) {
- bs->supported_write_flags = BDRV_REQ_FUA;
- bs->supported_zero_flags |= BDRV_REQ_FUA;
- }
- if (s->info.flags & NBD_FLAG_SEND_WRITE_ZEROES) {
- bs->supported_zero_flags |= BDRV_REQ_MAY_UNMAP;
- if (s->info.flags & NBD_FLAG_SEND_FAST_ZERO) {
- bs->supported_zero_flags |= BDRV_REQ_NO_FALLBACK;
- }
- }
- if (!s->ioc) {
- s->ioc = QIO_CHANNEL(s->sioc);
- object_ref(OBJECT(s->ioc));
- }
-
- trace_nbd_client_handshake_success(s->export);
-
- return 0;
-
- fail:
- /*
- * We have connected, but must fail for other reasons.
- * Send NBD_CMD_DISC as a courtesy to the server.
- */
- {
+ ret = nbd_handle_updated_info(bs, errp);
+ 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 ?: QIO_CHANNEL(s->sioc), &request);
@@ -1635,6 +1643,13 @@ static int nbd_client_handshake(BlockDriverState *bs,
Error **errp)
return ret;
}
+
+ if (!s->ioc) {
+ s->ioc = QIO_CHANNEL(s->sioc);
+ object_ref(OBJECT(s->ioc));
+ }
+
+ return 0;
}
/*
--
2.29.2
- [PATCH v3 13/33] block/nbd: introduce nbd_client_connection_release(), (continued)
- [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, 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 19/33] block/nbd: split nbd_handle_updated_info out of nbd_client_handshake(),
Vladimir Sementsov-Ogievskiy <=
- [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
- [PATCH v3 32/33] block/nbd: safer transition to receiving request, Vladimir Sementsov-Ogievskiy, 2021/04/16