aboutsummaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
authorZhi Yong Wu <wuzhy@linux.vnet.ibm.com>2012-04-12 14:00:57 +0200
committerKevin Wolf <kwolf@redhat.com>2012-05-10 10:32:11 +0200
commit4c355d53c6a5444b78b695f8bf106f1ffcba45e1 (patch)
tree8eaaae1385724a7c66ba3b9982956cbbbac773e4 /block.c
parent1b3e76ebd1e270eae27e502ea8b836c31d95f801 (diff)
downloadqemu-4c355d53c6a5444b78b695f8bf106f1ffcba45e1.zip
qemu-4c355d53c6a5444b78b695f8bf106f1ffcba45e1.tar.gz
qemu-4c355d53c6a5444b78b695f8bf106f1ffcba45e1.tar.bz2
block: add the support to drain throttled requests
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com> [ Iterate until all block devices have processed all requests, add comments. - Paolo ] Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block.c')
-rw-r--r--block.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/block.c b/block.c
index ee7d8f2..a307fe1 100644
--- a/block.c
+++ b/block.c
@@ -906,12 +906,31 @@ void bdrv_close_all(void)
*
* This function does not flush data to disk, use bdrv_flush_all() for that
* after calling this function.
+ *
+ * Note that completion of an asynchronous I/O operation can trigger any
+ * number of other I/O operations on other devices---for example a coroutine
+ * can be arbitrarily complex and a constant flow of I/O can come until the
+ * coroutine is complete. Because of this, it is not possible to have a
+ * function to drain a single device's I/O queue.
*/
void bdrv_drain_all(void)
{
BlockDriverState *bs;
+ bool busy;
- qemu_aio_flush();
+ do {
+ busy = qemu_aio_wait();
+
+ /* FIXME: We do not have timer support here, so this is effectively
+ * a busy wait.
+ */
+ QTAILQ_FOREACH(bs, &bdrv_states, list) {
+ if (!qemu_co_queue_empty(&bs->throttled_reqs)) {
+ qemu_co_queue_restart_all(&bs->throttled_reqs);
+ busy = true;
+ }
+ }
+ } while (busy);
/* If requests are still pending there is a bug somewhere */
QTAILQ_FOREACH(bs, &bdrv_states, list) {