On Fri, Oct 16, 2026 at 10:41:36AM +0200, Guillaume Vincke wrote:
> Test the connect thread starting condition with reconnect-delay=0 when
> the server disconnects after a successful handshake but before running
> operations. Prior to the change to nbd_co_establish_connection(), this
> test would demonstrate two I/O errors. The tests 264 and 277 covering
> reconnection do not use reconnect-delay=0 so this case is not exercised.
>
> Add a test that provokes multiple errors in order to put an NBD client
> in the above-mentioned situation and shows that the first operation
> starts the connect thread and leads to successful subsequent I/O.
>
> Signed-off-by: Guillaume Vincke <[email protected]>
> ---
> tests/qemu-iotests/tests/nbd-stale-connection | 60 +++++++++++++++++++
> .../tests/nbd-stale-connection.out | 17 ++++++
> 2 files changed, 77 insertions(+)
> create mode 100755 tests/qemu-iotests/tests/nbd-stale-connection
> create mode 100644 tests/qemu-iotests/tests/nbd-stale-connection.out
> +
> +# estimated duration required by the connect thread to reach a running server
> +MAX_NBD_CONNECT_DURATION = 1
> +
> +
> + with qemu_nbd_popen('-k', nbd_sock, '-f', iotests.imgfmt, disk):
> + iotests.log('=== NBD server up. Wait for the connect thread to park '
> + 'the channel ===')
> + # in CONNECTING, the operation starts the connect thread
> + log(vm.qmp('x-qemu-io', device='nbd0', command='write -P 0x5a 0
> 64k'))
> + # wait for the connect thread to get a new channel and stop
> + time.sleep(MAX_NBD_CONNECT_DURATION)
Timeout-based tests are always risky for false negatives when the CI
system has more load than the development system. But comparing this
version of the patch to v1, it looks like you managed to get much more
reliable witness points. I'll be running this through testing on my
own branch of gitlab several times to see if I can tease out any more
failures, but hopefully it is ready to use. I'll reply again once I've
made a decision on whether to include it in my current pull request or
defer it to my next batch of patches.
> +
> + iotests.log('=== NBD server down. The parked channel is closed ===')
> +
> + with qemu_nbd_popen('-k', nbd_sock, '-f', iotests.imgfmt, disk):
> + iotests.log('=== NBD server up. Restart the connect thread ===')
> + # operation will determine that the channel got closed and restart
> the
> + # connect thread
> + log(vm.qmp('x-qemu-io', device='nbd0', command='write -P 0x5a 0
> 64k'))
> + # Wait for it to succeed
> + iotests.log('=== Wait for the connect thread to park the new
> channel. '
> + 'Subsequent operations are successful ===')
> + time.sleep(MAX_NBD_CONNECT_DURATION)
> + log(vm.qmp('x-qemu-io', device='nbd0', command='write -P 0x5a 0
> 64k'))
> diff --git a/tests/qemu-iotests/tests/nbd-stale-connection.out
> b/tests/qemu-iotests/tests/nbd-stale-connection.out
> new file mode 100644
> index 0000000000..065ba329e9
> --- /dev/null
> +++ b/tests/qemu-iotests/tests/nbd-stale-connection.out
> @@ -0,0 +1,17 @@
> +Start NBD server
> +=== NBD Device connected ===
> +{"return": {}}
> +Kill NBD server
> +=== NBD server down. Detect the break and start the connect thread ===
> +{"error": {"class": "GenericError", "desc": "write failed: Input/output
> error"}}
> +Start NBD server
> +=== NBD server up. Wait for the connect thread to park the channel ===
> +{"error": {"class": "GenericError", "desc": "write failed: Input/output
> error"}}
> +Kill NBD server
> +=== NBD server down. The parked channel is closed ===
> +Start NBD server
> +=== NBD server up. Restart the connect thread ===
> +{"error": {"class": "GenericError", "desc": "write failed: Input/output
> error"}}
> +=== Wait for the connect thread to park the new channel. Subsequent
> operations are successful ===
> +{"return": {}}
> +Kill NBD server
> --
> 2.43.0
>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization: qemu.org | libguestfs.org