nbd/server: Add FLAG_PAYLOAD support to CMD_BLOCK_STATUSexthdr-v5
commitf31190bda65e92633aa636029c7fe06fbd49079b
authorEric Blake <eblake@redhat.com>
Mon, 7 Aug 2023 21:01:14 +0000 (7 16:01 -0500)
committerEric Blake <eblake@redhat.com>
Thu, 10 Aug 2023 14:44:02 +0000 (10 09:44 -0500)
treebec028006151506ec99c7086ab4cfd1c32f12d79
parentcd34820ff0db2bc0896576ec2cd9ca1caabc3ba0
nbd/server: Add FLAG_PAYLOAD support to CMD_BLOCK_STATUS

Allow a client to request a subset of negotiated meta contexts.  For
example, a client may ask to use a single connection to learn about
both block status and dirty bitmaps, but where the dirty bitmap
queries only need to be performed on a subset of the disk; forcing the
server to compute that information on block status queries in the rest
of the disk is wasted effort (both at the server, and on the amount of
traffic sent over the wire to be parsed and ignored by the client).

Qemu as an NBD client never requests to use more than one meta
context, so it has no need to use block status payloads.  Testing this
instead requires support from libnbd, which CAN access multiple meta
contexts in parallel from a single NBD connection; an interop test
submitted to the libnbd project at the same time as this patch
demonstrates the feature working, as well as testing some corner cases
(for example, when the payload length is longer than the export
length), although other corner cases (like passing the same id
duplicated) requires a protocol fuzzer because libnbd is not wired up
to break the protocol that badly.

This also includes tweaks to 'qemu-nbd --list' to show when a server
is advertising the capability, and to the testsuite to reflect the
addition to that output.

Of note: qemu will always advertise the new feature bit during
NBD_OPT_INFO if extended headers have alreay been negotiated
(regardless of whether any NBD_OPT_SET_META_CONTEXT negotiation has
occurred); but for NBD_OPT_GO, qemu only advertises the feature if
block status is also enabled (that is, if the client does not
negotiate any contexts, then NBD_CMD_BLOCK_STATUS cannot be used, so
the feature is not advertised).

Signed-off-by: Eric Blake <eblake@redhat.com>
---

v5: factor out 'id - NBD_MTA_ID_DIRTY_BITMAP' [Vladimir], rework logic
on zero-length requests to be clearer [Vladimir], rebase to earlier
changes
docs/interop/nbd.txt
nbd/server.c
nbd/trace-events
qemu-nbd.c
tests/qemu-iotests/223.out
tests/qemu-iotests/307.out
tests/qemu-iotests/tests/nbd-qemu-allocation.out