Commit c16b5a2ca0b186de618654a576bdad9cdd2d1ab2

Authored by Christoph Hellwig
Committed by Anthony Liguori
1 parent ad53089b

fully split aio_pool from BlockDriver

Now that we have a separate aio pool structure we can remove those
aio pool details from BlockDriver.

Every driver supporting AIO now needs to declare a static AIOPool
with the aiocb size and the cancellation method.  This cleans up the
current code considerably and will make it cleaner and more obvious
to support two different aio implementations behind a single
BlockDriver.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
@@ -48,23 +48,12 @@ @@ -48,23 +48,12 @@
48 #define SECTOR_BITS 9 48 #define SECTOR_BITS 9
49 #define SECTOR_SIZE (1 << SECTOR_BITS) 49 #define SECTOR_SIZE (1 << SECTOR_BITS)
50 50
51 -typedef struct BlockDriverAIOCBSync {  
52 - BlockDriverAIOCB common;  
53 - QEMUBH *bh;  
54 - int ret;  
55 - /* vector translation state */  
56 - QEMUIOVector *qiov;  
57 - uint8_t *bounce;  
58 - int is_write;  
59 -} BlockDriverAIOCBSync;  
60 -  
61 static BlockDriverAIOCB *bdrv_aio_readv_em(BlockDriverState *bs, 51 static BlockDriverAIOCB *bdrv_aio_readv_em(BlockDriverState *bs,
62 int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, 52 int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
63 BlockDriverCompletionFunc *cb, void *opaque); 53 BlockDriverCompletionFunc *cb, void *opaque);
64 static BlockDriverAIOCB *bdrv_aio_writev_em(BlockDriverState *bs, 54 static BlockDriverAIOCB *bdrv_aio_writev_em(BlockDriverState *bs,
65 int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, 55 int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
66 BlockDriverCompletionFunc *cb, void *opaque); 56 BlockDriverCompletionFunc *cb, void *opaque);
67 -static void bdrv_aio_cancel_em(BlockDriverAIOCB *acb);  
68 static int bdrv_read_em(BlockDriverState *bs, int64_t sector_num, 57 static int bdrv_read_em(BlockDriverState *bs, int64_t sector_num,
69 uint8_t *buf, int nb_sectors); 58 uint8_t *buf, int nb_sectors);
70 static int bdrv_write_em(BlockDriverState *bs, int64_t sector_num, 59 static int bdrv_write_em(BlockDriverState *bs, int64_t sector_num,
@@ -138,21 +127,17 @@ void path_combine(char *dest, int dest_size, @@ -138,21 +127,17 @@ void path_combine(char *dest, int dest_size,
138 } 127 }
139 } 128 }
140 129
141 -  
142 void bdrv_register(BlockDriver *bdrv) 130 void bdrv_register(BlockDriver *bdrv)
143 { 131 {
144 if (!bdrv->bdrv_aio_readv) { 132 if (!bdrv->bdrv_aio_readv) {
145 /* add AIO emulation layer */ 133 /* add AIO emulation layer */
146 bdrv->bdrv_aio_readv = bdrv_aio_readv_em; 134 bdrv->bdrv_aio_readv = bdrv_aio_readv_em;
147 bdrv->bdrv_aio_writev = bdrv_aio_writev_em; 135 bdrv->bdrv_aio_writev = bdrv_aio_writev_em;
148 - bdrv->bdrv_aio_cancel = bdrv_aio_cancel_em;  
149 - bdrv->aiocb_size = sizeof(BlockDriverAIOCBSync);  
150 } else if (!bdrv->bdrv_read) { 136 } else if (!bdrv->bdrv_read) {
151 /* add synchronous IO emulation layer */ 137 /* add synchronous IO emulation layer */
152 bdrv->bdrv_read = bdrv_read_em; 138 bdrv->bdrv_read = bdrv_read_em;
153 bdrv->bdrv_write = bdrv_write_em; 139 bdrv->bdrv_write = bdrv_write_em;
154 } 140 }
155 - aio_pool_init(&bdrv->aio_pool, bdrv->aiocb_size, bdrv->bdrv_aio_cancel);  
156 bdrv->next = first_drv; 141 bdrv->next = first_drv;
157 first_drv = bdrv; 142 first_drv = bdrv;
158 } 143 }
@@ -1369,6 +1354,28 @@ void bdrv_aio_cancel(BlockDriverAIOCB *acb) @@ -1369,6 +1354,28 @@ void bdrv_aio_cancel(BlockDriverAIOCB *acb)
1369 /**************************************************************/ 1354 /**************************************************************/
1370 /* async block device emulation */ 1355 /* async block device emulation */
1371 1356
  1357 +typedef struct BlockDriverAIOCBSync {
  1358 + BlockDriverAIOCB common;
  1359 + QEMUBH *bh;
  1360 + int ret;
  1361 + /* vector translation state */
  1362 + QEMUIOVector *qiov;
  1363 + uint8_t *bounce;
  1364 + int is_write;
  1365 +} BlockDriverAIOCBSync;
  1366 +
  1367 +static void bdrv_aio_cancel_em(BlockDriverAIOCB *blockacb)
  1368 +{
  1369 + BlockDriverAIOCBSync *acb = (BlockDriverAIOCBSync *)blockacb;
  1370 + qemu_bh_cancel(acb->bh);
  1371 + qemu_aio_release(acb);
  1372 +}
  1373 +
  1374 +static AIOPool bdrv_em_aio_pool = {
  1375 + .aiocb_size = sizeof(BlockDriverAIOCBSync),
  1376 + .cancel = bdrv_aio_cancel_em,
  1377 +};
  1378 +
