Re: [Libguestfs] [libnbd PATCH v3 01/22] block_status: Refactor array storage

2023-05-25 Thread Laszlo Ersek
On 5/25/23 15:00, Eric Blake wrote: > For 32-bit block status, we were able to cheat and use an array with > an odd number of elements, with array[0] holding the context id, and > passing [1] to the user's callback. But once we have 64-bit > extents, we can no longer abuse array element 0 like

[Libguestfs] [libnbd PATCH v3 10/22] api: Add [aio_]nbd_block_status_64

2023-05-25 Thread Eric Blake
Overcome the inherent 32-bit limitation of our existing nbd_block_status command by adding a 64-bit variant. The command sent to the server does not change, but the user's callback is now handed 64-bit information regardless of whether the server replies with 32- or 64-bit extents. Unit tests

[Libguestfs] [libnbd PATCH v3 21/22] api: Add nbd_can_block_status_payload()

2023-05-25 Thread Eric Blake
In the recent NBD protocol extensions to add 64-bit commands [1], an additional option was added to allow NBD_CMD_BLOCK_STATUS pass a client payload instructing the server to filter its answers in nbd.git commit e6f3b94a (mainly useful when the client requests more than one meta context with

[Libguestfs] [libnbd PATCH v3 18/22] generator: Actually request extended headers

2023-05-25 Thread Eric Blake
This is the culmination of the previous patches' preparation work for using extended headers when possible. The new states in the state machine are copied extensively from our handling of OPT_STRUCTURED_REPLY. The next patch will then expose a new API nbd_opt_extended_headers() for manual

[Libguestfs] [libnbd PATCH v3 16/22] examples: Update copy-libev to use 64-bit block status

2023-05-25 Thread Eric Blake
Although our use of "base:allocation" doesn't require the use of the 64-bit API for flags, we might perform slightly faster for a server that does give us 64-bit extent lengths and honors larger nbd_zero lengths. Signed-off-by: Eric Blake --- examples/copy-libev.c | 21 ++--- 1

[Libguestfs] [libnbd PATCH v3 05/22] states: Prepare to receive 64-bit replies

2023-05-25 Thread Eric Blake
Support receiving headers for 64-bit replies if extended headers were negotiated. We already insist that the server not send us too much payload in one reply, so we can exploit that and merge the 64-bit length back into a normalized 32-bit field for the rest of the payload length calculations.

[Libguestfs] [libnbd PATCH v3 01/22] block_status: Refactor array storage

2023-05-25 Thread Eric Blake
For 32-bit block status, we were able to cheat and use an array with an odd number of elements, with array[0] holding the context id, and passing [1] to the user's callback. But once we have 64-bit extents, we can no longer abuse array element 0 like that, for two reasons: 64-bit extents contain

[Libguestfs] [libnbd PATCH v3 04/22] states: Prepare to send 64-bit requests

2023-05-25 Thread Eric Blake
Support sending 64-bit requests if extended headers were negotiated. This includes setting NBD_CMD_FLAG_PAYLOAD_LEN any time we send an extended NBD_CMD_WRITE; this is such a fundamental part of the protocol that for now it is easier to silently ignore whatever value the user passes in for that

[Libguestfs] [libnbd PATCH v3 06/22] states: Break deadlock if server goofs on extended replies

2023-05-25 Thread Eric Blake
One of the benefits of extended replies is that we can do a fixed-length read for the entire header of every server reply, which is fewer syscalls than the split-read approach required by structured replies. But one of the drawbacks of doing a large read is that if the server is non-compliant

[Libguestfs] [libnbd PATCH v3 14/22] info: Expose extended-headers support through nbdinfo

2023-05-25 Thread Eric Blake
Add another bit of overall server information, as well as a '--can extended-headers' silent query. For now, the testsuite is written assuming that when nbdkit finally adds extended headers support, it will also add a --no-eh kill switch comparable to its existing --no-sr switch. Signed-off-by:

[Libguestfs] [libnbd PATCH v3 07/22] generator: Add struct nbd_extent in prep for 64-bit extents

2023-05-25 Thread Eric Blake
The existing nbd_block_status() callback is permanently stuck with an array of uint32_t pairs (len/2 extents), which is both constrained on maximum extent size (no larger than 4G) and on the status flags (must fit in 32 bits). While the "base:allocation" metacontext will never exceed 32 bits, it

[Libguestfs] [libnbd PATCH v3 09/22] block_status: Accept 64-bit extents during block status

2023-05-25 Thread Eric Blake
Support a server giving us a 64-bit extent. Note that the protocol says a server should not give a 64-bit answer when extended headers are not negotiated; we can handle that by reporting EPROTO but otherwise accepting the information. Conversely, when extended headers are in effect, the server

[Libguestfs] [libnbd PATCH v3 02/22] internal: Refactor layout of replies in sbuf

2023-05-25 Thread Eric Blake
In order to more easily add a third reply type with an even larger header, but where the payload will look the same for both structured and extended replies, it is nicer if simple and structured replies are nested inside the same layer of sbuf.reply.hdr. While at it, note that while .or and .sr

[Libguestfs] [libnbd PATCH v3 22/22] api: Add nbd_[aio_]block_status_filter()

2023-05-25 Thread Eric Blake
As part of extending NBD to support 64-bit lengths, the protocol also added an option for servers to allow clients to request filtered responses to NBD_CMD_BLOCK_STATUS when more than one meta-context is negotiated (see NBD commit e6f3b94a). At the same time as this patch, qemu-nbd was taught to

[Libguestfs] [libnbd PATCH v3 08/22] block_status: Track 64-bit extents internally

2023-05-25 Thread Eric Blake
When extended headers are in use, the server is required to use a response that can include 64-bit extent lengths and flags (even if it chooses to keep the extent length under 4G, and even for metacontexts like "base:allocation" where the flags never need more than 32 bits). For maximum

[Libguestfs] [libnbd PATCH v3 00/22] NBD 64-bit extensions (libnbd portion)

2023-05-25 Thread Eric Blake
v2 was here: https://listman.redhat.com/archives/libguestfs/2022-November/030292.html For v3, there are now approved specs to code to: https://listman.redhat.com/archives/libguestfs/2023-April/031251.html visible on an upstream branch at

[Libguestfs] [libnbd PATCH v3 03/22] protocol: Add definitions for extended headers

2023-05-25 Thread Eric Blake
Add the magic numbers and new structs necessary to implement the NBD protocol extension of extended headers providing 64-bit lengths. This corresponds to upstream nbd commits 36abf47d and a9384e2f on the extension-ext-header branch[1] (commit e6f3b94a for NBD_FLAG_BLOCK_STATUS_PAYLOAD is saved

[Libguestfs] [libnbd PATCH v3 11/22] api: Add several functions for controlling extended headers

2023-05-25 Thread Eric Blake
The new NBD_OPT_EXTENDED_HEADERS feature is worth using by default, but there may be cases where the user explicitly wants to stick with the older 32-bit headers. nbd_set_request_extended_headers() will let the client override the default, nbd_get_request_extended_headers() determines the current

[Libguestfs] [libnbd PATCH v3 17/22] ocaml: Add example for 64-bit extents

2023-05-25 Thread Eric Blake
Since our example program for 32-bit extents is inherently limited to 32-bit lengths, it is also worth demonstrating the 64-bit extent API, including the difference in the array indexing being saner. Signed-off-by: Eric Blake --- ocaml/examples/Makefile.am | 1 + ocaml/examples/extents64.ml |

[Libguestfs] [libnbd PATCH v3 13/22] dump: Update nbddump to use 64-bit block status

2023-05-25 Thread Eric Blake
Although our use of "base:allocation" doesn't require the use of the 64-bit API for flags, we might perform slightly faster for a server that does give us 64-bit extent lengths. Signed-off-by: Eric Blake --- dump/dump.c | 27 ++- 1 file changed, 14 insertions(+), 13

[Libguestfs] [libnbd PATCH v3 12/22] copy: Update nbdcopy to use 64-bit block status

2023-05-25 Thread Eric Blake
Although our use of "base:allocation" doesn't require the use of the 64-bit API for flags, we might perform slightly faster for a server that does give us 64-bit extent lengths and honors larger nbd_zero lengths. Signed-off-by: Eric Blake --- copy/nbd-ops.c | 22 +++--- 1 file

[Libguestfs] [libnbd PATCH v3 19/22] api: Add nbd_[aio_]opt_extended_headers()

2023-05-25 Thread Eric Blake
Very similar to the recent addition of nbd_opt_structured_reply, giving us fine-grained control over an extended headers request. Because nbdkit does not yet support extended headers, testsuite coverage is limited to interop testing with qemu-nbd. It shows that extended headers imply structured

[Libguestfs] [libnbd PATCH v3 20/22] interop: Add test of 64-bit block status

2023-05-25 Thread Eric Blake
Prove that we can round-trip a block status request larger than 4G through a new-enough qemu-nbd. Also serves as a unit test of our shim for converting internal 64-bit representation back to the older 32-bit nbd_block_status callback interface. Signed-off-by: Eric Blake --- interop/Makefile.am

[Libguestfs] [libnbd PATCH v3 15/22] info: Update nbdinfo --map to use 64-bit block status

2023-05-25 Thread Eric Blake
Although we usually map "base:allocation" which doesn't require the use of the 64-bit API for flags, this application IS intended to map out other metacontexts that might have 64-bit flags. And when extended headers are in use, we might as well ask for the server to give us extents as large as it