Skip to content

Commit

Permalink
block: Dec. drained_end_counter before bdrv_wakeup
Browse files Browse the repository at this point in the history
Decrementing drained_end_counter after bdrv_dec_in_flight() (which in
turn invokes bdrv_wakeup() and thus aio_wait_kick()) is not very clever.
We should decrement it beforehand, so that any waiting aio_poll() that
is woken by bdrv_dec_in_flight() sees the decremented
drained_end_counter.

Because the time window between decrementing drained_end_counter and
aio_wait_kick() is very small, I cannot supply a reliable regression
test.  However, running e.g. the /bdrv-drain/blockjob/iothread/drain_all
test in test-bdrv-drain has a small chance of hanging without this
patch (about 1/200 or so; it gets to nearly 100 % if you add e.g. an
fputc(' ', stderr); after the bdrv_dec_in_flight()).

Fixes: e037c09
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 20190722133054.21781-2-mreitz@redhat.com
Signed-off-by: Max Reitz <mreitz@redhat.com>
  • Loading branch information
XanClic committed Jul 22, 2019
1 parent 258867d commit 65181d6
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions block/io.c
Expand Up @@ -217,13 +217,12 @@ static void coroutine_fn bdrv_drain_invoke_entry(void *opaque)
bs->drv->bdrv_co_drain_end(bs);
}

/* Set data->done before reading bs->wakeup. */
/* Set data->done and decrement drained_end_counter before bdrv_wakeup() */
atomic_mb_set(&data->done, true);
bdrv_dec_in_flight(bs);

if (!data->begin) {
atomic_dec(data->drained_end_counter);
}
bdrv_dec_in_flight(bs);

g_free(data);
}
Expand Down

0 comments on commit 65181d6

Please sign in to comment.