[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 4/7] nbd/client: Pass mode through to nbd_send_request
From: |
Eric Blake |
Subject: |
[PULL 4/7] nbd/client: Pass mode through to nbd_send_request |
Date: |
Mon, 25 Sep 2023 14:01:19 -0500 |
Once the 64-bit headers extension is enabled, the data layout we send
over the wire for a client request depends on the mode negotiated with
the server. Rather than adding a parameter to nbd_send_request, we
can add a member to struct NBDRequest, since it already does not
reflect on-wire format. Some callers initialize it directly; many
others rely on a common initialization point during
nbd_co_send_request(). At this point, there is no semantic change.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Message-ID: <20230829175826.377251-21-eblake@redhat.com>
---
include/block/nbd.h | 12 +++++++-----
block/nbd.c | 5 +++--
nbd/client.c | 3 ++-
3 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/include/block/nbd.h b/include/block/nbd.h
index 53226764574..e07b9f9bff7 100644
--- a/include/block/nbd.h
+++ b/include/block/nbd.h
@@ -63,17 +63,19 @@ typedef enum NBDMode {
/* TODO add NBD_MODE_EXTENDED */
} NBDMode;
-/* Transmission phase structs
- *
- * Note: these are _NOT_ the same as the network representation of an NBD
- * request and reply!
+/* Transmission phase structs */
+
+/*
+ * Note: NBDRequest is _NOT_ the same as the network representation of an NBD
+ * request!
*/
typedef struct NBDRequest {
uint64_t cookie;
uint64_t from;
uint32_t len;
uint16_t flags; /* NBD_CMD_FLAG_* */
- uint16_t type; /* NBD_CMD_* */
+ uint16_t type; /* NBD_CMD_* */
+ NBDMode mode; /* Determines which network representation to use */
} NBDRequest;
typedef struct NBDSimpleReply {
diff --git a/block/nbd.c b/block/nbd.c
index 676b755d79f..24f50b79e47 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -339,7 +339,7 @@ int coroutine_fn
nbd_co_do_establish_connection(BlockDriverState *bs,
* 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 };
+ NBDRequest request = { .type = NBD_CMD_DISC, .mode = s->info.mode };
nbd_send_request(s->ioc, &request);
@@ -520,6 +520,7 @@ nbd_co_send_request(BlockDriverState *bs, NBDRequest
*request,
qemu_co_mutex_lock(&s->send_mutex);
request->cookie = INDEX_TO_COOKIE(i);
+ request->mode = s->info.mode;
assert(s->ioc);
@@ -1465,7 +1466,7 @@ static void nbd_yank(void *opaque)
static void nbd_client_close(BlockDriverState *bs)
{
BDRVNBDState *s = (BDRVNBDState *)bs->opaque;
- NBDRequest request = { .type = NBD_CMD_DISC };
+ NBDRequest request = { .type = NBD_CMD_DISC, .mode = s->info.mode };
if (s->ioc) {
nbd_send_request(s->ioc, &request);
diff --git a/nbd/client.c b/nbd/client.c
index 844be42181a..345f1c0f2d0 100644
--- a/nbd/client.c
+++ b/nbd/client.c
@@ -1218,7 +1218,7 @@ int nbd_receive_export_list(QIOChannel *ioc,
QCryptoTLSCreds *tlscreds,
/* Send NBD_CMD_DISC as a courtesy to the server, but ignore all
* errors now that we have the information we wanted. */
if (nbd_drop(ioc, 124, NULL) == 0) {
- NBDRequest request = { .type = NBD_CMD_DISC };
+ NBDRequest request = { .type = NBD_CMD_DISC, .mode = result };
nbd_send_request(ioc, &request);
}
@@ -1348,6 +1348,7 @@ int nbd_send_request(QIOChannel *ioc, NBDRequest *request)
{
uint8_t buf[NBD_REQUEST_SIZE];
+ assert(request->mode <= NBD_MODE_STRUCTURED); /* TODO handle extended */
trace_nbd_send_request(request->from, request->len, request->cookie,
request->flags, request->type,
nbd_cmd_lookup(request->type));
--
2.41.0
- [PULL 0/7] NBD patches through 2023-09-25, Eric Blake, 2023/09/25
- [PULL 1/7] iotests: use TEST_IMG_FILE instead of TEST_IMG in _require_large_file, Eric Blake, 2023/09/25
- [PULL 4/7] nbd/client: Pass mode through to nbd_send_request,
Eric Blake <=
- [PULL 7/7] nbd/server: Refactor handling of command sanity checks, Eric Blake, 2023/09/25
- [PULL 6/7] nbd: Prepare for 64-bit request effect lengths, Eric Blake, 2023/09/25
- [PULL 5/7] nbd: Add types for extended headers, Eric Blake, 2023/09/25
- [PULL 2/7] iotests: improve 'not run' message for nbd-multiconn test, Eric Blake, 2023/09/25
- [PULL 3/7] nbd: Replace bool structured_reply with mode enum, Eric Blake, 2023/09/25
- Re: [PULL 0/7] NBD patches through 2023-09-25, Stefan Hajnoczi, 2023/09/26