virtio-blk: Fix hot-unplug race in remove method
authorAsias He <asias@redhat.com>
Fri, 4 May 2012 12:22:04 +0000 (20:22 +0800)
committerBen Hutchings <ben@decadent.org.uk>
Wed, 12 Sep 2012 02:37:32 +0000 (03:37 +0100)
commite5000b33460e5008a3a189dc2107d274d8096eff
tree18105aa77de20b11b1c5430d1d2e862a6254f0aa
parent788c8de383e3c59df49126f95343eed0cf1733ea
virtio-blk: Fix hot-unplug race in remove method

commit b79d866c8b7014a51f611a64c40546109beaf24a upstream.

If we reset the virtio-blk device before the requests already dispatched
to the virtio-blk driver from the block layer are finised, we will stuck
in blk_cleanup_queue() and the remove will fail.

blk_cleanup_queue() calls blk_drain_queue() to drain all requests queued
before DEAD marking. However it will never success if the device is
already stopped. We'll have q->in_flight[] > 0, so the drain will not
finish.

How to reproduce the race:
1. hot-plug a virtio-blk device
2. keep reading/writing the device in guest
3. hot-unplug while the device is busy serving I/O

Test:
~1000 rounds of hot-plug/hot-unplug test passed with this patch.

Changes in v3:
- Drop blk_abort_queue and blk_abort_request
- Use __blk_end_request_all to complete request dispatched to driver

Changes in v2:
- Drop req_in_flight
- Use virtqueue_detach_unused_buf to get request dispatched to driver

Signed-off-by: Asias He <asias@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
drivers/block/virtio_blk.c