Recently, CKI project reported nbd/001 and nbd/002 failure with the error message "Socket failed: Connection refused". It is suspected nbd- server is not yet ready when nbd-client connects for the first time. To avoid the failure, wait for the nbd-server start listening to the port at the end of _start_nbd_server(). For that purpose, use "nbd-client -l" command, which connects to the server and asks to list available exports. Reported-by: Yi Zhang <yi.zhang@xxxxxxxxxx> Link: https://github.com/osandov/blktests/issues/142 Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@xxxxxxx> --- tests/nbd/rc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/nbd/rc b/tests/nbd/rc index e96dc61..a56bae5 100644 --- a/tests/nbd/rc +++ b/tests/nbd/rc @@ -63,13 +63,24 @@ _wait_for_nbd_disconnect() { } _start_nbd_server() { + local i + truncate -s 10G "${TMPDIR}/export" cat > "${TMPDIR}/nbd.conf" << EOF [generic] +allowlist=true [export] exportname=${TMPDIR}/export EOF nbd-server -p "${TMPDIR}/nbd.pid" -C "${TMPDIR}/nbd.conf" + + # Wait for nbd-server start listening the port + for ((i = 0; i < 10; i++)); do + if nbd-client -l localhost &> "$FULL"; then + break + fi + sleep 1 + done } _stop_nbd_server() { -- 2.45.2