qcow2: Convert qcow2 to use coroutines for async I/O
commitfcdedcf412c66d1e58bef6ea9aed3795b9742657
authorStefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Thu, 20 Jan 2011 17:55:58 +0000 (20 17:55 +0000)
committerStefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Fri, 21 Jan 2011 16:58:30 +0000 (21 16:58 +0000)
tree75c094dafedfe6ac2fd7ea27e966d1a1a1c11c23
parent4f3c1c780fec95ec66e76554f4c2b03f0d4e07ab
qcow2: Convert qcow2 to use coroutines for async I/O

Converting qcow2 to use coroutines is fairly simple since most of qcow2
is synchronous.  The synchronous I/O functions likes bdrv_pread() now
transparently work when called from a coroutine, so all the synchronous
code just works.

The explicitly asynchronous code is adjusted to repeatedly call
qcow2_aio_read_cb() or qcow2_aio_write_cb() until the request completes.
At that point the coroutine will return from its entry function and its
resources are freed.

The bdrv_aio_readv() and bdrv_aio_writev() user callback is now invoked
from a BH.  This is necessary since the user callback code does not
expect to be executed from a coroutine.

This conversion is not completely correct because the safety the
synchronous code does not carry over to the coroutine version.
Previously, a synchronous code path could assume that it will never be
interleaved with another request executing.  This is no longer true
because bdrv_pread() and bdrv_pwrite() cause the coroutine to yield and
other requests can be processed during that time.

The solution is to carefully introduce checks so that pending requests
do not step on each other's toes.  That is left for a future patch...

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
block/qcow2.c