From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LjCbD-0006AV-Jc for qemu-devel@nongnu.org; Mon, 16 Mar 2009 09:11:23 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LjCb9-00069C-Qy for qemu-devel@nongnu.org; Mon, 16 Mar 2009 09:11:23 -0400 Received: from [199.232.76.173] (port=41549 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LjCb9-00068i-94 for qemu-devel@nongnu.org; Mon, 16 Mar 2009 09:11:19 -0400 Received: from mx2.redhat.com ([66.187.237.31]:39035) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LjCb8-000241-M8 for qemu-devel@nongnu.org; Mon, 16 Mar 2009 09:11:19 -0400 From: Avi Kivity Date: Mon, 16 Mar 2009 15:11:07 +0200 Message-Id: <1237209071-26942-2-git-send-email-avi@redhat.com> In-Reply-To: <1237209071-26942-1-git-send-email-avi@redhat.com> References: <1237209071-26942-1-git-send-email-avi@redhat.com> Subject: [Qemu-devel] [PATCH 1/5] Refactor aio callback allocation to use an aiocb pool Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: qemu-devel@nongnu.org Move the AIOCB allocation code to use a dedicate structure, AIOPool. AIOCB specific information, such as the AIOCB size and cancellation routine, is moved into the pool. At present, there is exactly one pool per block format driver, maintaining the status quo. Signed-off-by: Avi Kivity --- block.c | 42 +++++++++++++++++++++++++++--------------- block_int.h | 14 +++++++++++++- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/block.c b/block.c index 135fbe6..ad16ee4 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; } /**************************************************************/ diff --git a/block_int.h b/block_int.h index d3c81fa..8b4c5fe 100644 --- a/block_int.h +++ b/block_int.h @@ -30,6 +30,12 @@ #define BLOCK_FLAG_COMPRESS 2 #define BLOCK_FLAG_COMPAT6 4 +typedef struct AIOPool { + void (*cancel)(BlockDriverAIOCB *acb); + int aiocb_size; + BlockDriverAIOCB *free_aiocb; +} AIOPool; + struct BlockDriver { const char *format_name; int instance_size; @@ -91,7 +97,7 @@ struct BlockDriver { BlockDriverCompletionFunc *cb, void *opaque); - BlockDriverAIOCB *free_aiocb; + AIOPool aio_pool; struct BlockDriver *next; }; @@ -141,6 +147,7 @@ struct BlockDriverState { }; struct BlockDriverAIOCB { + AIOPool *pool; BlockDriverState *bs; BlockDriverCompletionFunc *cb; void *opaque; @@ -149,8 +156,13 @@ struct BlockDriverAIOCB { void get_tmp_filename(char *filename, int size); +void aio_pool_init(AIOPool *pool, int aiocb_size, + void (*cancel)(BlockDriverAIOCB *acb)); + void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb, void *opaque); +void *qemu_aio_get_pool(AIOPool *pool, BlockDriverState *bs, + BlockDriverCompletionFunc *cb, void *opaque); void qemu_aio_release(void *p); extern BlockDriverState *bdrv_first; -- 1.6.1.1