[Qemu-block] [PATCH v3 11/19] nbd/client: Split out nbd_receive_one_meta_context()

2019-01-12 Thread Eric Blake
Extract portions of nbd_negotiate_simple_meta_context() to a new function nbd_receive_one_meta_context() that copies the pattern of nbd_receive_list() for performing the argument validation of one reply. The error message when the server replies with more than one context changes slightly, but

[Qemu-block] [PATCH v3 18/19] nbd/client: Work around 3.0 bug for listing meta contexts

2019-01-12 Thread Eric Blake
Commit 3d068aff forgot to advertise available qemu: contexts when the client requests a list with 0 queries. Furthermore, 3.0 shipped with a qemu-img hack of x-dirty-bitmap (commit 216ee365) that _silently_ acts as though the entire image is clean if a requested bitmap is not present. Both bugs

[Qemu-block] [PATCH v3 03/19] qemu-nbd: Sanity check partition bounds

2019-01-12 Thread Eric Blake
When the user requests a partition, we were using data read from the disk as disk offsets without a bounds check. We got lucky that even when computed offsets are out-of-bounds, blk_pread() will gracefully catch the error later (so I don't think a malicious image can crash or exploit qemu-nbd, and

[Qemu-block] [PATCH v3 02/19] qemu-nbd: Enhance man page

2019-01-12 Thread Eric Blake
Document some useful qemu-nbd command lines. Mention some restrictions on particular options, like -p being only for MBR images, or -c/-d being Linux-only. Update some text given the recent change to no longer serve oldstyle protocol (missed in commit 7f7dfe2a). Also, consistently use trailing

[Qemu-block] [PATCH v3 17/19] qemu-nbd: Add --list option

2019-01-12 Thread Eric Blake
We want to be able to detect whether a given qemu NBD server is exposing the right export(s) and dirty bitmaps, at least for regression testing. We could use 'nbd-client -l' from the upstream NBD project to list exports, but it's annoying to rely on out-of-tree binaries; furthermore, nbd-client

[Qemu-block] [PATCH v3 10/19] nbd/client: Split out nbd_send_one_meta_context()

2019-01-12 Thread Eric Blake
Refactor nbd_negotiate_simple_meta_context() to pull out the code that can be reused to send a LIST request for 0 or 1 query. No semantic change. The old comment about 'sizeof(uint32_t)' being equivalent to '/* number of queries */' is no longer needed, now that we are computing 'sizeof(queries)'

[Qemu-block] [PATCH v3 05/19] nbd/server: Favor [u]int64_t over off_t

2019-01-12 Thread Eric Blake
Although our compile-time environment is set up so that we always support long files with 64-bit off_t, we have no guarantee whether off_t is the same type as int64_t. This requires casts when printing values, and prevents us from directly using qemu_strtoi64(). Let's just flip to [u]int64_t

[Qemu-block] [PATCH v3 14/19] nbd/client: Pull out oldstyle size determination

2019-01-12 Thread Eric Blake
Another refactoring creating nbd_negotiate_finish_oldstyle() for further reuse during 'qemu-nbd --list'. Signed-off-by: Eric Blake Message-Id: <20181215135324.152629-18-ebl...@redhat.com> Reviewed-by: Richard W.M. Jones --- nbd/client.c | 49 - 1

[Qemu-block] [PATCH v3 12/19] nbd/client: Refactor return of nbd_receive_negotiate()

2019-01-12 Thread Eric Blake
The function could only ever return 0 or -EINVAL; make this clearer by dropping a useless 'fail:' label. Signed-off-by: Eric Blake Reviewed-by: Richard W.M. Jones Reviewed-by: Vladimir Sementsov-Ogievskiy Message-Id: <20181215135324.152629-16-ebl...@redhat.com> --- nbd/client.c | 51

[Qemu-block] [PATCH v3 08/19] nbd/client: Move export name into NBDExportInfo

2019-01-12 Thread Eric Blake
Refactor the 'name' parameter of nbd_receive_negotiate() from being a separate parameter into being part of the in-out 'info'. This also spills over to a simplification of nbd_opt_go(). The main driver for this refactoring is that an upcoming patch would like to add support to qemu-nbd to list

[Qemu-block] [PATCH v3 09/19] nbd/client: Change signature of nbd_negotiate_simple_meta_context()

2019-01-12 Thread Eric Blake
Pass 'info' instead of three separate parameters related to info, when requesting the server to set the meta context. Update the NBDExportInfo struct to rename the received id field to match the fact that we are currently overloading the field to match whatever context the user supplied through

[Qemu-block] [PATCH v3 04/19] nbd/server: Hoist length check to qemp_nbd_server_add

2019-01-12 Thread Eric Blake
We only had two callers to nbd_export_new; qemu-nbd.c always passed a valid offset/length pair (because it already checked the file length, to ensure that offset was in bounds), while blockdev-nbd always passed 0/-1. Then nbd_export_new reduces the size to a multiple of BDRV_SECTOR_SIZE (can only

[Qemu-block] [PATCH v3 19/19] iotests: Enhance 223, 233 to cover 'qemu-nbd --list'

2019-01-12 Thread Eric Blake
Any good new feature deserves some regression testing :) Coverage includes: - 223: what happens when there are 0 or more than 1 export, proof that we can see multiple contexts including qemu:dirty-bitmap - 233: proof that we can list over TLS, and that mix-and-match of plain/TLS listings will

[Qemu-block] [PATCH v3 01/19] maint: Allow for EXAMPLES in texi2pod

2019-01-12 Thread Eric Blake
The next commit will add an EXAMPLES section to qemu-nbd.8; for that to work, we need to recognize EXAMPLES in texi2pod. We also need to add a dependency from all man pages against the generator script, since a change to the generator may cause the resulting man page to differ. Signed-off-by:

[Qemu-block] [PATCH v3 00/19] nbd: add qemu-nbd --list

2019-01-12 Thread Eric Blake
I got tired of debugging whether a server was advertising the correct things during negotiation by inspecting the trace logs of qemu-io as client - not to mention that without SOME sort of client tracing particular commands, we can't easily regression test the server for correct behavior. The

[Qemu-block] [PATCH v3 07/19] nbd/client: Refactor nbd_receive_list()

2019-01-12 Thread Eric Blake
Right now, nbd_receive_list() is only called by nbd_receive_query_exports(), which in turn is only called if the server lacks NBD_OPT_GO but has working option negotiation, and is merely used as a quality-of-implementation trick since servers can't give decent errors for NBD_OPT_EXPORT_NAME.

[Qemu-block] [PATCH v3 06/19] qemu-nbd: Avoid strtol open-coding

2019-01-12 Thread Eric Blake
Our copy-and-pasted open-coding of strtol handling forgot to handle overflow conditions. Use qemu_strto*() instead. In the case of --partition, since we insist on a user-supplied partition to be non-zero, we can use 0 rather than -1 for our initial value to distinguish when a partition is not

[Qemu-block] [PATCH v3 13/19] nbd/client: Split handshake into two functions

2019-01-12 Thread Eric Blake
An upcoming patch will add the ability for qemu-nbd to list the services provided by an NBD server. Share the common code of the TLS handshake by splitting the initial exchange into a separate function, leaving only the export handling in the original function. Functionally, there should be no

[Qemu-block] [PATCH v3 16/19] nbd/client: Add meta contexts to nbd_receive_export_list()

2019-01-12 Thread Eric Blake
We want to be able to detect whether a given qemu NBD server is exposing the right export(s) and dirty bitmaps, at least for regression testing. We could use 'nbd-client -l' from the upstream NBD project to list exports, but it's annoying to rely on out-of-tree binaries; furthermore, nbd-client

[Qemu-block] [PATCH v3 15/19] nbd/client: Add nbd_receive_export_list()

2019-01-12 Thread Eric Blake
We want to be able to detect whether a given qemu NBD server is exposing the right export(s) and dirty bitmaps, at least for regression testing. We could use 'nbd-client -l' from the upstream NBD project to list exports, but it's annoying to rely on out-of-tree binaries; furthermore, nbd-client