aboutsummaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
Diffstat (limited to 'block.c')
-rw-r--r--block.c42
1 files changed, 27 insertions, 15 deletions
diff --git a/block.c b/block.c
index 135fbe6a30..ad16ee4935 100644
--- a/block.c
+++ b/block.c
@@ -147,6 +147,7 @@ static void bdrv_register(BlockDriver *bdrv)
bdrv->bdrv_read = bdrv_read_em;
bdrv->bdrv_write = bdrv_write_em;
}
+ aio_pool_init(&bdrv->aio_pool, bdrv->aiocb_size, bdrv->bdrv_aio_cancel);
bdrv->next = first_drv;
first_drv = bdrv;
}
@@ -1371,14 +1372,12 @@ BlockDriverAIOCB *bdrv_aio_write(BlockDriverState *bs, int64_t sector_num,
void bdrv_aio_cancel(BlockDriverAIOCB *acb)
{
- BlockDriver *drv = acb->bs->drv;
-
if (acb->cb == bdrv_aio_rw_vector_cb) {
VectorTranslationState *s = acb->opaque;
acb = s->aiocb;
}
- drv->bdrv_aio_cancel(acb);
+ acb->pool->cancel(acb);
}
@@ -1496,18 +1495,25 @@ void bdrv_init(void)
bdrv_register(&bdrv_nbd);
}
-void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb,
- void *opaque)
+void aio_pool_init(AIOPool *pool, int aiocb_size,
+ void (*cancel)(BlockDriverAIOCB *acb))
+{
+ pool->aiocb_size = aiocb_size;
+ pool->cancel = cancel;
+ pool->free_aiocb = NULL;
+}
+
+void *qemu_aio_get_pool(AIOPool *pool, BlockDriverState *bs,
+ BlockDriverCompletionFunc *cb, void *opaque)
{
- BlockDriver *drv;
BlockDriverAIOCB *acb;
- drv = bs->drv;
- if (drv->free_aiocb) {
- acb = drv->free_aiocb;
- drv->free_aiocb = acb->next;
+ if (pool->free_aiocb) {
+ acb = pool->free_aiocb;
+ pool->free_aiocb = acb->next;
} else {
- acb = qemu_mallocz(drv->aiocb_size);
+ acb = qemu_mallocz(pool->aiocb_size);
+ acb->pool = pool;
}
acb->bs = bs;
acb->cb = cb;
@@ -1515,12 +1521,18 @@ void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb,
return acb;
}
+void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb,
+ void *opaque)
+{
+ return qemu_aio_get_pool(&bs->drv->aio_pool, bs, cb, opaque);
+}
+
void qemu_aio_release(void *p)
{
- BlockDriverAIOCB *acb = p;
- BlockDriver *drv = acb->bs->drv;
- acb->next = drv->free_aiocb;
- drv->free_aiocb = acb;
+ BlockDriverAIOCB *acb = (BlockDriverAIOCB *)p;
+ AIOPool *pool = acb->pool;
+ acb->next = pool->free_aiocb;
+ pool->free_aiocb = acb;
}
/**************************************************************/