[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 04/14] vdi: Avoid direct AIO callback
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 04/14] vdi: Avoid direct AIO callback |
Date: |
Wed, 15 Jun 2011 16:03:03 +0200 |
bdrv_aio_* must not call the callback before returning to its caller. In vdi,
this could happen in some error cases. This starts the real requests processing
in a BH to avoid this situation.
Signed-off-by: Kevin Wolf <address@hidden>
---
block/vdi.c | 41 ++++++++++++++++++++++++++++++++++++-----
1 files changed, 36 insertions(+), 5 deletions(-)
diff --git a/block/vdi.c b/block/vdi.c
index 4c9e201..261cf9b 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -152,6 +152,7 @@ typedef struct {
/* Buffer for new allocated block. */
void *block_buffer;
void *orig_buf;
+ bool is_write;
int header_modified;
BlockDriverAIOCB *hd_aiocb;
struct iovec hd_iov;
@@ -504,6 +505,8 @@ static VdiAIOCB *vdi_aio_setup(BlockDriverState *bs,
int64_t sector_num,
acb->hd_aiocb = NULL;
acb->sector_num = sector_num;
acb->qiov = qiov;
+ acb->is_write = is_write;
+
if (qiov->niov > 1) {
acb->buf = qemu_blockalign(bs, qiov->size);
acb->orig_buf = acb->buf;
@@ -542,14 +545,20 @@ static int vdi_schedule_bh(QEMUBHFunc *cb, VdiAIOCB *acb)
}
static void vdi_aio_read_cb(void *opaque, int ret);
+static void vdi_aio_write_cb(void *opaque, int ret);
-static void vdi_aio_read_bh(void *opaque)
+static void vdi_aio_rw_bh(void *opaque)
{
VdiAIOCB *acb = opaque;
logout("\n");
qemu_bh_delete(acb->bh);
acb->bh = NULL;
- vdi_aio_read_cb(opaque, 0);
+
+ if (acb->is_write) {
+ vdi_aio_write_cb(opaque, 0);
+ } else {
+ vdi_aio_read_cb(opaque, 0);
+ }
}
static void vdi_aio_read_cb(void *opaque, int ret)
@@ -597,7 +606,7 @@ static void vdi_aio_read_cb(void *opaque, int ret)
if (bmap_entry == VDI_UNALLOCATED) {
/* Block not allocated, return zeros, no need to wait. */
memset(acb->buf, 0, n_sectors * SECTOR_SIZE);
- ret = vdi_schedule_bh(vdi_aio_read_bh, acb);
+ ret = vdi_schedule_bh(vdi_aio_rw_bh, acb);
if (ret < 0) {
goto done;
}
@@ -630,12 +639,23 @@ static BlockDriverAIOCB *vdi_aio_readv(BlockDriverState
*bs,
BlockDriverCompletionFunc *cb, void *opaque)
{
VdiAIOCB *acb;
+ int ret;
+
logout("\n");
acb = vdi_aio_setup(bs, sector_num, qiov, nb_sectors, cb, opaque, 0);
if (!acb) {
return NULL;
}
- vdi_aio_read_cb(acb, 0);
+
+ ret = vdi_schedule_bh(vdi_aio_rw_bh, acb);
+ if (ret < 0) {
+ if (acb->qiov->niov > 1) {
+ qemu_vfree(acb->orig_buf);
+ }
+ qemu_aio_release(acb);
+ return NULL;
+ }
+
return &acb->common;
}
@@ -789,12 +809,23 @@ static BlockDriverAIOCB *vdi_aio_writev(BlockDriverState
*bs,
BlockDriverCompletionFunc *cb, void *opaque)
{
VdiAIOCB *acb;
+ int ret;
+
logout("\n");
acb = vdi_aio_setup(bs, sector_num, qiov, nb_sectors, cb, opaque, 1);
if (!acb) {
return NULL;
}
- vdi_aio_write_cb(acb, 0);
+
+ ret = vdi_schedule_bh(vdi_aio_rw_bh, acb);
+ if (ret < 0) {
+ if (acb->qiov->niov > 1) {
+ qemu_vfree(acb->orig_buf);
+ }
+ qemu_aio_release(acb);
+ return NULL;
+ }
+
return &acb->common;
}
--
1.7.5.2
- [Qemu-devel] [PULL 00/14] Block patches, Kevin Wolf, 2011/06/15
- [Qemu-devel] [PATCH 01/14] block/rbd: Remove unused local variable, Kevin Wolf, 2011/06/15
- [Qemu-devel] [PATCH 04/14] vdi: Avoid direct AIO callback,
Kevin Wolf <=
- [Qemu-devel] [PATCH 02/14] qcow2: Avoid direct AIO callback, Kevin Wolf, 2011/06/15
- [Qemu-devel] [PATCH 06/14] qcow2: Fix in-flight list after qcow2_cache_put failure, Kevin Wolf, 2011/06/15
- [Qemu-devel] [PATCH 05/14] Replaced tabs with spaces in block.h and block_int.h, Kevin Wolf, 2011/06/15
- [Qemu-devel] [PATCH 07/14] ide: Split error status from status register, Kevin Wolf, 2011/06/15
- [Qemu-devel] [PATCH 08/14] ide: Fix ide_drive_pio_state_needed(), Kevin Wolf, 2011/06/15
- [Qemu-devel] [PATCH 09/14] ide: Add forgotten VMSTATE_END_OF_LIST in subsection, Kevin Wolf, 2011/06/15
- [Qemu-devel] [PATCH 10/14] make dma_bdrv_io available to drivers, Kevin Wolf, 2011/06/15
- [Qemu-devel] [PATCH 11/14] ide: allow other dma comands than read and write, Kevin Wolf, 2011/06/15
- [Qemu-devel] [PATCH 13/14] ide: Clear error_status after restarting flush, Kevin Wolf, 2011/06/15
- [Qemu-devel] [PATCH 03/14] qcow: Avoid direct AIO callback, Kevin Wolf, 2011/06/15