summaryrefslogtreecommitdiff
path: root/qemu/block-qcow2.c
diff options
context:
space:
mode:
authoraliguori <aliguori>2008-10-31 17:28:00 +0000
committeraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2008-10-31 17:28:00 +0000
commitaf1405b9c816541a22719409755c2ed1edb5a8f2 (patch)
treeaf7492e201f065654250068bfc043e55e01dcb8c /qemu/block-qcow2.c
parentf36223fa8551613ba7815aa142e7615dfa8a8119 (diff)
fix bdrv_aio_read API breakage in qcow2 (Andrea Arcangeli)
I noticed the qemu_aio_flush was doing nothing at all. And a flood of cmd_writeb commands leading to a noop-invocation of qemu_aio_flush were executed. In short all 'memset;goto redo' places must be fixed to use the bh and not to call the callback in the context of bdrv_aio_read or the bdrv_aio_read model falls apart. Reading from qcow2 holes is possible with phyisical readahead (kind of breada in linux buffer cache). This is needed at least for scsi, ide is lucky (or it has been band-aided against this API breakage by fixing the symptom and not the real bug). Same bug exists in qcow of course, can be fixed later as it's less urgent. Signed-off-by: Andrea Arcangeli <aarcange@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'qemu/block-qcow2.c')
-rw-r--r--qemu/block-qcow2.c44
1 files changed, 40 insertions, 4 deletions
diff --git a/qemu/block-qcow2.c b/qemu/block-qcow2.c
index 693cd772..dc73769e 100644
--- a/qemu/block-qcow2.c
+++ b/qemu/block-qcow2.c
@@ -1165,8 +1165,18 @@ typedef struct QCowAIOCB {
uint64_t cluster_offset;
uint8_t *cluster_data;
BlockDriverAIOCB *hd_aiocb;
+ QEMUBH *bh;
} QCowAIOCB;
+static void qcow_aio_read_cb(void *opaque, int ret);
+static void qcow_aio_read_bh(void *opaque)
+{
+ QCowAIOCB *acb = opaque;
+ qemu_bh_delete(acb->bh);
+ acb->bh = NULL;
+ qcow_aio_read_cb(opaque, 0);
+}
+
static void qcow_aio_read_cb(void *opaque, int ret)
{
QCowAIOCB *acb = opaque;
@@ -1182,7 +1192,6 @@ static void qcow_aio_read_cb(void *opaque, int ret)
return;
}
- redo:
/* post process the read buffer */
if (!acb->cluster_offset) {
/* nothing to do */
@@ -1223,12 +1232,30 @@ static void qcow_aio_read_cb(void *opaque, int ret)
if (acb->hd_aiocb == NULL)
goto fail;
} else {
- goto redo;
+ if (acb->bh) {
+ ret = -EIO;
+ goto fail;
+ }
+ acb->bh = qemu_bh_new(qcow_aio_read_bh, acb);
+ if (!acb->bh) {
+ ret = -EIO;
+ goto fail;
+ }
+ qemu_bh_schedule(acb->bh);
}
} else {
/* Note: in this case, no need to wait */
memset(acb->buf, 0, 512 * acb->n);
- goto redo;
+ if (acb->bh) {
+ ret = -EIO;
+ goto fail;
+ }
+ acb->bh = qemu_bh_new(qcow_aio_read_bh, acb);
+ if (!acb->bh) {
+ ret = -EIO;
+ goto fail;
+ }
+ qemu_bh_schedule(acb->bh);
}
} else if (acb->cluster_offset & QCOW_OFLAG_COMPRESSED) {
/* add AIO support for compressed blocks ? */
@@ -1236,7 +1263,16 @@ static void qcow_aio_read_cb(void *opaque, int ret)
goto fail;
memcpy(acb->buf,
s->cluster_cache + index_in_cluster * 512, 512 * acb->n);
- goto redo;
+ if (acb->bh) {
+ ret = -EIO;
+ goto fail;
+ }
+ acb->bh = qemu_bh_new(qcow_aio_read_bh, acb);
+ if (!acb->bh) {
+ ret = -EIO;
+ goto fail;
+ }
+ qemu_bh_schedule(acb->bh);
} else {
if ((acb->cluster_offset & 511) != 0) {
ret = -EIO;