block/nbd: on shutdown terminate connection attempt
commitfbeb3e63b34a1af4a968031de1c82e5edf20bf6c
authorVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Mon, 27 Jul 2020 18:47:49 +0000 (27 21:47 +0300)
committerEric Blake <eblake@redhat.com>
Tue, 28 Jul 2020 14:54:43 +0000 (28 09:54 -0500)
tree89dc9e3d352e7b0afe1c1e67647f9ef85eaa7bc8
parentdd1ec1a4afe190e030edfa052d95c9e6e065438c
block/nbd: on shutdown terminate connection attempt

On shutdown nbd driver may be in a connecting state. We should shutdown
it as well, otherwise we may hang in
nbd_teardown_connection, waiting for conneciton_co to finish in
BDRV_POLL_WHILE(bs, s->connection_co) loop if remote server is down.

How to reproduce the dead lock:

1. Create nbd-fault-injector.conf with the following contents:

[inject-error "mega1"]
event=data
io=readwrite
when=before

2. In one terminal run nbd-fault-injector in a loop, like this:

n=1; while true; do
    echo $n; ((n++));
    ./nbd-fault-injector.py 127.0.0.1:10000 nbd-fault-injector.conf;
done

3. In another terminal run qemu-io in a loop, like this:

n=1; while true; do
    echo $n; ((n++));
    ./qemu-io -c 'read 0 512' nbd://127.0.0.1:10000;
done

After some time, qemu-io will hang. Note, that this hang may be
triggered by another bug, so the whole case is fixed only together with
commit "block/nbd: allow drain during reconnect attempt".

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200727184751.15704-4-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
block/nbd.c