block: Drain requests in bdrv_close

If an AIO request is in flight that refers to a BlockDriverState that
has been closed and possibly even freed, more or less anything could
happen. I have seen segfaults, -EBADF return values and qcow2 sometimes
actually catches the situation in bdrv_close() and abort()s.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Kevin Wolf 2012-04-11 11:06:37 +02:00
parent aafcdcc9eb
commit 7094f12f86

View File

@ -816,6 +816,8 @@ void bdrv_close(BlockDriverState *bs)
if (bs->job) { if (bs->job) {
block_job_cancel_sync(bs->job); block_job_cancel_sync(bs->job);
} }
bdrv_drain_all();
if (bs == bs_snapshots) { if (bs == bs_snapshots) {
bs_snapshots = NULL; bs_snapshots = NULL;
} }