Commit 6bbff9a0b495918309074ac60375be5f9dc868b3

Authored by aliguori
1 parent 97b83deb

Refactor aio callback allocation to use an aiocb pool (Avi Kivity)

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 <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6870 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 2 changed files with 40 additions and 16 deletions
... ... @@ -147,6 +147,7 @@ static void bdrv_register(BlockDriver *bdrv)
147 147 bdrv->bdrv_read = bdrv_read_em;
148 148 bdrv->bdrv_write = bdrv_write_em;
149 149 }
  150 + aio_pool_init(&bdrv->aio_pool, bdrv->aiocb_size, bdrv->bdrv_aio_cancel);
150 151 bdrv->next = first_drv;
151 152 first_drv = bdrv;
152 153 }
... ... @@ -1371,14 +1372,12 @@ BlockDriverAIOCB *bdrv_aio_write(BlockDriverState *bs, int64_t sector_num,
1371 1372  
1372 1373 void bdrv_aio_cancel(BlockDriverAIOCB *acb)
1373 1374 {
1374   - BlockDriver *drv = acb->bs->drv;
1375   -
1376 1375 if (acb->cb == bdrv_aio_rw_vector_cb) {
1377 1376 VectorTranslationState *s = acb->opaque;
1378 1377 acb = s->aiocb;
1379 1378 }
1380 1379  
1381   - drv->bdrv_aio_cancel(acb);
  1380 + acb->pool->cancel(acb);
1382 1381 }
1383 1382  
1384 1383  
... ... @@ -1496,18 +1495,25 @@ void bdrv_init(void)
1496 1495 bdrv_register(&bdrv_nbd);
1497 1496 }
1498 1497  
1499   -void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb,
1500   - void *opaque)
  1498 +void aio_pool_init(AIOPool *pool, int aiocb_size,
  1499 + void (*cancel)(BlockDriverAIOCB *acb))
  1500 +{
  1501 + pool->aiocb_size = aiocb_size;
  1502 + pool->cancel = cancel;
  1503 + pool->free_aiocb = NULL;
  1504 +}
  1505 +
  1506 +void *qemu_aio_get_pool(AIOPool *pool, BlockDriverState *bs,
  1507 + BlockDriverCompletionFunc *cb, void *opaque)
1501 1508 {
1502   - BlockDriver *drv;
1503 1509 BlockDriverAIOCB *acb;
1504 1510  
1505   - drv = bs->drv;
1506   - if (drv->free_aiocb) {
1507   - acb = drv->free_aiocb;
1508   - drv->free_aiocb = acb->next;
  1511 + if (pool->free_aiocb) {
  1512 + acb = pool->free_aiocb;
  1513 + pool->free_aiocb = acb->next;
1509 1514 } else {
1510   - acb = qemu_mallocz(drv->aiocb_size);
  1515 + acb = qemu_mallocz(pool->aiocb_size);
  1516 + acb->pool = pool;
1511 1517 }
1512 1518 acb->bs = bs;
1513 1519 acb->cb = cb;
... ... @@ -1515,12 +1521,18 @@ void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb,
1515 1521 return acb;
1516 1522 }
1517 1523  
  1524 +void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb,
  1525 + void *opaque)
  1526 +{
  1527 + return qemu_aio_get_pool(&bs->drv->aio_pool, bs, cb, opaque);
  1528 +}
  1529 +
1518 1530 void qemu_aio_release(void *p)
1519 1531 {
1520   - BlockDriverAIOCB *acb = p;
1521   - BlockDriver *drv = acb->bs->drv;
1522   - acb->next = drv->free_aiocb;
1523   - drv->free_aiocb = acb;
  1532 + BlockDriverAIOCB *acb = (BlockDriverAIOCB *)p;
  1533 + AIOPool *pool = acb->pool;
  1534 + acb->next = pool->free_aiocb;
  1535 + pool->free_aiocb = acb;
1524 1536 }
1525 1537  
1526 1538 /**************************************************************/
... ...
block_int.h
... ... @@ -30,6 +30,12 @@
30 30 #define BLOCK_FLAG_COMPRESS 2
31 31 #define BLOCK_FLAG_COMPAT6 4
32 32  
  33 +typedef struct AIOPool {
  34 + void (*cancel)(BlockDriverAIOCB *acb);
  35 + int aiocb_size;
  36 + BlockDriverAIOCB *free_aiocb;
  37 +} AIOPool;
  38 +
33 39 struct BlockDriver {
34 40 const char *format_name;
35 41 int instance_size;
... ... @@ -91,7 +97,7 @@ struct BlockDriver {
91 97 BlockDriverCompletionFunc *cb,
92 98 void *opaque);
93 99  
94   - BlockDriverAIOCB *free_aiocb;
  100 + AIOPool aio_pool;
95 101 struct BlockDriver *next;
96 102 };
97 103  
... ... @@ -141,6 +147,7 @@ struct BlockDriverState {
141 147 };
142 148  
143 149 struct BlockDriverAIOCB {
  150 + AIOPool *pool;
144 151 BlockDriverState *bs;
145 152 BlockDriverCompletionFunc *cb;
146 153 void *opaque;
... ... @@ -149,8 +156,13 @@ struct BlockDriverAIOCB {
149 156  
150 157 void get_tmp_filename(char *filename, int size);
151 158  
  159 +void aio_pool_init(AIOPool *pool, int aiocb_size,
  160 + void (*cancel)(BlockDriverAIOCB *acb));
  161 +
152 162 void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb,
153 163 void *opaque);
  164 +void *qemu_aio_get_pool(AIOPool *pool, BlockDriverState *bs,
  165 + BlockDriverCompletionFunc *cb, void *opaque);
154 166 void qemu_aio_release(void *p);
155 167  
156 168 extern BlockDriverState *bdrv_first;
... ...