1372 static void bdrv_aio_bh_cb(void *opaque) 1379 static void bdrv_aio_bh_cb(void *opaque)
1373 { 1380 {
1374 BlockDriverAIOCBSync *acb = opaque; 1381 BlockDriverAIOCBSync *acb = opaque;
@@ -1392,7 +1399,7 @@ static BlockDriverAIOCB *bdrv_aio_rw_vector(BlockDriverState *bs, @@ -1392,7 +1399,7 @@ static BlockDriverAIOCB *bdrv_aio_rw_vector(BlockDriverState *bs,
1392 { 1399 {
1393 BlockDriverAIOCBSync *acb; 1400 BlockDriverAIOCBSync *acb;
1394 1401
1395 - acb = qemu_aio_get(bs, cb, opaque); 1402 + acb = qemu_aio_get(&bdrv_em_aio_pool, bs, cb, opaque);
1396 acb->is_write = is_write; 1403 acb->is_write = is_write;
1397 acb->qiov = qiov; 1404 acb->qiov = qiov;
1398 acb->bounce = qemu_blockalign(bs, qiov->size); 1405 acb->bounce = qemu_blockalign(bs, qiov->size);
@@ -1426,14 +1433,6 @@ static BlockDriverAIOCB *bdrv_aio_writev_em(BlockDriverState *bs, @@ -1426,14 +1433,6 @@ static BlockDriverAIOCB *bdrv_aio_writev_em(BlockDriverState *bs,
1426 return bdrv_aio_rw_vector(bs, sector_num, qiov, nb_sectors, cb, opaque, 1); 1433 return bdrv_aio_rw_vector(bs, sector_num, qiov, nb_sectors, cb, opaque, 1);
1427 } 1434 }
1428 1435
1429 -  
1430 -static void bdrv_aio_cancel_em(BlockDriverAIOCB *blockacb)  
1431 -{  
1432 - BlockDriverAIOCBSync *acb = (BlockDriverAIOCBSync *)blockacb;  
1433 - qemu_bh_cancel(acb->bh);  
1434 - qemu_aio_release(acb);  
1435 -}  
1436 -  
1437 /**************************************************************/ 1436 /**************************************************************/
1438 /* sync block device emulation */ 1437 /* sync block device emulation */
1439 1438
@@ -1495,16 +1494,8 @@ void bdrv_init(void) @@ -1495,16 +1494,8 @@ void bdrv_init(void)
1495 module_call_init(MODULE_INIT_BLOCK); 1494 module_call_init(MODULE_INIT_BLOCK);
1496 } 1495 }
1497 1496
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) 1497 +void *qemu_aio_get(AIOPool *pool, BlockDriverState *bs,
  1498 + BlockDriverCompletionFunc *cb, void *opaque)
1508 { 1499 {
1509 BlockDriverAIOCB *acb; 1500 BlockDriverAIOCB *acb;
1510 1501
@@ -1521,12 +1512,6 @@ void *qemu_aio_get_pool(AIOPool *pool, BlockDriverState *bs, @@ -1521,12 +1512,6 @@ void *qemu_aio_get_pool(AIOPool *pool, BlockDriverState *bs,
1521 return acb; 1512 return acb;
1522 } 1513 }
1523 1514
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 -  
1530 void qemu_aio_release(void *p) 1515 void qemu_aio_release(void *p)
1531 { 1516 {
1532 BlockDriverAIOCB *acb = (BlockDriverAIOCB *)p; 1517 BlockDriverAIOCB *acb = (BlockDriverAIOCB *)p;
block/curl.c
@@ -349,6 +349,16 @@ out_noclean: @@ -349,6 +349,16 @@ out_noclean:
349 return -EINVAL; 349 return -EINVAL;
350 } 350 }
351 351
  352 +static void curl_aio_cancel(BlockDriverAIOCB *blockacb)
  353 +{
  354 + // Do we have to implement canceling? Seems to work without...
  355 +}
  356 +
  357 +static AIOPool curl_aio_pool = {
  358 + .aiocb_size = sizeof(CURLAIOCB),
  359 + .cancel = curl_aio_cancel,
  360 +};
  361 +
352 static BlockDriverAIOCB *curl_aio_readv(BlockDriverState *bs, 362 static BlockDriverAIOCB *curl_aio_readv(BlockDriverState *bs,
353 int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, 363 int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
354 BlockDriverCompletionFunc *cb, void *opaque) 364 BlockDriverCompletionFunc *cb, void *opaque)
@@ -359,7 +369,7 @@ static BlockDriverAIOCB *curl_aio_readv(BlockDriverState *bs, @@ -359,7 +369,7 @@ static BlockDriverAIOCB *curl_aio_readv(BlockDriverState *bs,
359 size_t end; 369 size_t end;
360 CURLState *state; 370 CURLState *state;
361 371
362 - acb = qemu_aio_get(bs, cb, opaque); 372 + acb = qemu_aio_get(&curl_aio_pool, bs, cb, opaque);
363 if (!acb) 373 if (!acb)
364 return NULL; 374 return NULL;
365 375
@@ -406,11 +416,6 @@ static BlockDriverAIOCB *curl_aio_readv(BlockDriverState *bs, @@ -406,11 +416,6 @@ static BlockDriverAIOCB *curl_aio_readv(BlockDriverState *bs,
406 return &acb->common; 416 return &acb->common;
407 } 417 }
408 418
409 -static void curl_aio_cancel(BlockDriverAIOCB *blockacb)  
410 -{  
411 - // Do we have to implement canceling? Seems to work without...  
412 -}  
413 -  
414 static void curl_close(BlockDriverState *bs) 419 static void curl_close(BlockDriverState *bs)
415 { 420 {
416 BDRVCURLState *s = bs->opaque; 421 BDRVCURLState *s = bs->opaque;
@@ -450,9 +455,7 @@ static BlockDriver bdrv_http = { @@ -450,9 +455,7 @@ static BlockDriver bdrv_http = {
450 .bdrv_close = curl_close, 455 .bdrv_close = curl_close,
451 .bdrv_getlength = curl_getlength, 456 .bdrv_getlength = curl_getlength,
452 457
453 - .aiocb_size = sizeof(CURLAIOCB),  
454 .bdrv_aio_readv = curl_aio_readv, 458 .bdrv_aio_readv = curl_aio_readv,
455 - .bdrv_aio_cancel = curl_aio_cancel,  
456 }; 459 };
457 460
458 static BlockDriver bdrv_https = { 461 static BlockDriver bdrv_https = {
@@ -464,9 +467,7 @@ static BlockDriver bdrv_https = { @@ -464,9 +467,7 @@ static BlockDriver bdrv_https = {
464 .bdrv_close = curl_close, 467 .bdrv_close = curl_close,
465 .bdrv_getlength = curl_getlength, 468 .bdrv_getlength = curl_getlength,
466 469
467 - .aiocb_size = sizeof(CURLAIOCB),  
468 .bdrv_aio_readv = curl_aio_readv, 470 .bdrv_aio_readv = curl_aio_readv,
469 - .bdrv_aio_cancel = curl_aio_cancel,  
470 }; 471 };
471 472
472 static BlockDriver bdrv_ftp = { 473 static BlockDriver bdrv_ftp = {
@@ -478,9 +479,7 @@ static BlockDriver bdrv_ftp = { @@ -478,9 +479,7 @@ static BlockDriver bdrv_ftp = {
478 .bdrv_close = curl_close, 479 .bdrv_close = curl_close,
479 .bdrv_getlength = curl_getlength, 480 .bdrv_getlength = curl_getlength,
480 481
481 - .aiocb_size = sizeof(CURLAIOCB),  
482 .bdrv_aio_readv = curl_aio_readv, 482 .bdrv_aio_readv = curl_aio_readv,
483 - .bdrv_aio_cancel = curl_aio_cancel,  
484 }; 483 };
485 484
486 static BlockDriver bdrv_ftps = { 485 static BlockDriver bdrv_ftps = {
@@ -492,9 +491,7 @@ static BlockDriver bdrv_ftps = { @@ -492,9 +491,7 @@ static BlockDriver bdrv_ftps = {
492 .bdrv_close = curl_close, 491 .bdrv_close = curl_close,
493 .bdrv_getlength = curl_getlength, 492 .bdrv_getlength = curl_getlength,
494 493
495 - .aiocb_size = sizeof(CURLAIOCB),  
496 .bdrv_aio_readv = curl_aio_readv, 494 .bdrv_aio_readv = curl_aio_readv,
497 - .bdrv_aio_cancel = curl_aio_cancel,  
498 }; 495 };
499 496
500 static BlockDriver bdrv_tftp = { 497 static BlockDriver bdrv_tftp = {
@@ -506,9 +503,7 @@ static BlockDriver bdrv_tftp = { @@ -506,9 +503,7 @@ static BlockDriver bdrv_tftp = {
506 .bdrv_close = curl_close, 503 .bdrv_close = curl_close,
507 .bdrv_getlength = curl_getlength, 504 .bdrv_getlength = curl_getlength,
508 505
509 - .aiocb_size = sizeof(CURLAIOCB),  
510 .bdrv_aio_readv = curl_aio_readv, 506 .bdrv_aio_readv = curl_aio_readv,
511 - .bdrv_aio_cancel = curl_aio_cancel,  
512 }; 507 };
513 508
514 static void curl_block_init(void) 509 static void curl_block_init(void)
block/qcow.c
@@ -503,6 +503,18 @@ typedef struct QCowAIOCB { @@ -503,6 +503,18 @@ typedef struct QCowAIOCB {
503 BlockDriverAIOCB *hd_aiocb; 503 BlockDriverAIOCB *hd_aiocb;
504 } QCowAIOCB; 504 } QCowAIOCB;
505 505
  506 +static void qcow_aio_cancel(BlockDriverAIOCB *blockacb)
  507 +{
  508 + QCowAIOCB *acb = (QCowAIOCB *)blockacb;
  509 + if (acb->hd_aiocb)
  510 + bdrv_aio_cancel(acb->hd_aiocb);
  511 + qemu_aio_release(acb);
  512 +}
  513 +
  514 +static AIOPool qcow_aio_pool = {
  515 + .aiocb_size = sizeof(QCowAIOCB),
  516 + .cancel = qcow_aio_cancel,
  517 +};
506 518
507 static QCowAIOCB *qcow_aio_setup(BlockDriverState *bs, 519 static QCowAIOCB *qcow_aio_setup(BlockDriverState *bs,
508 int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, 520 int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
@@ -510,7 +522,7 @@ static QCowAIOCB *qcow_aio_setup(BlockDriverState *bs, @@ -510,7 +522,7 @@ static QCowAIOCB *qcow_aio_setup(BlockDriverState *bs,
510 { 522 {
511 QCowAIOCB *acb; 523 QCowAIOCB *acb;
512 524
513 - acb = qemu_aio_get(bs, cb, opaque); 525 + acb = qemu_aio_get(&qcow_aio_pool, bs, cb, opaque);
514 if (!acb) 526 if (!acb)
515 return NULL; 527 return NULL;
516 acb->hd_aiocb = NULL; 528 acb->hd_aiocb = NULL;
@@ -720,14 +732,6 @@ static BlockDriverAIOCB *qcow_aio_writev(BlockDriverState *bs, @@ -720,14 +732,6 @@ static BlockDriverAIOCB *qcow_aio_writev(BlockDriverState *bs,
720 return &acb->common; 732 return &acb->common;
721 } 733 }
722 734
723 -static void qcow_aio_cancel(BlockDriverAIOCB *blockacb)  
724 -{  
725 - QCowAIOCB *acb = (QCowAIOCB *)blockacb;  
726 - if (acb->hd_aiocb)  
727 - bdrv_aio_cancel(acb->hd_aiocb);  
728 - qemu_aio_release(acb);  
729 -}  
730 -  
731 static void qcow_close(BlockDriverState *bs) 735 static void qcow_close(BlockDriverState *bs)
732 { 736 {
733 BDRVQcowState *s = bs->opaque; 737 BDRVQcowState *s = bs->opaque;
@@ -924,8 +928,6 @@ static BlockDriver bdrv_qcow = { @@ -924,8 +928,6 @@ static BlockDriver bdrv_qcow = {
924 .bdrv_make_empty = qcow_make_empty, 928 .bdrv_make_empty = qcow_make_empty,
925 .bdrv_aio_readv = qcow_aio_readv, 929 .bdrv_aio_readv = qcow_aio_readv,
926 .bdrv_aio_writev = qcow_aio_writev, 930 .bdrv_aio_writev = qcow_aio_writev,
927 - .bdrv_aio_cancel = qcow_aio_cancel,  
928 - .aiocb_size = sizeof(QCowAIOCB),  
929 .bdrv_write_compressed = qcow_write_compressed, 931 .bdrv_write_compressed = qcow_write_compressed,
930 .bdrv_get_info = qcow_get_info, 932 .bdrv_get_info = qcow_get_info,
931 933
block/qcow2.c
@@ -1246,6 +1246,19 @@ typedef struct QCowAIOCB { @@ -1246,6 +1246,19 @@ typedef struct QCowAIOCB {
1246 QCowL2Meta l2meta; 1246 QCowL2Meta l2meta;
1247 } QCowAIOCB; 1247 } QCowAIOCB;
1248 1248
  1249 +static void qcow_aio_cancel(BlockDriverAIOCB *blockacb)
  1250 +{
  1251 + QCowAIOCB *acb = (QCowAIOCB *)blockacb;
  1252 + if (acb->hd_aiocb)
  1253 + bdrv_aio_cancel(acb->hd_aiocb);
  1254 + qemu_aio_release(acb);
  1255 +}
  1256 +
  1257 +static AIOPool qcow_aio_pool = {
  1258 + .aiocb_size = sizeof(QCowAIOCB),
  1259 + .cancel = qcow_aio_cancel,
  1260 +};
  1261 +
1249 static void qcow_aio_read_cb(void *opaque, int ret); 1262 static void qcow_aio_read_cb(void *opaque, int ret);
1250 static void qcow_aio_read_bh(void *opaque) 1263 static void qcow_aio_read_bh(void *opaque)
1251 { 1264 {
@@ -1375,7 +1388,7 @@ static QCowAIOCB *qcow_aio_setup(BlockDriverState *bs, @@ -1375,7 +1388,7 @@ static QCowAIOCB *qcow_aio_setup(BlockDriverState *bs,
1375 { 1388 {
1376 QCowAIOCB *acb; 1389 QCowAIOCB *acb;
1377 1390
1378 - acb = qemu_aio_get(bs, cb, opaque); 1391 + acb = qemu_aio_get(&qcow_aio_pool, bs, cb, opaque);
1379 if (!acb) 1392 if (!acb)
1380 return NULL; 1393 return NULL;
1381 acb->hd_aiocb = NULL; 1394 acb->hd_aiocb = NULL;
@@ -1498,14 +1511,6 @@ static BlockDriverAIOCB *qcow_aio_writev(BlockDriverState *bs, @@ -1498,14 +1511,6 @@ static BlockDriverAIOCB *qcow_aio_writev(BlockDriverState *bs,
1498 return &acb->common; 1511 return &acb->common;
1499 } 1512 }
1500 1513
1501 -static void qcow_aio_cancel(BlockDriverAIOCB *blockacb)  
1502 -{  
1503 - QCowAIOCB *acb = (QCowAIOCB *)blockacb;  
1504 - if (acb->hd_aiocb)  
1505 - bdrv_aio_cancel(acb->hd_aiocb);  
1506 - qemu_aio_release(acb);  
1507 -}  
1508 -  
1509 static void qcow_close(BlockDriverState *bs) 1514 static void qcow_close(BlockDriverState *bs)
1510 { 1515 {
1511 BDRVQcowState *s = bs->opaque; 1516 BDRVQcowState *s = bs->opaque;
@@ -2998,8 +3003,6 @@ static BlockDriver bdrv_qcow2 = { @@ -2998,8 +3003,6 @@ static BlockDriver bdrv_qcow2 = {
2998 3003
2999 .bdrv_aio_readv = qcow_aio_readv, 3004 .bdrv_aio_readv = qcow_aio_readv,
3000 .bdrv_aio_writev = qcow_aio_writev, 3005 .bdrv_aio_writev = qcow_aio_writev,
3001 - .bdrv_aio_cancel = qcow_aio_cancel,  
3002 - .aiocb_size = sizeof(QCowAIOCB),  
3003 .bdrv_write_compressed = qcow_write_compressed, 3006 .bdrv_write_compressed = qcow_write_compressed,
3004 3007
3005 .bdrv_snapshot_create = qcow_snapshot_create, 3008 .bdrv_snapshot_create = qcow_snapshot_create,
block/raw-posix.c
@@ -599,6 +599,45 @@ static int posix_aio_init(void) @@ -599,6 +599,45 @@ static int posix_aio_init(void)
599 return 0; 599 return 0;
600 } 600 }
601 601
  602 +static void raw_aio_remove(RawAIOCB *acb)
  603 +{
  604 + RawAIOCB **pacb;
  605 +
  606 + /* remove the callback from the queue */
  607 + pacb = &posix_aio_state->first_aio;
  608 + for(;;) {
  609 + if (*pacb == NULL) {
  610 + fprintf(stderr, "raw_aio_remove: aio request not found!\n");
  611 + break;
  612 + } else if (*pacb == acb) {
  613 + *pacb = acb->next;
  614 + qemu_aio_release(acb);
  615 + break;
  616 + }
  617 + pacb = &(*pacb)->next;
  618 + }
  619 +}
  620 +
  621 +static void raw_aio_cancel(BlockDriverAIOCB *blockacb)
  622 +{
  623 + int ret;
  624 + RawAIOCB *acb = (RawAIOCB *)blockacb;
  625 +
  626 + ret = qemu_paio_cancel(acb->aiocb.aio_fildes, &acb->aiocb);
  627 + if (ret == QEMU_PAIO_NOTCANCELED) {
  628 + /* fail safe: if the aio could not be canceled, we wait for
  629 + it */
  630 + while (qemu_paio_error(&acb->aiocb) == EINPROGRESS);
  631 + }
  632 +
  633 + raw_aio_remove(acb);
  634 +}
  635 +
  636 +static AIOPool raw_aio_pool = {
  637 + .aiocb_size = sizeof(RawAIOCB),
  638 + .cancel = raw_aio_cancel,
  639 +};
  640 +
602 static RawAIOCB *raw_aio_setup(BlockDriverState *bs, int64_t sector_num, 641 static RawAIOCB *raw_aio_setup(BlockDriverState *bs, int64_t sector_num,
603 QEMUIOVector *qiov, int nb_sectors, 642 QEMUIOVector *qiov, int nb_sectors,
604 BlockDriverCompletionFunc *cb, void *opaque) 643 BlockDriverCompletionFunc *cb, void *opaque)
@@ -609,7 +648,7 @@ static RawAIOCB *raw_aio_setup(BlockDriverState *bs, int64_t sector_num, @@ -609,7 +648,7 @@ static RawAIOCB *raw_aio_setup(BlockDriverState *bs, int64_t sector_num,
609 if (fd_open(bs) < 0) 648 if (fd_open(bs) < 0)
610 return NULL; 649 return NULL;
611 650
612 - acb = qemu_aio_get(bs, cb, opaque); 651 + acb = qemu_aio_get(&raw_aio_pool, bs, cb, opaque);
613 if (!acb) 652 if (!acb)
614 return NULL; 653 return NULL;
615 acb->aiocb.aio_fildes = s->fd; 654 acb->aiocb.aio_fildes = s->fd;
@@ -633,25 +672,6 @@ static RawAIOCB *raw_aio_setup(BlockDriverState *bs, int64_t sector_num, @@ -633,25 +672,6 @@ static RawAIOCB *raw_aio_setup(BlockDriverState *bs, int64_t sector_num,
633 return acb; 672 return acb;
634 } 673 }
635 674
636 -static void raw_aio_remove(RawAIOCB *acb)  
637 -{  
638 - RawAIOCB **pacb;  
639 -  
640 - /* remove the callback from the queue */  
641 - pacb = &posix_aio_state->first_aio;  
642 - for(;;) {  
643 - if (*pacb == NULL) {  
644 - fprintf(stderr, "raw_aio_remove: aio request not found!\n");  
645 - break;  
646 - } else if (*pacb == acb) {  
647 - *pacb = acb->next;  
648 - qemu_aio_release(acb);  
649 - break;  
650 - }  
651 - pacb = &(*pacb)->next;  
652 - }  
653 -}  
654 -  
655 static BlockDriverAIOCB *raw_aio_readv(BlockDriverState *bs, 675 static BlockDriverAIOCB *raw_aio_readv(BlockDriverState *bs,
656 int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, 676 int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
657 BlockDriverCompletionFunc *cb, void *opaque) 677 BlockDriverCompletionFunc *cb, void *opaque)
@@ -683,21 +703,6 @@ static BlockDriverAIOCB *raw_aio_writev(BlockDriverState *bs, @@ -683,21 +703,6 @@ static BlockDriverAIOCB *raw_aio_writev(BlockDriverState *bs,
683 } 703 }
684 return &acb->common; 704 return &acb->common;
685 } 705 }
686 -  
687 -static void raw_aio_cancel(BlockDriverAIOCB *blockacb)  
688 -{  
689 - int ret;  
690 - RawAIOCB *acb = (RawAIOCB *)blockacb;  
691 -  
692 - ret = qemu_paio_cancel(acb->aiocb.aio_fildes, &acb->aiocb);  
693 - if (ret == QEMU_PAIO_NOTCANCELED) {  
694 - /* fail safe: if the aio could not be canceled, we wait for  
695 - it */  
696 - while (qemu_paio_error(&acb->aiocb) == EINPROGRESS);  
697 - }  
698 -  
699 - raw_aio_remove(acb);  
700 -}  
701 #else /* CONFIG_AIO */ 706 #else /* CONFIG_AIO */
702 static int posix_aio_init(void) 707 static int posix_aio_init(void)
703 { 708 {
@@ -871,8 +876,6 @@ static BlockDriver bdrv_raw = { @@ -871,8 +876,6 @@ static BlockDriver bdrv_raw = {
871 #ifdef CONFIG_AIO 876 #ifdef CONFIG_AIO
872 .bdrv_aio_readv = raw_aio_readv, 877 .bdrv_aio_readv = raw_aio_readv,
873 .bdrv_aio_writev = raw_aio_writev, 878 .bdrv_aio_writev = raw_aio_writev,
874 - .bdrv_aio_cancel = raw_aio_cancel,  
875 - .aiocb_size = sizeof(RawAIOCB),  
876 #endif 879 #endif
877 880
878 .bdrv_truncate = raw_truncate, 881 .bdrv_truncate = raw_truncate,
@@ -1205,7 +1208,7 @@ static BlockDriverAIOCB *raw_aio_ioctl(BlockDriverState *bs, @@ -1205,7 +1208,7 @@ static BlockDriverAIOCB *raw_aio_ioctl(BlockDriverState *bs,
1205 if (fd_open(bs) < 0) 1208 if (fd_open(bs) < 0)
1206 return NULL; 1209 return NULL;
1207 1210
1208 - acb = qemu_aio_get(bs, cb, opaque); 1211 + acb = qemu_aio_get(&raw_aio_pool, bs, cb, opaque);
1209 if (!acb) 1212 if (!acb)
1210 return NULL; 1213 return NULL;
1211 acb->aiocb.aio_fildes = s->fd; 1214 acb->aiocb.aio_fildes = s->fd;
@@ -1417,8 +1420,6 @@ static BlockDriver bdrv_host_device = { @@ -1417,8 +1420,6 @@ static BlockDriver bdrv_host_device = {
1417 #ifdef CONFIG_AIO 1420 #ifdef CONFIG_AIO
1418 .bdrv_aio_readv = raw_aio_readv, 1421 .bdrv_aio_readv = raw_aio_readv,
1419 .bdrv_aio_writev = raw_aio_writev, 1422 .bdrv_aio_writev = raw_aio_writev,
1420 - .bdrv_aio_cancel = raw_aio_cancel,  
1421 - .aiocb_size = sizeof(RawAIOCB),  
1422 #endif 1423 #endif
1423 1424
1424 .bdrv_read = raw_read, 1425 .bdrv_read = raw_read,
block_int.h
@@ -67,8 +67,6 @@ struct BlockDriver { @@ -67,8 +67,6 @@ struct BlockDriver {
67 BlockDriverAIOCB *(*bdrv_aio_writev)(BlockDriverState *bs, 67 BlockDriverAIOCB *(*bdrv_aio_writev)(BlockDriverState *bs,
68 int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, 68 int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
69 BlockDriverCompletionFunc *cb, void *opaque); 69 BlockDriverCompletionFunc *cb, void *opaque);
70 - void (*bdrv_aio_cancel)(BlockDriverAIOCB *acb);  
71 - int aiocb_size;  
72 70
73 const char *protocol_name; 71 const char *protocol_name;
74 int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset); 72 int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset);
@@ -102,8 +100,6 @@ struct BlockDriver { @@ -102,8 +100,6 @@ struct BlockDriver {
102 unsigned long int req, void *buf, 100 unsigned long int req, void *buf,
103 BlockDriverCompletionFunc *cb, void *opaque); 101 BlockDriverCompletionFunc *cb, void *opaque);
104 102
105 - AIOPool aio_pool;  
106 -  
107 /* List of options for creating images, terminated by name == NULL */ 103 /* List of options for creating images, terminated by name == NULL */
108 QEMUOptionParameter *create_options; 104 QEMUOptionParameter *create_options;
109 105
@@ -173,13 +169,8 @@ struct BlockDriverAIOCB { @@ -173,13 +169,8 @@ struct BlockDriverAIOCB {
173 169
174 void get_tmp_filename(char *filename, int size); 170 void get_tmp_filename(char *filename, int size);
175 171
176 -void aio_pool_init(AIOPool *pool, int aiocb_size,  
177 - void (*cancel)(BlockDriverAIOCB *acb));  
178 -  
179 -void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb,  
180 - void *opaque);  
181 -void *qemu_aio_get_pool(AIOPool *pool, BlockDriverState *bs,  
182 - BlockDriverCompletionFunc *cb, void *opaque); 172 +void *qemu_aio_get(AIOPool *pool, BlockDriverState *bs,
  173 + BlockDriverCompletionFunc *cb, void *opaque);
183 void qemu_aio_release(void *p); 174 void qemu_aio_release(void *p);
184 175
185 void *qemu_blockalign(BlockDriverState *bs, size_t size); 176 void *qemu_blockalign(BlockDriverState *bs, size_t size);
dma-helpers.c
@@ -10,8 +10,6 @@ @@ -10,8 +10,6 @@
10 #include "dma.h" 10 #include "dma.h"
11 #include "block_int.h" 11 #include "block_int.h"
12 12
13 -static AIOPool dma_aio_pool;  
14 -  
15 void qemu_sglist_init(QEMUSGList *qsg, int alloc_hint) 13 void qemu_sglist_init(QEMUSGList *qsg, int alloc_hint)
16 { 14 {
17 qsg->sg = qemu_malloc(alloc_hint * sizeof(ScatterGatherEntry)); 15 qsg->sg = qemu_malloc(alloc_hint * sizeof(ScatterGatherEntry));
@@ -132,12 +130,26 @@ static void dma_bdrv_cb(void *opaque, int ret) @@ -132,12 +130,26 @@ static void dma_bdrv_cb(void *opaque, int ret)
132 } 130 }
133 } 131 }
134 132
  133 +static void dma_aio_cancel(BlockDriverAIOCB *acb)
  134 +{
  135 + DMAAIOCB *dbs = container_of(acb, DMAAIOCB, common);
  136 +
  137 + if (dbs->acb) {
  138 + bdrv_aio_cancel(dbs->acb);
  139 + }
  140 +}
  141 +
  142 +static AIOPool dma_aio_pool = {
  143 + .aiocb_size = sizeof(DMAAIOCB),
  144 + .cancel = dma_aio_cancel,
  145 +};
  146 +
135 static BlockDriverAIOCB *dma_bdrv_io( 147 static BlockDriverAIOCB *dma_bdrv_io(
136 BlockDriverState *bs, QEMUSGList *sg, uint64_t sector_num, 148 BlockDriverState *bs, QEMUSGList *sg, uint64_t sector_num,
137 BlockDriverCompletionFunc *cb, void *opaque, 149 BlockDriverCompletionFunc *cb, void *opaque,
138 int is_write) 150 int is_write)
139 { 151 {
140 - DMAAIOCB *dbs = qemu_aio_get_pool(&dma_aio_pool, bs, cb, opaque); 152 + DMAAIOCB *dbs = qemu_aio_get(&dma_aio_pool, bs, cb, opaque);
141 153
142 dbs->acb = NULL; 154 dbs->acb = NULL;
143 dbs->bs = bs; 155 dbs->bs = bs;
@@ -170,17 +182,3 @@ BlockDriverAIOCB *dma_bdrv_write(BlockDriverState *bs, @@ -170,17 +182,3 @@ BlockDriverAIOCB *dma_bdrv_write(BlockDriverState *bs,
170 { 182 {
171 return dma_bdrv_io(bs, sg, sector, cb, opaque, 1); 183 return dma_bdrv_io(bs, sg, sector, cb, opaque, 1);
172 } 184 }
173 -  
174 -static void dma_aio_cancel(BlockDriverAIOCB *acb)  
175 -{  
176 - DMAAIOCB *dbs = container_of(acb, DMAAIOCB, common);  
177 -  
178 - if (dbs->acb) {  
179 - bdrv_aio_cancel(dbs->acb);  
180 - }  
181 -}  
182 -  
183 -void dma_helper_init(void)  
184 -{  
185 - aio_pool_init(&dma_aio_pool, sizeof(DMAAIOCB), dma_aio_cancel);  
186 -}  
@@ -38,6 +38,4 @@ BlockDriverAIOCB *dma_bdrv_read(BlockDriverState *bs, @@ -38,6 +38,4 @@ BlockDriverAIOCB *dma_bdrv_read(BlockDriverState *bs,
38 BlockDriverAIOCB *dma_bdrv_write(BlockDriverState *bs, 38 BlockDriverAIOCB *dma_bdrv_write(BlockDriverState *bs,
39 QEMUSGList *sg, uint64_t sector, 39 QEMUSGList *sg, uint64_t sector,
40 BlockDriverCompletionFunc *cb, void *opaque); 40 BlockDriverCompletionFunc *cb, void *opaque);
41 -void dma_helper_init(void);  
42 -  
43 #endif 41 #endif
@@ -5753,7 +5753,6 @@ int main(int argc, char **argv, char **envp) @@ -5753,7 +5753,6 @@ int main(int argc, char **argv, char **envp)
5753 cpu_exec_init_all(tb_size * 1024 * 1024); 5753 cpu_exec_init_all(tb_size * 1024 * 1024);
5754 5754
5755 bdrv_init(); 5755 bdrv_init();
5756 - dma_helper_init();  
5757 5756
5758 /* we always create the cdrom drive, even if no disk is there */ 5757 /* we always create the cdrom drive, even if no disk is there */
5759 5758