mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
Merge tag 'pull-nbd-2023-10-05' of https://repo.or.cz/qemu/ericb into staging
NBD patches for 2023-10-05 - various: mailmap cleanups - Eric Blake: enable use of NBD 64-bit extended headers # -----BEGIN PGP SIGNATURE----- # # iQEzBAABCAAdFiEEccLMIrHEYCkn0vOqp6FrSiUnQ2oFAmUfA94ACgkQp6FrSiUn # Q2o2hAf/Q4q6RoEG9WoOIa6WB1nk9tZN6GRfW4jS+09hJTFVbYUhJOcvQwwZjPT6 # 6oIwde8w7uE+AxBOA3XPbgTOBnTnpt2RH2AYVctNYB2vonuSrx3/KE3XSi4nrJRo # +XiPbOsDzQu+vYsI7XJ+5e13BE4iZVmzbyke0U6hO88uR6tQstDJV1Mhem4jIbCG # uLzkVDs3yY5sUFoUe77lFGWgKqfh87eJXV18T76df97ZZ5O2/w9G8MknG/CTSsR0 # fmzzC1Q4a2UEFtX8M3etRQ/b5WbFYhM+XwFevm2YBpod89ejGEA0ohhpn+GpZDU9 # SU66lXL/5jM9N7RkiSFwvupaot9hvw== # =UieX # -----END PGP SIGNATURE----- # gpg: Signature made Thu 05 Oct 2023 14:43:42 EDT # gpg: using RSA key 71C2CC22B1C4602927D2F3AAA7A16B4A2527436A # gpg: Good signature from "Eric Blake <eblake@redhat.com>" [full] # gpg: aka "Eric Blake (Free Software Programmer) <ebb9@byu.net>" [full] # gpg: aka "[jpeg image of size 6874]" [full] # Primary key fingerprint: 71C2 CC22 B1C4 6029 27D2 F3AA A7A1 6B4A 2527 436A * tag 'pull-nbd-2023-10-05' of https://repo.or.cz/qemu/ericb: nbd/server: Add FLAG_PAYLOAD support to CMD_BLOCK_STATUS nbd/server: Prepare for per-request filtering of BLOCK_STATUS nbd/server: Refactor list of negotiated meta contexts nbd/client: Request extended headers during negotiation nbd/client: Accept 64-bit block status chunks nbd/client: Initial support for extended headers nbd/client: Plumb errp through nbd_receive_replies nbd/server: Enable initial support for extended headers nbd/server: Support 64-bit block status nbd/server: Prepare to send extended header replies nbd/server: Prepare to receive extended header requests nbd/server: Support a request payload mailmap: Fix BALATON Zoltan author email maint: Tweak comments in mailmap regarding SPF mailmap: Fix Andrey Drobyshev author email Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
@@ -40,12 +40,26 @@ Nick Hudson <hnick@vmware.com> hnick@vmware.com <hnick@vmware.com>
|
||||
# for the cvs2svn initialization commit e63c3dc74bf.
|
||||
|
||||
# Next, translate a few commits where mailman rewrote the From: line due
|
||||
# to strict SPF, although we prefer to avoid adding more entries like that.
|
||||
# to strict SPF and DMARC. Usually, our build process should be flagging
|
||||
# commits like these before maintainer merges; if you find the need to add
|
||||
# a line here, please also report a bug against the part of the build
|
||||
# process that let the mis-attribution slip through in the first place.
|
||||
#
|
||||
# If the mailing list munges your emails, use:
|
||||
# git config sendemail.from '"Your Name" <your.email@example.com>'
|
||||
# the use of "" in that line will differ from the typically unquoted
|
||||
# 'git config user.name', which in turn is sufficient for 'git send-email'
|
||||
# to add an extra From: line in the body of your email that takes
|
||||
# precedence over any munged From: in the mail's headers.
|
||||
# See https://lists.openembedded.org/g/openembedded-core/message/166515
|
||||
# and https://lists.gnu.org/archive/html/qemu-devel/2023-09/msg06784.html
|
||||
Ed Swierk <eswierk@skyportsystems.com> Ed Swierk via Qemu-devel <qemu-devel@nongnu.org>
|
||||
Ian McKellar <ianloic@google.com> Ian McKellar via Qemu-devel <qemu-devel@nongnu.org>
|
||||
Julia Suvorova <jusual@mail.ru> Julia Suvorova via Qemu-devel <qemu-devel@nongnu.org>
|
||||
Justin Terry (VM) <juterry@microsoft.com> Justin Terry (VM) via Qemu-devel <qemu-devel@nongnu.org>
|
||||
Stefan Weil <sw@weilnetz.de> Stefan Weil via <qemu-devel@nongnu.org>
|
||||
Andrey Drobyshev <andrey.drobyshev@virtuozzo.com> Andrey Drobyshev via <qemu-block@nongnu.org>
|
||||
BALATON Zoltan <balaton@eik.bme.hu> BALATON Zoltan via <qemu-ppc@nongnu.org>
|
||||
|
||||
# Next, replace old addresses by a more recent one.
|
||||
Aleksandar Markovic <aleksandar.qemu.devel@gmail.com> <aleksandar.markovic@mips.com>
|
||||
|
||||
+46
-21
@@ -416,7 +416,8 @@ static void coroutine_fn GRAPH_RDLOCK nbd_reconnect_attempt(BDRVNBDState *s)
|
||||
reconnect_delay_timer_del(s);
|
||||
}
|
||||
|
||||
static coroutine_fn int nbd_receive_replies(BDRVNBDState *s, uint64_t cookie)
|
||||
static coroutine_fn int nbd_receive_replies(BDRVNBDState *s, uint64_t cookie,
|
||||
Error **errp)
|
||||
{
|
||||
int ret;
|
||||
uint64_t ind = COOKIE_TO_INDEX(cookie), ind2;
|
||||
@@ -457,20 +458,25 @@ static coroutine_fn int nbd_receive_replies(BDRVNBDState *s, uint64_t cookie)
|
||||
|
||||
/* We are under mutex and cookie is 0. We have to do the dirty work. */
|
||||
assert(s->reply.cookie == 0);
|
||||
ret = nbd_receive_reply(s->bs, s->ioc, &s->reply, NULL);
|
||||
if (ret <= 0) {
|
||||
ret = ret ? ret : -EIO;
|
||||
ret = nbd_receive_reply(s->bs, s->ioc, &s->reply, s->info.mode, errp);
|
||||
if (ret == 0) {
|
||||
ret = -EIO;
|
||||
error_setg(errp, "server dropped connection");
|
||||
}
|
||||
if (ret < 0) {
|
||||
nbd_channel_error(s, ret);
|
||||
return ret;
|
||||
}
|
||||
if (nbd_reply_is_structured(&s->reply) &&
|
||||
s->info.mode < NBD_MODE_STRUCTURED) {
|
||||
nbd_channel_error(s, -EINVAL);
|
||||
error_setg(errp, "unexpected structured reply");
|
||||
return -EINVAL;
|
||||
}
|
||||
ind2 = COOKIE_TO_INDEX(s->reply.cookie);
|
||||
if (ind2 >= MAX_NBD_REQUESTS || !s->requests[ind2].coroutine) {
|
||||
nbd_channel_error(s, -EINVAL);
|
||||
error_setg(errp, "unexpected cookie value");
|
||||
return -EINVAL;
|
||||
}
|
||||
if (s->reply.cookie == cookie) {
|
||||
@@ -609,13 +615,17 @@ static int nbd_parse_offset_hole_payload(BDRVNBDState *s,
|
||||
*/
|
||||
static int nbd_parse_blockstatus_payload(BDRVNBDState *s,
|
||||
NBDStructuredReplyChunk *chunk,
|
||||
uint8_t *payload, uint64_t orig_length,
|
||||
NBDExtent32 *extent, Error **errp)
|
||||
uint8_t *payload, bool wide,
|
||||
uint64_t orig_length,
|
||||
NBDExtent64 *extent, Error **errp)
|
||||
{
|
||||
uint32_t context_id;
|
||||
uint32_t count;
|
||||
size_t ext_len = wide ? sizeof(*extent) : sizeof(NBDExtent32);
|
||||
size_t pay_len = sizeof(context_id) + wide * sizeof(count) + ext_len;
|
||||
|
||||
/* The server succeeded, so it must have sent [at least] one extent */
|
||||
if (chunk->length < sizeof(context_id) + sizeof(*extent)) {
|
||||
if (chunk->length < pay_len) {
|
||||
error_setg(errp, "Protocol error: invalid payload for "
|
||||
"NBD_REPLY_TYPE_BLOCK_STATUS");
|
||||
return -EINVAL;
|
||||
@@ -630,8 +640,15 @@ static int nbd_parse_blockstatus_payload(BDRVNBDState *s,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
extent->length = payload_advance32(&payload);
|
||||
extent->flags = payload_advance32(&payload);
|
||||
if (wide) {
|
||||
count = payload_advance32(&payload);
|
||||
extent->length = payload_advance64(&payload);
|
||||
extent->flags = payload_advance64(&payload);
|
||||
} else {
|
||||
count = 0;
|
||||
extent->length = payload_advance32(&payload);
|
||||
extent->flags = payload_advance32(&payload);
|
||||
}
|
||||
|
||||
if (extent->length == 0) {
|
||||
error_setg(errp, "Protocol error: server sent status chunk with "
|
||||
@@ -652,7 +669,7 @@ static int nbd_parse_blockstatus_payload(BDRVNBDState *s,
|
||||
* (always a safe status, even if it loses information).
|
||||
*/
|
||||
if (s->info.min_block && !QEMU_IS_ALIGNED(extent->length,
|
||||
s->info.min_block)) {
|
||||
s->info.min_block)) {
|
||||
trace_nbd_parse_blockstatus_compliance("extent length is unaligned");
|
||||
if (extent->length > s->info.min_block) {
|
||||
extent->length = QEMU_ALIGN_DOWN(extent->length,
|
||||
@@ -666,13 +683,15 @@ static int nbd_parse_blockstatus_payload(BDRVNBDState *s,
|
||||
/*
|
||||
* We used NBD_CMD_FLAG_REQ_ONE, so the server should not have
|
||||
* sent us any more than one extent, nor should it have included
|
||||
* status beyond our request in that extent. However, it's easy
|
||||
* enough to ignore the server's noncompliance without killing the
|
||||
* status beyond our request in that extent. Furthermore, a wide
|
||||
* server should have replied with an accurate count (we left
|
||||
* count at 0 for a narrow server). However, it's easy enough to
|
||||
* ignore the server's noncompliance without killing the
|
||||
* connection; just ignore trailing extents, and clamp things to
|
||||
* the length of our request.
|
||||
*/
|
||||
if (chunk->length > sizeof(context_id) + sizeof(*extent)) {
|
||||
trace_nbd_parse_blockstatus_compliance("more than one extent");
|
||||
if (count != wide || chunk->length > pay_len) {
|
||||
trace_nbd_parse_blockstatus_compliance("unexpected extent count");
|
||||
}
|
||||
if (extent->length > orig_length) {
|
||||
extent->length = orig_length;
|
||||
@@ -842,9 +861,9 @@ static coroutine_fn int nbd_co_do_receive_one_chunk(
|
||||
}
|
||||
*request_ret = 0;
|
||||
|
||||
ret = nbd_receive_replies(s, cookie);
|
||||
ret = nbd_receive_replies(s, cookie, errp);
|
||||
if (ret < 0) {
|
||||
error_setg(errp, "Connection closed");
|
||||
error_prepend(errp, "Connection closed: ");
|
||||
return -EIO;
|
||||
}
|
||||
assert(s->ioc);
|
||||
@@ -1118,7 +1137,7 @@ nbd_co_receive_cmdread_reply(BDRVNBDState *s, uint64_t cookie,
|
||||
|
||||
static int coroutine_fn
|
||||
nbd_co_receive_blockstatus_reply(BDRVNBDState *s, uint64_t cookie,
|
||||
uint64_t length, NBDExtent32 *extent,
|
||||
uint64_t length, NBDExtent64 *extent,
|
||||
int *request_ret, Error **errp)
|
||||
{
|
||||
NBDReplyChunkIter iter;
|
||||
@@ -1131,11 +1150,17 @@ nbd_co_receive_blockstatus_reply(BDRVNBDState *s, uint64_t cookie,
|
||||
NBD_FOREACH_REPLY_CHUNK(s, iter, cookie, false, NULL, &reply, &payload) {
|
||||
int ret;
|
||||
NBDStructuredReplyChunk *chunk = &reply.structured;
|
||||
bool wide;
|
||||
|
||||
assert(nbd_reply_is_structured(&reply));
|
||||
|
||||
switch (chunk->type) {
|
||||
case NBD_REPLY_TYPE_BLOCK_STATUS_EXT:
|
||||
case NBD_REPLY_TYPE_BLOCK_STATUS:
|
||||
wide = chunk->type == NBD_REPLY_TYPE_BLOCK_STATUS_EXT;
|
||||
if ((s->info.mode >= NBD_MODE_EXTENDED) != wide) {
|
||||
trace_nbd_extended_headers_compliance("block_status");
|
||||
}
|
||||
if (received) {
|
||||
nbd_channel_error(s, -EINVAL);
|
||||
error_setg(&local_err, "Several BLOCK_STATUS chunks in reply");
|
||||
@@ -1143,9 +1168,9 @@ nbd_co_receive_blockstatus_reply(BDRVNBDState *s, uint64_t cookie,
|
||||
}
|
||||
received = true;
|
||||
|
||||
ret = nbd_parse_blockstatus_payload(s, &reply.structured,
|
||||
payload, length, extent,
|
||||
&local_err);
|
||||
ret = nbd_parse_blockstatus_payload(
|
||||
s, &reply.structured, payload, wide,
|
||||
length, extent, &local_err);
|
||||
if (ret < 0) {
|
||||
nbd_channel_error(s, ret);
|
||||
nbd_iter_channel_error(&iter, ret, &local_err);
|
||||
@@ -1375,7 +1400,7 @@ static int coroutine_fn GRAPH_RDLOCK nbd_client_co_block_status(
|
||||
int64_t *pnum, int64_t *map, BlockDriverState **file)
|
||||
{
|
||||
int ret, request_ret;
|
||||
NBDExtent32 extent = { 0 };
|
||||
NBDExtent64 extent = { 0 };
|
||||
BDRVNBDState *s = (BDRVNBDState *)bs->opaque;
|
||||
Error *local_err = NULL;
|
||||
|
||||
|
||||
@@ -166,6 +166,7 @@ iscsi_xcopy(void *src_lun, uint64_t src_off, void *dst_lun, uint64_t dst_off, ui
|
||||
# nbd.c
|
||||
nbd_parse_blockstatus_compliance(const char *err) "ignoring extra data from non-compliant server: %s"
|
||||
nbd_structured_read_compliance(const char *type) "server sent non-compliant unaligned read %s chunk"
|
||||
nbd_extended_headers_compliance(const char *type) "server sent non-compliant %s chunk not matching choice of extended headers"
|
||||
nbd_read_reply_entry_fail(int ret, const char *err) "ret = %d, err: %s"
|
||||
nbd_co_request_fail(uint64_t from, uint64_t len, uint64_t handle, uint16_t flags, uint16_t type, const char *name, int ret, const char *err) "Request failed { .from = %" PRIu64", .len = %" PRIu64 ", .handle = %" PRIu64 ", .flags = 0x%" PRIx16 ", .type = %" PRIu16 " (%s) } ret = %d, err: %s"
|
||||
nbd_client_handshake(const char *export_name) "export '%s'"
|
||||
|
||||
@@ -69,3 +69,4 @@ NBD_CMD_BLOCK_STATUS for "qemu:dirty-bitmap:", NBD_CMD_CACHE
|
||||
NBD_CMD_FLAG_FAST_ZERO
|
||||
* 5.2: NBD_CMD_BLOCK_STATUS for "qemu:allocation-depth"
|
||||
* 7.1: NBD_FLAG_CAN_MULTI_CONN for shareable writable exports
|
||||
* 8.2: NBD_OPT_EXTENDED_HEADERS, NBD_FLAG_BLOCK_STATUS_PAYLOAD
|
||||
|
||||
+4
-1
@@ -29,6 +29,7 @@
|
||||
typedef struct NBDExport NBDExport;
|
||||
typedef struct NBDClient NBDClient;
|
||||
typedef struct NBDClientConnection NBDClientConnection;
|
||||
typedef struct NBDMetaContexts NBDMetaContexts;
|
||||
|
||||
extern const BlockExportDriver blk_exp_nbd;
|
||||
|
||||
@@ -76,6 +77,7 @@ typedef struct NBDRequest {
|
||||
uint16_t flags; /* NBD_CMD_FLAG_* */
|
||||
uint16_t type; /* NBD_CMD_* */
|
||||
NBDMode mode; /* Determines which network representation to use */
|
||||
NBDMetaContexts *contexts; /* Used by NBD_CMD_BLOCK_STATUS */
|
||||
} NBDRequest;
|
||||
|
||||
typedef struct NBDSimpleReply {
|
||||
@@ -389,7 +391,8 @@ int nbd_init(int fd, QIOChannelSocket *sioc, NBDExportInfo *info,
|
||||
Error **errp);
|
||||
int nbd_send_request(QIOChannel *ioc, NBDRequest *request);
|
||||
int coroutine_fn nbd_receive_reply(BlockDriverState *bs, QIOChannel *ioc,
|
||||
NBDReply *reply, Error **errp);
|
||||
NBDReply *reply, NBDMode mode,
|
||||
Error **errp);
|
||||
int nbd_client(int fd);
|
||||
int nbd_disconnect(int fd);
|
||||
int nbd_errno_to_system_errno(int err);
|
||||
|
||||
@@ -93,7 +93,7 @@ NBDClientConnection *nbd_client_connection_new(const SocketAddress *saddr,
|
||||
.do_negotiation = do_negotiation,
|
||||
|
||||
.initial_info.request_sizes = true,
|
||||
.initial_info.mode = NBD_MODE_STRUCTURED,
|
||||
.initial_info.mode = NBD_MODE_EXTENDED,
|
||||
.initial_info.base_allocation = true,
|
||||
.initial_info.x_dirty_bitmap = g_strdup(x_dirty_bitmap),
|
||||
.initial_info.name = g_strdup(export_name ?: "")
|
||||
|
||||
+84
-40
@@ -953,15 +953,23 @@ static int nbd_start_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
|
||||
if (fixedNewStyle) {
|
||||
int result = 0;
|
||||
|
||||
if (max_mode >= NBD_MODE_EXTENDED) {
|
||||
result = nbd_request_simple_option(ioc,
|
||||
NBD_OPT_EXTENDED_HEADERS,
|
||||
false, errp);
|
||||
if (result) {
|
||||
return result < 0 ? -EINVAL : NBD_MODE_EXTENDED;
|
||||
}
|
||||
}
|
||||
if (max_mode >= NBD_MODE_STRUCTURED) {
|
||||
result = nbd_request_simple_option(ioc,
|
||||
NBD_OPT_STRUCTURED_REPLY,
|
||||
false, errp);
|
||||
if (result < 0) {
|
||||
return -EINVAL;
|
||||
if (result) {
|
||||
return result < 0 ? -EINVAL : NBD_MODE_STRUCTURED;
|
||||
}
|
||||
}
|
||||
return result ? NBD_MODE_STRUCTURED : NBD_MODE_SIMPLE;
|
||||
return NBD_MODE_SIMPLE;
|
||||
} else {
|
||||
return NBD_MODE_EXPORT_NAME;
|
||||
}
|
||||
@@ -1034,6 +1042,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
|
||||
}
|
||||
|
||||
switch (info->mode) {
|
||||
case NBD_MODE_EXTENDED:
|
||||
case NBD_MODE_STRUCTURED:
|
||||
if (base_allocation) {
|
||||
result = nbd_negotiate_simple_meta_context(ioc, info, errp);
|
||||
@@ -1144,7 +1153,7 @@ int nbd_receive_export_list(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
|
||||
|
||||
*info = NULL;
|
||||
result = nbd_start_negotiate(ioc, tlscreds, hostname, &sioc,
|
||||
NBD_MODE_STRUCTURED, NULL, errp);
|
||||
NBD_MODE_EXTENDED, NULL, errp);
|
||||
if (tlscreds && sioc) {
|
||||
ioc = sioc;
|
||||
}
|
||||
@@ -1155,6 +1164,7 @@ int nbd_receive_export_list(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
|
||||
switch ((NBDMode)result) {
|
||||
case NBD_MODE_SIMPLE:
|
||||
case NBD_MODE_STRUCTURED:
|
||||
case NBD_MODE_EXTENDED:
|
||||
/* newstyle - use NBD_OPT_LIST to populate array, then try
|
||||
* NBD_OPT_INFO on each array member. If structured replies
|
||||
* are enabled, also try NBD_OPT_LIST_META_CONTEXT. */
|
||||
@@ -1191,7 +1201,7 @@ int nbd_receive_export_list(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
|
||||
break;
|
||||
}
|
||||
|
||||
if (result == NBD_MODE_STRUCTURED &&
|
||||
if (result >= NBD_MODE_STRUCTURED &&
|
||||
nbd_list_meta_contexts(ioc, &array[i], errp) < 0) {
|
||||
goto out;
|
||||
}
|
||||
@@ -1346,22 +1356,29 @@ int nbd_disconnect(int fd)
|
||||
|
||||
int nbd_send_request(QIOChannel *ioc, NBDRequest *request)
|
||||
{
|
||||
uint8_t buf[NBD_REQUEST_SIZE];
|
||||
uint8_t buf[NBD_EXTENDED_REQUEST_SIZE];
|
||||
size_t len;
|
||||
|
||||
assert(request->mode <= NBD_MODE_STRUCTURED); /* TODO handle extended */
|
||||
assert(request->len <= UINT32_MAX);
|
||||
trace_nbd_send_request(request->from, request->len, request->cookie,
|
||||
request->flags, request->type,
|
||||
nbd_cmd_lookup(request->type));
|
||||
|
||||
stl_be_p(buf, NBD_REQUEST_MAGIC);
|
||||
stw_be_p(buf + 4, request->flags);
|
||||
stw_be_p(buf + 6, request->type);
|
||||
stq_be_p(buf + 8, request->cookie);
|
||||
stq_be_p(buf + 16, request->from);
|
||||
stl_be_p(buf + 24, request->len);
|
||||
if (request->mode >= NBD_MODE_EXTENDED) {
|
||||
stl_be_p(buf, NBD_EXTENDED_REQUEST_MAGIC);
|
||||
stq_be_p(buf + 24, request->len);
|
||||
len = NBD_EXTENDED_REQUEST_SIZE;
|
||||
} else {
|
||||
assert(request->len <= UINT32_MAX);
|
||||
stl_be_p(buf, NBD_REQUEST_MAGIC);
|
||||
stl_be_p(buf + 24, request->len);
|
||||
len = NBD_REQUEST_SIZE;
|
||||
}
|
||||
|
||||
return nbd_write(ioc, buf, sizeof(buf), NULL);
|
||||
return nbd_write(ioc, buf, len, NULL);
|
||||
}
|
||||
|
||||
/* nbd_receive_simple_reply
|
||||
@@ -1388,30 +1405,36 @@ static int nbd_receive_simple_reply(QIOChannel *ioc, NBDSimpleReply *reply,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* nbd_receive_structured_reply_chunk
|
||||
/* nbd_receive_reply_chunk_header
|
||||
* Read structured reply chunk except magic field (which should be already
|
||||
* read).
|
||||
* read). Normalize into the compact form.
|
||||
* Payload is not read.
|
||||
*/
|
||||
static int nbd_receive_structured_reply_chunk(QIOChannel *ioc,
|
||||
NBDStructuredReplyChunk *chunk,
|
||||
Error **errp)
|
||||
static int nbd_receive_reply_chunk_header(QIOChannel *ioc, NBDReply *chunk,
|
||||
Error **errp)
|
||||
{
|
||||
int ret;
|
||||
size_t len;
|
||||
uint64_t payload_len;
|
||||
|
||||
assert(chunk->magic == NBD_STRUCTURED_REPLY_MAGIC);
|
||||
if (chunk->magic == NBD_STRUCTURED_REPLY_MAGIC) {
|
||||
len = sizeof(chunk->structured);
|
||||
} else {
|
||||
assert(chunk->magic == NBD_EXTENDED_REPLY_MAGIC);
|
||||
len = sizeof(chunk->extended);
|
||||
}
|
||||
|
||||
ret = nbd_read(ioc, (uint8_t *)chunk + sizeof(chunk->magic),
|
||||
sizeof(*chunk) - sizeof(chunk->magic), "structured chunk",
|
||||
len - sizeof(chunk->magic), "structured chunk",
|
||||
errp);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
chunk->flags = be16_to_cpu(chunk->flags);
|
||||
chunk->type = be16_to_cpu(chunk->type);
|
||||
chunk->cookie = be64_to_cpu(chunk->cookie);
|
||||
chunk->length = be32_to_cpu(chunk->length);
|
||||
/* flags, type, and cookie occupy same space between forms */
|
||||
chunk->structured.flags = be16_to_cpu(chunk->structured.flags);
|
||||
chunk->structured.type = be16_to_cpu(chunk->structured.type);
|
||||
chunk->structured.cookie = be64_to_cpu(chunk->structured.cookie);
|
||||
|
||||
/*
|
||||
* Because we use BLOCK_STATUS with REQ_ONE, and cap READ requests
|
||||
@@ -1419,11 +1442,20 @@ static int nbd_receive_structured_reply_chunk(QIOChannel *ioc,
|
||||
* this. Even if we stopped using REQ_ONE, sane servers will cap
|
||||
* the number of extents they return for block status.
|
||||
*/
|
||||
if (chunk->length > NBD_MAX_BUFFER_SIZE + sizeof(NBDStructuredReadData)) {
|
||||
if (chunk->magic == NBD_STRUCTURED_REPLY_MAGIC) {
|
||||
payload_len = be32_to_cpu(chunk->structured.length);
|
||||
} else {
|
||||
/* For now, we are ignoring the extended header offset. */
|
||||
payload_len = be64_to_cpu(chunk->extended.length);
|
||||
chunk->magic = NBD_STRUCTURED_REPLY_MAGIC;
|
||||
}
|
||||
if (payload_len > NBD_MAX_BUFFER_SIZE + sizeof(NBDStructuredReadData)) {
|
||||
error_setg(errp, "server chunk %" PRIu32 " (%s) payload is too long",
|
||||
chunk->type, nbd_rep_lookup(chunk->type));
|
||||
chunk->structured.type,
|
||||
nbd_rep_lookup(chunk->structured.type));
|
||||
return -EINVAL;
|
||||
}
|
||||
chunk->structured.length = payload_len;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1470,19 +1502,21 @@ nbd_read_eof(BlockDriverState *bs, QIOChannel *ioc, void *buffer, size_t size,
|
||||
|
||||
/* nbd_receive_reply
|
||||
*
|
||||
* Decreases bs->in_flight while waiting for a new reply. This yield is where
|
||||
* we wait indefinitely and the coroutine must be able to be safely reentered
|
||||
* for nbd_client_attach_aio_context().
|
||||
* Wait for a new reply. If this yields, the coroutine must be able to be
|
||||
* safely reentered for nbd_client_attach_aio_context(). @mode determines
|
||||
* which reply magic we are expecting, although this normalizes the result
|
||||
* so that the caller only has to work with compact headers.
|
||||
*
|
||||
* Returns 1 on success
|
||||
* 0 on eof, when no data was read (errp is not set)
|
||||
* negative errno on failure (errp is set)
|
||||
* 0 on eof, when no data was read
|
||||
* negative errno on failure
|
||||
*/
|
||||
int coroutine_fn nbd_receive_reply(BlockDriverState *bs, QIOChannel *ioc,
|
||||
NBDReply *reply, Error **errp)
|
||||
NBDReply *reply, NBDMode mode, Error **errp)
|
||||
{
|
||||
int ret;
|
||||
const char *type;
|
||||
uint32_t expected;
|
||||
|
||||
ret = nbd_read_eof(bs, ioc, &reply->magic, sizeof(reply->magic), errp);
|
||||
if (ret <= 0) {
|
||||
@@ -1491,34 +1525,44 @@ int coroutine_fn nbd_receive_reply(BlockDriverState *bs, QIOChannel *ioc,
|
||||
|
||||
reply->magic = be32_to_cpu(reply->magic);
|
||||
|
||||
/* Diagnose but accept wrong-width header */
|
||||
switch (reply->magic) {
|
||||
case NBD_SIMPLE_REPLY_MAGIC:
|
||||
if (mode >= NBD_MODE_EXTENDED) {
|
||||
trace_nbd_receive_wrong_header(reply->magic,
|
||||
nbd_mode_lookup(mode));
|
||||
}
|
||||
ret = nbd_receive_simple_reply(ioc, &reply->simple, errp);
|
||||
if (ret < 0) {
|
||||
break;
|
||||
return ret;
|
||||
}
|
||||
trace_nbd_receive_simple_reply(reply->simple.error,
|
||||
nbd_err_lookup(reply->simple.error),
|
||||
reply->cookie);
|
||||
break;
|
||||
case NBD_STRUCTURED_REPLY_MAGIC:
|
||||
ret = nbd_receive_structured_reply_chunk(ioc, &reply->structured, errp);
|
||||
case NBD_EXTENDED_REPLY_MAGIC:
|
||||
expected = mode >= NBD_MODE_EXTENDED ? NBD_EXTENDED_REPLY_MAGIC
|
||||
: NBD_STRUCTURED_REPLY_MAGIC;
|
||||
if (reply->magic != expected) {
|
||||
trace_nbd_receive_wrong_header(reply->magic,
|
||||
nbd_mode_lookup(mode));
|
||||
}
|
||||
ret = nbd_receive_reply_chunk_header(ioc, reply, errp);
|
||||
if (ret < 0) {
|
||||
break;
|
||||
return ret;
|
||||
}
|
||||
type = nbd_reply_type_lookup(reply->structured.type);
|
||||
trace_nbd_receive_structured_reply_chunk(reply->structured.flags,
|
||||
reply->structured.type, type,
|
||||
reply->structured.cookie,
|
||||
reply->structured.length);
|
||||
trace_nbd_receive_reply_chunk_header(reply->structured.flags,
|
||||
reply->structured.type, type,
|
||||
reply->structured.cookie,
|
||||
reply->structured.length);
|
||||
break;
|
||||
default:
|
||||
trace_nbd_receive_wrong_header(reply->magic, nbd_mode_lookup(mode));
|
||||
error_setg(errp, "invalid magic (got 0x%" PRIx32 ")", reply->magic);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
+4
-1
@@ -34,8 +34,11 @@
|
||||
* https://github.com/yoe/nbd/blob/master/doc/proto.md
|
||||
*/
|
||||
|
||||
/* Size of all NBD_OPT_*, without payload */
|
||||
/* Size of all compact NBD_CMD_*, without payload */
|
||||
#define NBD_REQUEST_SIZE (4 + 2 + 2 + 8 + 8 + 4)
|
||||
/* Size of all extended NBD_CMD_*, without payload */
|
||||
#define NBD_EXTENDED_REQUEST_SIZE (4 + 2 + 2 + 8 + 8 + 8)
|
||||
|
||||
/* Size of all NBD_REP_* sent in answer to most NBD_OPT_*, without payload */
|
||||
#define NBD_REPLY_SIZE (4 + 4 + 8)
|
||||
/* Size of reply to NBD_OPT_EXPORT_NAME */
|
||||
|
||||
+342
-82
File diff suppressed because it is too large
Load Diff
+4
-1
@@ -33,7 +33,8 @@ nbd_client_clear_queue(void) "Clearing NBD queue"
|
||||
nbd_client_clear_socket(void) "Clearing NBD socket"
|
||||
nbd_send_request(uint64_t from, uint64_t len, uint64_t cookie, uint16_t flags, uint16_t type, const char *name) "Sending request to server: { .from = %" PRIu64", .len = %" PRIu64 ", .cookie = %" PRIu64 ", .flags = 0x%" PRIx16 ", .type = %" PRIu16 " (%s) }"
|
||||
nbd_receive_simple_reply(int32_t error, const char *errname, uint64_t cookie) "Got simple reply: { .error = %" PRId32 " (%s), cookie = %" PRIu64" }"
|
||||
nbd_receive_structured_reply_chunk(uint16_t flags, uint16_t type, const char *name, uint64_t cookie, uint32_t length) "Got structured reply chunk: { flags = 0x%" PRIx16 ", type = %d (%s), cookie = %" PRIu64 ", length = %" PRIu32 " }"
|
||||
nbd_receive_reply_chunk_header(uint16_t flags, uint16_t type, const char *name, uint64_t cookie, uint32_t length) "Got reply chunk header: { flags = 0x%" PRIx16 ", type = %" PRIu16 " (%s), cookie = %" PRIu64 ", length = %" PRIu32 " }"
|
||||
nbd_receive_wrong_header(uint32_t magic, const char *mode) "Server sent unexpected magic 0x%" PRIx32 " for negotiated mode %s"
|
||||
|
||||
# common.c
|
||||
nbd_unknown_error(int err) "Squashing unexpected error %d to EINVAL"
|
||||
@@ -69,8 +70,10 @@ nbd_co_send_chunk_read(uint64_t cookie, uint64_t offset, void *data, uint64_t si
|
||||
nbd_co_send_chunk_read_hole(uint64_t cookie, uint64_t offset, uint64_t size) "Send structured read hole reply: cookie = %" PRIu64 ", offset = %" PRIu64 ", len = %" PRIu64
|
||||
nbd_co_send_extents(uint64_t cookie, unsigned int extents, uint32_t id, uint64_t length, int last) "Send block status reply: cookie = %" PRIu64 ", extents = %u, context = %d (extents cover %" PRIu64 " bytes, last chunk = %d)"
|
||||
nbd_co_send_chunk_error(uint64_t cookie, int err, const char *errname, const char *msg) "Send structured error reply: cookie = %" PRIu64 ", error = %d (%s), msg = '%s'"
|
||||
nbd_co_receive_block_status_payload_compliance(uint64_t from, uint64_t len) "client sent unusable block status payload: from=0x%" PRIx64 ", len=0x%" PRIx64
|
||||
nbd_co_receive_request_decode_type(uint64_t cookie, uint16_t type, const char *name) "Decoding type: cookie = %" PRIu64 ", type = %" PRIu16 " (%s)"
|
||||
nbd_co_receive_request_payload_received(uint64_t cookie, uint64_t len) "Payload received: cookie = %" PRIu64 ", len = %" PRIu64
|
||||
nbd_co_receive_ext_payload_compliance(uint64_t from, uint64_t len) "client sent non-compliant write without payload flag: from=0x%" PRIx64 ", len=0x%" PRIx64
|
||||
nbd_co_receive_align_compliance(const char *op, uint64_t from, uint64_t len, uint32_t align) "client sent non-compliant unaligned %s request: from=0x%" PRIx64 ", len=0x%" PRIx64 ", align=0x%" PRIx32
|
||||
nbd_trip(void) "Reading request"
|
||||
|
||||
|
||||
@@ -219,6 +219,7 @@ static int qemu_nbd_client_list(SocketAddress *saddr, QCryptoTLSCreds *tls,
|
||||
[NBD_FLAG_SEND_RESIZE_BIT] = "resize",
|
||||
[NBD_FLAG_SEND_CACHE_BIT] = "cache",
|
||||
[NBD_FLAG_SEND_FAST_ZERO_BIT] = "fast-zero",
|
||||
[NBD_FLAG_BLOCK_STAT_PAYLOAD_BIT] = "block-status-payload",
|
||||
};
|
||||
|
||||
printf(" size: %" PRIu64 "\n", list[i].size);
|
||||
@@ -235,6 +236,9 @@ static int qemu_nbd_client_list(SocketAddress *saddr, QCryptoTLSCreds *tls,
|
||||
printf(" opt block: %u\n", list[i].opt_block);
|
||||
printf(" max block: %u\n", list[i].max_block);
|
||||
}
|
||||
printf(" transaction size: %s\n",
|
||||
list[i].mode >= NBD_MODE_EXTENDED ?
|
||||
"64-bit" : "32-bit");
|
||||
if (list[i].n_contexts) {
|
||||
printf(" available meta contexts: %d\n", list[i].n_contexts);
|
||||
for (j = 0; j < list[i].n_contexts; j++) {
|
||||
|
||||
@@ -83,29 +83,32 @@ exports available: 0
|
||||
exports available: 3
|
||||
export: 'n'
|
||||
size: 4194304
|
||||
flags: 0x58f ( readonly flush fua df multi cache )
|
||||
flags: 0x158f ( readonly flush fua df multi cache block-status-payload )
|
||||
min block: 1
|
||||
opt block: 4096
|
||||
max block: 33554432
|
||||
transaction size: 64-bit
|
||||
available meta contexts: 2
|
||||
base:allocation
|
||||
qemu:dirty-bitmap:b
|
||||
export: 'n2'
|
||||
description: some text
|
||||
size: 4194304
|
||||
flags: 0xded ( flush fua trim zeroes df multi cache fast-zero )
|
||||
flags: 0x1ded ( flush fua trim zeroes df multi cache fast-zero block-status-payload )
|
||||
min block: 1
|
||||
opt block: 4096
|
||||
max block: 33554432
|
||||
transaction size: 64-bit
|
||||
available meta contexts: 2
|
||||
base:allocation
|
||||
qemu:dirty-bitmap:b2
|
||||
export: 'n3'
|
||||
size: 4194304
|
||||
flags: 0x58f ( readonly flush fua df multi cache )
|
||||
flags: 0x158f ( readonly flush fua df multi cache block-status-payload )
|
||||
min block: 1
|
||||
opt block: 4096
|
||||
max block: 33554432
|
||||
transaction size: 64-bit
|
||||
available meta contexts: 2
|
||||
base:allocation
|
||||
qemu:dirty-bitmap:b3
|
||||
@@ -202,29 +205,32 @@ exports available: 0
|
||||
exports available: 3
|
||||
export: 'n'
|
||||
size: 4194304
|
||||
flags: 0x58f ( readonly flush fua df multi cache )
|
||||
flags: 0x158f ( readonly flush fua df multi cache block-status-payload )
|
||||
min block: 1
|
||||
opt block: 4096
|
||||
max block: 33554432
|
||||
transaction size: 64-bit
|
||||
available meta contexts: 2
|
||||
base:allocation
|
||||
qemu:dirty-bitmap:b
|
||||
export: 'n2'
|
||||
description: some text
|
||||
size: 4194304
|
||||
flags: 0xded ( flush fua trim zeroes df multi cache fast-zero )
|
||||
flags: 0x1ded ( flush fua trim zeroes df multi cache fast-zero block-status-payload )
|
||||
min block: 1
|
||||
opt block: 4096
|
||||
max block: 33554432
|
||||
transaction size: 64-bit
|
||||
available meta contexts: 2
|
||||
base:allocation
|
||||
qemu:dirty-bitmap:b2
|
||||
export: 'n3'
|
||||
size: 4194304
|
||||
flags: 0x58f ( readonly flush fua df multi cache )
|
||||
flags: 0x158f ( readonly flush fua df multi cache block-status-payload )
|
||||
min block: 1
|
||||
opt block: 4096
|
||||
max block: 33554432
|
||||
transaction size: 64-bit
|
||||
available meta contexts: 2
|
||||
base:allocation
|
||||
qemu:dirty-bitmap:b3
|
||||
|
||||
@@ -39,6 +39,7 @@ exports available: 1
|
||||
export: ''
|
||||
size: 67108864
|
||||
min block: 1
|
||||
transaction size: 64-bit
|
||||
|
||||
== check TLS fail over TCP with mismatched hostname ==
|
||||
qemu-img: Could not open 'driver=nbd,host=localhost,port=PORT,tls-creds=tls0': Certificate does not match the hostname localhost
|
||||
@@ -53,6 +54,7 @@ exports available: 1
|
||||
export: ''
|
||||
size: 67108864
|
||||
min block: 1
|
||||
transaction size: 64-bit
|
||||
|
||||
== check TLS with different CA fails ==
|
||||
qemu-img: Could not open 'driver=nbd,host=127.0.0.1,port=PORT,tls-creds=tls0': The certificate hasn't got a known issuer
|
||||
@@ -83,6 +85,7 @@ exports available: 1
|
||||
export: ''
|
||||
size: 67108864
|
||||
min block: 1
|
||||
transaction size: 64-bit
|
||||
|
||||
== check TLS works over UNIX with PSK ==
|
||||
image: nbd+unix://?socket=SOCK_DIR/qemu-nbd.sock
|
||||
@@ -93,6 +96,7 @@ exports available: 1
|
||||
export: ''
|
||||
size: 67108864
|
||||
min block: 1
|
||||
transaction size: 64-bit
|
||||
|
||||
== check TLS fails over UNIX with mismatch PSK ==
|
||||
qemu-img: Could not open 'driver=nbd,path=SOCK_DIR/qemu-nbd.sock,tls-creds=tls0': TLS handshake failed: The TLS connection was non-properly terminated.
|
||||
|
||||
@@ -6,6 +6,7 @@ exports available: 1
|
||||
export: ''
|
||||
size: 1024
|
||||
min block: 1
|
||||
transaction size: 64-bit
|
||||
[{ "start": 0, "length": 1000, "depth": 0, "present": true, "zero": false, "data": true, "compressed": false, "offset": OFFSET},
|
||||
{ "start": 1000, "length": 24, "depth": 0, "present": true, "zero": true, "data": false, "compressed": false, "offset": OFFSET}]
|
||||
1 KiB (0x400) bytes allocated at offset 0 bytes (0x0)
|
||||
@@ -16,6 +17,7 @@ exports available: 1
|
||||
export: ''
|
||||
size: 1024
|
||||
min block: 512
|
||||
transaction size: 64-bit
|
||||
[{ "start": 0, "length": 1024, "depth": 0, "present": true, "zero": false, "data": true, "compressed": false, "offset": OFFSET}]
|
||||
1 KiB (0x400) bytes allocated at offset 0 bytes (0x0)
|
||||
WARNING: Image format was not specified for 'TEST_DIR/t.raw' and probing guessed raw.
|
||||
@@ -28,6 +30,7 @@ exports available: 1
|
||||
export: ''
|
||||
size: 1024
|
||||
min block: 1
|
||||
transaction size: 64-bit
|
||||
[{ "start": 0, "length": 1000, "depth": 0, "present": true, "zero": false, "data": true, "compressed": false, "offset": OFFSET},
|
||||
{ "start": 1000, "length": 24, "depth": 0, "present": true, "zero": true, "data": false, "compressed": false, "offset": OFFSET}]
|
||||
1 KiB (0x400) bytes allocated at offset 0 bytes (0x0)
|
||||
|
||||
@@ -15,10 +15,11 @@ wrote 4096/4096 bytes at offset 0
|
||||
exports available: 1
|
||||
export: 'fmt'
|
||||
size: 67108864
|
||||
flags: 0x58f ( readonly flush fua df multi cache )
|
||||
flags: 0x158f ( readonly flush fua df multi cache block-status-payload )
|
||||
min block: XXX
|
||||
opt block: XXX
|
||||
max block: XXX
|
||||
transaction size: 64-bit
|
||||
available meta contexts: 1
|
||||
base:allocation
|
||||
|
||||
@@ -43,10 +44,11 @@ exports available: 1
|
||||
exports available: 1
|
||||
export: 'fmt'
|
||||
size: 67108864
|
||||
flags: 0x58f ( readonly flush fua df multi cache )
|
||||
flags: 0x158f ( readonly flush fua df multi cache block-status-payload )
|
||||
min block: XXX
|
||||
opt block: XXX
|
||||
max block: XXX
|
||||
transaction size: 64-bit
|
||||
available meta contexts: 1
|
||||
base:allocation
|
||||
|
||||
@@ -74,19 +76,21 @@ exports available: 1
|
||||
exports available: 2
|
||||
export: 'fmt'
|
||||
size: 67108864
|
||||
flags: 0x58f ( readonly flush fua df multi cache )
|
||||
flags: 0x158f ( readonly flush fua df multi cache block-status-payload )
|
||||
min block: XXX
|
||||
opt block: XXX
|
||||
max block: XXX
|
||||
transaction size: 64-bit
|
||||
available meta contexts: 1
|
||||
base:allocation
|
||||
export: 'export1'
|
||||
description: This is the writable second export
|
||||
size: 67108864
|
||||
flags: 0xded ( flush fua trim zeroes df multi cache fast-zero )
|
||||
flags: 0x1ded ( flush fua trim zeroes df multi cache fast-zero block-status-payload )
|
||||
min block: XXX
|
||||
opt block: XXX
|
||||
max block: XXX
|
||||
transaction size: 64-bit
|
||||
available meta contexts: 1
|
||||
base:allocation
|
||||
|
||||
@@ -109,10 +113,11 @@ exports available: 1
|
||||
export: 'export1'
|
||||
description: This is the writable second export
|
||||
size: 67108864
|
||||
flags: 0xded ( flush fua trim zeroes df multi cache fast-zero )
|
||||
flags: 0x1ded ( flush fua trim zeroes df multi cache fast-zero block-status-payload )
|
||||
min block: XXX
|
||||
opt block: XXX
|
||||
max block: XXX
|
||||
transaction size: 64-bit
|
||||
available meta contexts: 1
|
||||
base:allocation
|
||||
|
||||
|
||||
@@ -17,10 +17,11 @@ wrote 2097152/2097152 bytes at offset 1048576
|
||||
exports available: 1
|
||||
export: ''
|
||||
size: 4194304
|
||||
flags: 0x48f ( readonly flush fua df cache )
|
||||
flags: 0x148f ( readonly flush fua df cache block-status-payload )
|
||||
min block: 1
|
||||
opt block: 4096
|
||||
max block: 33554432
|
||||
transaction size: 64-bit
|
||||
available meta contexts: 2
|
||||
base:allocation
|
||||
qemu:allocation-depth
|
||||
|
||||
Reference in New Issue
Block a user