Commit c87c0672936a5b825c0b95bb1d7f5d6dc92294e4
1 parent
f1b2f712
remove bdrv_aio_read/bdrv_aio_write (Christoph Hellwig)
Always use the vectored APIs to reduce code churn once we switch the BlockDriver API to be vectored. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@7019 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
6 changed files
with
119 additions
and
90 deletions
block-qcow.c
| @@ -530,6 +530,8 @@ typedef struct QCowAIOCB { | @@ -530,6 +530,8 @@ typedef struct QCowAIOCB { | ||
| 530 | int n; | 530 | int n; |
| 531 | uint64_t cluster_offset; | 531 | uint64_t cluster_offset; |
| 532 | uint8_t *cluster_data; | 532 | uint8_t *cluster_data; |
| 533 | + struct iovec hd_iov; | ||
| 534 | + QEMUIOVector hd_qiov; | ||
| 533 | BlockDriverAIOCB *hd_aiocb; | 535 | BlockDriverAIOCB *hd_aiocb; |
| 534 | } QCowAIOCB; | 536 | } QCowAIOCB; |
| 535 | 537 | ||
| @@ -584,8 +586,11 @@ static void qcow_aio_read_cb(void *opaque, int ret) | @@ -584,8 +586,11 @@ static void qcow_aio_read_cb(void *opaque, int ret) | ||
| 584 | if (!acb->cluster_offset) { | 586 | if (!acb->cluster_offset) { |
| 585 | if (bs->backing_hd) { | 587 | if (bs->backing_hd) { |
| 586 | /* read from the base image */ | 588 | /* read from the base image */ |
| 587 | - acb->hd_aiocb = bdrv_aio_read(bs->backing_hd, | ||
| 588 | - acb->sector_num, acb->buf, acb->n, qcow_aio_read_cb, acb); | 589 | + acb->hd_iov.iov_base = acb->buf; |
| 590 | + acb->hd_iov.iov_len = acb->n * 512; | ||
| 591 | + qemu_iovec_init_external(&acb->hd_qiov, &acb->hd_iov, 1); | ||
| 592 | + acb->hd_aiocb = bdrv_aio_readv(bs->backing_hd, acb->sector_num, | ||
| 593 | + &acb->hd_qiov, acb->n, qcow_aio_read_cb, acb); | ||
| 589 | if (acb->hd_aiocb == NULL) | 594 | if (acb->hd_aiocb == NULL) |
| 590 | goto fail; | 595 | goto fail; |
| 591 | } else { | 596 | } else { |
| @@ -605,9 +610,12 @@ static void qcow_aio_read_cb(void *opaque, int ret) | @@ -605,9 +610,12 @@ static void qcow_aio_read_cb(void *opaque, int ret) | ||
| 605 | ret = -EIO; | 610 | ret = -EIO; |
| 606 | goto fail; | 611 | goto fail; |
| 607 | } | 612 | } |
| 608 | - acb->hd_aiocb = bdrv_aio_read(s->hd, | 613 | + acb->hd_iov.iov_base = acb->buf; |
| 614 | + acb->hd_iov.iov_len = acb->n * 512; | ||
| 615 | + qemu_iovec_init_external(&acb->hd_qiov, &acb->hd_iov, 1); | ||
| 616 | + acb->hd_aiocb = bdrv_aio_readv(s->hd, | ||
| 609 | (acb->cluster_offset >> 9) + index_in_cluster, | 617 | (acb->cluster_offset >> 9) + index_in_cluster, |
| 610 | - acb->buf, acb->n, qcow_aio_read_cb, acb); | 618 | + &acb->hd_qiov, acb->n, qcow_aio_read_cb, acb); |
| 611 | if (acb->hd_aiocb == NULL) | 619 | if (acb->hd_aiocb == NULL) |
| 612 | goto fail; | 620 | goto fail; |
| 613 | } | 621 | } |
| @@ -687,10 +695,14 @@ static void qcow_aio_write_cb(void *opaque, int ret) | @@ -687,10 +695,14 @@ static void qcow_aio_write_cb(void *opaque, int ret) | ||
| 687 | } else { | 695 | } else { |
| 688 | src_buf = acb->buf; | 696 | src_buf = acb->buf; |
| 689 | } | 697 | } |
| 690 | - acb->hd_aiocb = bdrv_aio_write(s->hd, | ||
| 691 | - (cluster_offset >> 9) + index_in_cluster, | ||
| 692 | - src_buf, acb->n, | ||
| 693 | - qcow_aio_write_cb, acb); | 698 | + |
| 699 | + acb->hd_iov.iov_base = (void *)src_buf; | ||
| 700 | + acb->hd_iov.iov_len = acb->n * 512; | ||
| 701 | + qemu_iovec_init_external(&acb->hd_qiov, &acb->hd_iov, 1); | ||
| 702 | + acb->hd_aiocb = bdrv_aio_writev(s->hd, | ||
| 703 | + (cluster_offset >> 9) + index_in_cluster, | ||
| 704 | + &acb->hd_qiov, acb->n, | ||
| 705 | + qcow_aio_write_cb, acb); | ||
| 694 | if (acb->hd_aiocb == NULL) | 706 | if (acb->hd_aiocb == NULL) |
| 695 | goto fail; | 707 | goto fail; |
| 696 | } | 708 | } |
block-qcow2.c
| @@ -1270,6 +1270,8 @@ typedef struct QCowAIOCB { | @@ -1270,6 +1270,8 @@ typedef struct QCowAIOCB { | ||
| 1270 | uint64_t cluster_offset; | 1270 | uint64_t cluster_offset; |
| 1271 | uint8_t *cluster_data; | 1271 | uint8_t *cluster_data; |
| 1272 | BlockDriverAIOCB *hd_aiocb; | 1272 | BlockDriverAIOCB *hd_aiocb; |
| 1273 | + struct iovec hd_iov; | ||
| 1274 | + QEMUIOVector hd_qiov; | ||
| 1273 | QEMUBH *bh; | 1275 | QEMUBH *bh; |
| 1274 | QCowL2Meta l2meta; | 1276 | QCowL2Meta l2meta; |
| 1275 | } QCowAIOCB; | 1277 | } QCowAIOCB; |
| @@ -1347,8 +1349,12 @@ fail: | @@ -1347,8 +1349,12 @@ fail: | ||
| 1347 | n1 = backing_read1(bs->backing_hd, acb->sector_num, | 1349 | n1 = backing_read1(bs->backing_hd, acb->sector_num, |
| 1348 | acb->buf, acb->n); | 1350 | acb->buf, acb->n); |
| 1349 | if (n1 > 0) { | 1351 | if (n1 > 0) { |
| 1350 | - acb->hd_aiocb = bdrv_aio_read(bs->backing_hd, acb->sector_num, | ||
| 1351 | - acb->buf, acb->n, qcow_aio_read_cb, acb); | 1352 | + acb->hd_iov.iov_base = acb->buf; |
| 1353 | + acb->hd_iov.iov_len = acb->n * 512; | ||
| 1354 | + qemu_iovec_init_external(&acb->hd_qiov, &acb->hd_iov, 1); | ||
| 1355 | + acb->hd_aiocb = bdrv_aio_readv(bs->backing_hd, acb->sector_num, | ||
| 1356 | + &acb->hd_qiov, acb->n, | ||
| 1357 | + qcow_aio_read_cb, acb); | ||
| 1352 | if (acb->hd_aiocb == NULL) | 1358 | if (acb->hd_aiocb == NULL) |
| 1353 | goto fail; | 1359 | goto fail; |
| 1354 | } else { | 1360 | } else { |
| @@ -1377,9 +1383,13 @@ fail: | @@ -1377,9 +1383,13 @@ fail: | ||
| 1377 | ret = -EIO; | 1383 | ret = -EIO; |
| 1378 | goto fail; | 1384 | goto fail; |
| 1379 | } | 1385 | } |
| 1380 | - acb->hd_aiocb = bdrv_aio_read(s->hd, | 1386 | + |
| 1387 | + acb->hd_iov.iov_base = acb->buf; | ||
| 1388 | + acb->hd_iov.iov_len = acb->n * 512; | ||
| 1389 | + qemu_iovec_init_external(&acb->hd_qiov, &acb->hd_iov, 1); | ||
| 1390 | + acb->hd_aiocb = bdrv_aio_readv(s->hd, | ||
| 1381 | (acb->cluster_offset >> 9) + index_in_cluster, | 1391 | (acb->cluster_offset >> 9) + index_in_cluster, |
| 1382 | - acb->buf, acb->n, qcow_aio_read_cb, acb); | 1392 | + &acb->hd_qiov, acb->n, qcow_aio_read_cb, acb); |
| 1383 | if (acb->hd_aiocb == NULL) | 1393 | if (acb->hd_aiocb == NULL) |
| 1384 | goto fail; | 1394 | goto fail; |
| 1385 | } | 1395 | } |
| @@ -1476,10 +1486,13 @@ static void qcow_aio_write_cb(void *opaque, int ret) | @@ -1476,10 +1486,13 @@ static void qcow_aio_write_cb(void *opaque, int ret) | ||
| 1476 | } else { | 1486 | } else { |
| 1477 | src_buf = acb->buf; | 1487 | src_buf = acb->buf; |
| 1478 | } | 1488 | } |
| 1479 | - acb->hd_aiocb = bdrv_aio_write(s->hd, | ||
| 1480 | - (acb->cluster_offset >> 9) + index_in_cluster, | ||
| 1481 | - src_buf, acb->n, | ||
| 1482 | - qcow_aio_write_cb, acb); | 1489 | + acb->hd_iov.iov_base = (void *)src_buf; |
| 1490 | + acb->hd_iov.iov_len = acb->n * 512; | ||
| 1491 | + qemu_iovec_init_external(&acb->hd_qiov, &acb->hd_iov, 1); | ||
| 1492 | + acb->hd_aiocb = bdrv_aio_writev(s->hd, | ||
| 1493 | + (acb->cluster_offset >> 9) + index_in_cluster, | ||
| 1494 | + &acb->hd_qiov, acb->n, | ||
| 1495 | + qcow_aio_write_cb, acb); | ||
| 1483 | if (acb->hd_aiocb == NULL) | 1496 | if (acb->hd_aiocb == NULL) |
| 1484 | goto fail; | 1497 | goto fail; |
| 1485 | } | 1498 | } |
block.c
| @@ -55,6 +55,12 @@ typedef struct BlockDriverAIOCBSync { | @@ -55,6 +55,12 @@ typedef struct BlockDriverAIOCBSync { | ||
| 55 | int ret; | 55 | int ret; |
| 56 | } BlockDriverAIOCBSync; | 56 | } BlockDriverAIOCBSync; |
| 57 | 57 | ||
| 58 | +static BlockDriverAIOCB *bdrv_aio_read(BlockDriverState *bs, | ||
| 59 | + int64_t sector_num, uint8_t *buf, int nb_sectors, | ||
| 60 | + BlockDriverCompletionFunc *cb, void *opaque); | ||
| 61 | +static BlockDriverAIOCB *bdrv_aio_write(BlockDriverState *bs, | ||
| 62 | + int64_t sector_num, const uint8_t *buf, int nb_sectors, | ||
| 63 | + BlockDriverCompletionFunc *cb, void *opaque); | ||
| 58 | static BlockDriverAIOCB *bdrv_aio_read_em(BlockDriverState *bs, | 64 | static BlockDriverAIOCB *bdrv_aio_read_em(BlockDriverState *bs, |
| 59 | int64_t sector_num, uint8_t *buf, int nb_sectors, | 65 | int64_t sector_num, uint8_t *buf, int nb_sectors, |
| 60 | BlockDriverCompletionFunc *cb, void *opaque); | 66 | BlockDriverCompletionFunc *cb, void *opaque); |
| @@ -1370,7 +1376,7 @@ BlockDriverAIOCB *bdrv_aio_writev(BlockDriverState *bs, int64_t sector_num, | @@ -1370,7 +1376,7 @@ BlockDriverAIOCB *bdrv_aio_writev(BlockDriverState *bs, int64_t sector_num, | ||
| 1370 | cb, opaque, 1); | 1376 | cb, opaque, 1); |
| 1371 | } | 1377 | } |
| 1372 | 1378 | ||
| 1373 | -BlockDriverAIOCB *bdrv_aio_read(BlockDriverState *bs, int64_t sector_num, | 1379 | +static BlockDriverAIOCB *bdrv_aio_read(BlockDriverState *bs, int64_t sector_num, |
| 1374 | uint8_t *buf, int nb_sectors, | 1380 | uint8_t *buf, int nb_sectors, |
| 1375 | BlockDriverCompletionFunc *cb, void *opaque) | 1381 | BlockDriverCompletionFunc *cb, void *opaque) |
| 1376 | { | 1382 | { |
| @@ -1393,7 +1399,7 @@ BlockDriverAIOCB *bdrv_aio_read(BlockDriverState *bs, int64_t sector_num, | @@ -1393,7 +1399,7 @@ BlockDriverAIOCB *bdrv_aio_read(BlockDriverState *bs, int64_t sector_num, | ||
| 1393 | return ret; | 1399 | return ret; |
| 1394 | } | 1400 | } |
| 1395 | 1401 | ||
| 1396 | -BlockDriverAIOCB *bdrv_aio_write(BlockDriverState *bs, int64_t sector_num, | 1402 | +static BlockDriverAIOCB *bdrv_aio_write(BlockDriverState *bs, int64_t sector_num, |
| 1397 | const uint8_t *buf, int nb_sectors, | 1403 | const uint8_t *buf, int nb_sectors, |
| 1398 | BlockDriverCompletionFunc *cb, void *opaque) | 1404 | BlockDriverCompletionFunc *cb, void *opaque) |
| 1399 | { | 1405 | { |
block.h
| @@ -96,13 +96,6 @@ BlockDriverAIOCB *bdrv_aio_readv(BlockDriverState *bs, int64_t sector_num, | @@ -96,13 +96,6 @@ BlockDriverAIOCB *bdrv_aio_readv(BlockDriverState *bs, int64_t sector_num, | ||
| 96 | BlockDriverAIOCB *bdrv_aio_writev(BlockDriverState *bs, int64_t sector_num, | 96 | BlockDriverAIOCB *bdrv_aio_writev(BlockDriverState *bs, int64_t sector_num, |
| 97 | QEMUIOVector *iov, int nb_sectors, | 97 | QEMUIOVector *iov, int nb_sectors, |
| 98 | BlockDriverCompletionFunc *cb, void *opaque); | 98 | BlockDriverCompletionFunc *cb, void *opaque); |
| 99 | - | ||
| 100 | -BlockDriverAIOCB *bdrv_aio_read(BlockDriverState *bs, int64_t sector_num, | ||
| 101 | - uint8_t *buf, int nb_sectors, | ||
| 102 | - BlockDriverCompletionFunc *cb, void *opaque); | ||
| 103 | -BlockDriverAIOCB *bdrv_aio_write(BlockDriverState *bs, int64_t sector_num, | ||
| 104 | - const uint8_t *buf, int nb_sectors, | ||
| 105 | - BlockDriverCompletionFunc *cb, void *opaque); | ||
| 106 | void bdrv_aio_cancel(BlockDriverAIOCB *acb); | 99 | void bdrv_aio_cancel(BlockDriverAIOCB *acb); |
| 107 | 100 | ||
| 108 | /* sg packet commands */ | 101 | /* sg packet commands */ |
hw/ide.c
| @@ -496,6 +496,8 @@ typedef struct BMDMAState { | @@ -496,6 +496,8 @@ typedef struct BMDMAState { | ||
| 496 | IDEState *ide_if; | 496 | IDEState *ide_if; |
| 497 | BlockDriverCompletionFunc *dma_cb; | 497 | BlockDriverCompletionFunc *dma_cb; |
| 498 | BlockDriverAIOCB *aiocb; | 498 | BlockDriverAIOCB *aiocb; |
| 499 | + struct iovec iov; | ||
| 500 | + QEMUIOVector qiov; | ||
| 499 | int64_t sector_num; | 501 | int64_t sector_num; |
| 500 | uint32_t nsector; | 502 | uint32_t nsector; |
| 501 | } BMDMAState; | 503 | } BMDMAState; |
| @@ -1467,9 +1469,11 @@ static void ide_atapi_cmd_read_dma_cb(void *opaque, int ret) | @@ -1467,9 +1469,11 @@ static void ide_atapi_cmd_read_dma_cb(void *opaque, int ret) | ||
| 1467 | #ifdef DEBUG_AIO | 1469 | #ifdef DEBUG_AIO |
| 1468 | printf("aio_read_cd: lba=%u n=%d\n", s->lba, n); | 1470 | printf("aio_read_cd: lba=%u n=%d\n", s->lba, n); |
| 1469 | #endif | 1471 | #endif |
| 1470 | - bm->aiocb = bdrv_aio_read(s->bs, (int64_t)s->lba << 2, | ||
| 1471 | - s->io_buffer + data_offset, n * 4, | ||
| 1472 | - ide_atapi_cmd_read_dma_cb, bm); | 1472 | + bm->iov.iov_base = s->io_buffer + data_offset; |
| 1473 | + bm->iov.iov_len = n * 4 * 512; | ||
| 1474 | + qemu_iovec_init_external(&bm->qiov, &bm->iov, 1); | ||
| 1475 | + bm->aiocb = bdrv_aio_readv(s->bs, (int64_t)s->lba << 2, &bm->qiov, | ||
| 1476 | + n * 4, ide_atapi_cmd_read_dma_cb, bm); | ||
| 1473 | if (!bm->aiocb) { | 1477 | if (!bm->aiocb) { |
| 1474 | /* Note: media not present is the most likely case */ | 1478 | /* Note: media not present is the most likely case */ |
| 1475 | ide_atapi_cmd_error(s, SENSE_NOT_READY, | 1479 | ide_atapi_cmd_error(s, SENSE_NOT_READY, |
hw/scsi-disk.c
| @@ -52,9 +52,8 @@ typedef struct SCSIRequest { | @@ -52,9 +52,8 @@ typedef struct SCSIRequest { | ||
| 52 | /* Both sector and sector_count are in terms of qemu 512 byte blocks. */ | 52 | /* Both sector and sector_count are in terms of qemu 512 byte blocks. */ |
| 53 | uint64_t sector; | 53 | uint64_t sector; |
| 54 | uint32_t sector_count; | 54 | uint32_t sector_count; |
| 55 | - /* The amounnt of data in the buffer. */ | ||
| 56 | - int buf_len; | ||
| 57 | - uint8_t *dma_buf; | 55 | + struct iovec iov; |
| 56 | + QEMUIOVector qiov; | ||
| 58 | BlockDriverAIOCB *aiocb; | 57 | BlockDriverAIOCB *aiocb; |
| 59 | struct SCSIRequest *next; | 58 | struct SCSIRequest *next; |
| 60 | uint32_t status; | 59 | uint32_t status; |
| @@ -89,12 +88,12 @@ static SCSIRequest *scsi_new_request(SCSIDeviceState *s, uint32_t tag) | @@ -89,12 +88,12 @@ static SCSIRequest *scsi_new_request(SCSIDeviceState *s, uint32_t tag) | ||
| 89 | free_requests = r->next; | 88 | free_requests = r->next; |
| 90 | } else { | 89 | } else { |
| 91 | r = qemu_malloc(sizeof(SCSIRequest)); | 90 | r = qemu_malloc(sizeof(SCSIRequest)); |
| 92 | - r->dma_buf = qemu_memalign(512, SCSI_DMA_BUF_SIZE); | 91 | + r->iov.iov_base = qemu_memalign(512, SCSI_DMA_BUF_SIZE); |
| 93 | } | 92 | } |
| 94 | r->dev = s; | 93 | r->dev = s; |
| 95 | r->tag = tag; | 94 | r->tag = tag; |
| 96 | r->sector_count = 0; | 95 | r->sector_count = 0; |
| 97 | - r->buf_len = 0; | 96 | + r->iov.iov_len = 0; |
| 98 | r->aiocb = NULL; | 97 | r->aiocb = NULL; |
| 99 | r->status = 0; | 98 | r->status = 0; |
| 100 | 99 | ||
| @@ -173,9 +172,9 @@ static void scsi_read_complete(void * opaque, int ret) | @@ -173,9 +172,9 @@ static void scsi_read_complete(void * opaque, int ret) | ||
| 173 | scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_NO_SENSE); | 172 | scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_NO_SENSE); |
| 174 | return; | 173 | return; |
| 175 | } | 174 | } |
| 176 | - DPRINTF("Data ready tag=0x%x len=%d\n", r->tag, r->buf_len); | 175 | + DPRINTF("Data ready tag=0x%x len=%d\n", r->tag, r->iov.iov_len); |
| 177 | 176 | ||
| 178 | - s->completion(s->opaque, SCSI_REASON_DATA, r->tag, r->buf_len); | 177 | + s->completion(s->opaque, SCSI_REASON_DATA, r->tag, r->iov.iov_len); |
| 179 | } | 178 | } |
| 180 | 179 | ||
| 181 | /* Read more data from scsi device into buffer. */ | 180 | /* Read more data from scsi device into buffer. */ |
| @@ -193,9 +192,9 @@ static void scsi_read_data(SCSIDevice *d, uint32_t tag) | @@ -193,9 +192,9 @@ static void scsi_read_data(SCSIDevice *d, uint32_t tag) | ||
| 193 | return; | 192 | return; |
| 194 | } | 193 | } |
| 195 | if (r->sector_count == (uint32_t)-1) { | 194 | if (r->sector_count == (uint32_t)-1) { |
| 196 | - DPRINTF("Read buf_len=%d\n", r->buf_len); | 195 | + DPRINTF("Read buf_len=%d\n", r->iov.iov_len); |
| 197 | r->sector_count = 0; | 196 | r->sector_count = 0; |
| 198 | - s->completion(s->opaque, SCSI_REASON_DATA, r->tag, r->buf_len); | 197 | + s->completion(s->opaque, SCSI_REASON_DATA, r->tag, r->iov.iov_len); |
| 199 | return; | 198 | return; |
| 200 | } | 199 | } |
| 201 | DPRINTF("Read sector_count=%d\n", r->sector_count); | 200 | DPRINTF("Read sector_count=%d\n", r->sector_count); |
| @@ -208,9 +207,10 @@ static void scsi_read_data(SCSIDevice *d, uint32_t tag) | @@ -208,9 +207,10 @@ static void scsi_read_data(SCSIDevice *d, uint32_t tag) | ||
| 208 | if (n > SCSI_DMA_BUF_SIZE / 512) | 207 | if (n > SCSI_DMA_BUF_SIZE / 512) |
| 209 | n = SCSI_DMA_BUF_SIZE / 512; | 208 | n = SCSI_DMA_BUF_SIZE / 512; |
| 210 | 209 | ||
| 211 | - r->buf_len = n * 512; | ||
| 212 | - r->aiocb = bdrv_aio_read(s->bdrv, r->sector, r->dma_buf, n, | ||
| 213 | - scsi_read_complete, r); | 210 | + r->iov.iov_len = n * 512; |
| 211 | + qemu_iovec_init_external(&r->qiov, &r->iov, 1); | ||
| 212 | + r->aiocb = bdrv_aio_readv(s->bdrv, r->sector, &r->qiov, n, | ||
| 213 | + scsi_read_complete, r); | ||
| 214 | if (r->aiocb == NULL) | 214 | if (r->aiocb == NULL) |
| 215 | scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_HARDWARE_ERROR); | 215 | scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_HARDWARE_ERROR); |
| 216 | r->sector += n; | 216 | r->sector += n; |
| @@ -250,7 +250,7 @@ static void scsi_write_complete(void * opaque, int ret) | @@ -250,7 +250,7 @@ static void scsi_write_complete(void * opaque, int ret) | ||
| 250 | return; | 250 | return; |
| 251 | } | 251 | } |
| 252 | 252 | ||
| 253 | - n = r->buf_len / 512; | 253 | + n = r->iov.iov_len / 512; |
| 254 | r->sector += n; | 254 | r->sector += n; |
| 255 | r->sector_count -= n; | 255 | r->sector_count -= n; |
| 256 | if (r->sector_count == 0) { | 256 | if (r->sector_count == 0) { |
| @@ -260,7 +260,7 @@ static void scsi_write_complete(void * opaque, int ret) | @@ -260,7 +260,7 @@ static void scsi_write_complete(void * opaque, int ret) | ||
| 260 | if (len > SCSI_DMA_BUF_SIZE) { | 260 | if (len > SCSI_DMA_BUF_SIZE) { |
| 261 | len = SCSI_DMA_BUF_SIZE; | 261 | len = SCSI_DMA_BUF_SIZE; |
| 262 | } | 262 | } |
| 263 | - r->buf_len = len; | 263 | + r->iov.iov_len = len; |
| 264 | DPRINTF("Write complete tag=0x%x more=%d\n", r->tag, len); | 264 | DPRINTF("Write complete tag=0x%x more=%d\n", r->tag, len); |
| 265 | s->completion(s->opaque, SCSI_REASON_DATA, r->tag, len); | 265 | s->completion(s->opaque, SCSI_REASON_DATA, r->tag, len); |
| 266 | } | 266 | } |
| @@ -271,10 +271,11 @@ static void scsi_write_request(SCSIRequest *r) | @@ -271,10 +271,11 @@ static void scsi_write_request(SCSIRequest *r) | ||
| 271 | SCSIDeviceState *s = r->dev; | 271 | SCSIDeviceState *s = r->dev; |
| 272 | uint32_t n; | 272 | uint32_t n; |
| 273 | 273 | ||
| 274 | - n = r->buf_len / 512; | 274 | + n = r->iov.iov_len / 512; |
| 275 | if (n) { | 275 | if (n) { |
| 276 | - r->aiocb = bdrv_aio_write(s->bdrv, r->sector, r->dma_buf, n, | ||
| 277 | - scsi_write_complete, r); | 276 | + qemu_iovec_init_external(&r->qiov, &r->iov, 1); |
| 277 | + r->aiocb = bdrv_aio_writev(s->bdrv, r->sector, &r->qiov, n, | ||
| 278 | + scsi_write_complete, r); | ||
| 278 | if (r->aiocb == NULL) | 279 | if (r->aiocb == NULL) |
| 279 | scsi_command_complete(r, STATUS_CHECK_CONDITION, | 280 | scsi_command_complete(r, STATUS_CHECK_CONDITION, |
| 280 | SENSE_HARDWARE_ERROR); | 281 | SENSE_HARDWARE_ERROR); |
| @@ -334,7 +335,7 @@ static uint8_t *scsi_get_buf(SCSIDevice *d, uint32_t tag) | @@ -334,7 +335,7 @@ static uint8_t *scsi_get_buf(SCSIDevice *d, uint32_t tag) | ||
| 334 | BADF("Bad buffer tag 0x%x\n", tag); | 335 | BADF("Bad buffer tag 0x%x\n", tag); |
| 335 | return NULL; | 336 | return NULL; |
| 336 | } | 337 | } |
| 337 | - return r->dma_buf; | 338 | + return r->iov.iov_base; |
| 338 | } | 339 | } |
| 339 | 340 | ||
| 340 | /* Execute a scsi command. Returns the length of the data expected by the | 341 | /* Execute a scsi command. Returns the length of the data expected by the |
| @@ -364,7 +365,7 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, | @@ -364,7 +365,7 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, | ||
| 364 | /* ??? Tags are not unique for different luns. We only implement a | 365 | /* ??? Tags are not unique for different luns. We only implement a |
| 365 | single lun, so this should not matter. */ | 366 | single lun, so this should not matter. */ |
| 366 | r = scsi_new_request(s, tag); | 367 | r = scsi_new_request(s, tag); |
| 367 | - outbuf = r->dma_buf; | 368 | + outbuf = r->iov.iov_base; |
| 368 | is_write = 0; | 369 | is_write = 0; |
| 369 | DPRINTF("Command: lun=%d tag=0x%x data=0x%02x", lun, tag, buf[0]); | 370 | DPRINTF("Command: lun=%d tag=0x%x data=0x%02x", lun, tag, buf[0]); |
| 370 | switch (command >> 5) { | 371 | switch (command >> 5) { |
| @@ -425,10 +426,10 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, | @@ -425,10 +426,10 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, | ||
| 425 | if (len < 4) | 426 | if (len < 4) |
| 426 | goto fail; | 427 | goto fail; |
| 427 | memset(outbuf, 0, 4); | 428 | memset(outbuf, 0, 4); |
| 428 | - r->buf_len = 4; | 429 | + r->iov.iov_len = 4; |
| 429 | if (s->sense == SENSE_NOT_READY && len >= 18) { | 430 | if (s->sense == SENSE_NOT_READY && len >= 18) { |
| 430 | memset(outbuf, 0, 18); | 431 | memset(outbuf, 0, 18); |
| 431 | - r->buf_len = 18; | 432 | + r->iov.iov_len = 18; |
| 432 | outbuf[7] = 10; | 433 | outbuf[7] = 10; |
| 433 | /* asc 0x3a, ascq 0: Medium not present */ | 434 | /* asc 0x3a, ascq 0: Medium not present */ |
| 434 | outbuf[12] = 0x3a; | 435 | outbuf[12] = 0x3a; |
| @@ -461,20 +462,20 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, | @@ -461,20 +462,20 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, | ||
| 461 | DPRINTF("Inquiry EVPD[Supported pages] " | 462 | DPRINTF("Inquiry EVPD[Supported pages] " |
| 462 | "buffer size %d\n", len); | 463 | "buffer size %d\n", len); |
| 463 | 464 | ||
| 464 | - r->buf_len = 0; | 465 | + r->iov.iov_len = 0; |
| 465 | 466 | ||
| 466 | if (bdrv_get_type_hint(s->bdrv) == BDRV_TYPE_CDROM) { | 467 | if (bdrv_get_type_hint(s->bdrv) == BDRV_TYPE_CDROM) { |
| 467 | - outbuf[r->buf_len++] = 5; | 468 | + outbuf[r->iov.iov_len++] = 5; |
| 468 | } else { | 469 | } else { |
| 469 | - outbuf[r->buf_len++] = 0; | 470 | + outbuf[r->iov.iov_len++] = 0; |
| 470 | } | 471 | } |
| 471 | 472 | ||
| 472 | - outbuf[r->buf_len++] = 0x00; // this page | ||
| 473 | - outbuf[r->buf_len++] = 0x00; | ||
| 474 | - outbuf[r->buf_len++] = 3; // number of pages | ||
| 475 | - outbuf[r->buf_len++] = 0x00; // list of supported pages (this page) | ||
| 476 | - outbuf[r->buf_len++] = 0x80; // unit serial number | ||
| 477 | - outbuf[r->buf_len++] = 0x83; // device identification | 473 | + outbuf[r->iov.iov_len++] = 0x00; // this page |
| 474 | + outbuf[r->iov.iov_len++] = 0x00; | ||
| 475 | + outbuf[r->iov.iov_len++] = 3; // number of pages | ||
| 476 | + outbuf[r->iov.iov_len++] = 0x00; // list of supported pages (this page) | ||
| 477 | + outbuf[r->iov.iov_len++] = 0x80; // unit serial number | ||
| 478 | + outbuf[r->iov.iov_len++] = 0x83; // device identification | ||
| 478 | } | 479 | } |
| 479 | break; | 480 | break; |
| 480 | case 0x80: | 481 | case 0x80: |
| @@ -491,20 +492,20 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, | @@ -491,20 +492,20 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, | ||
| 491 | DPRINTF("Inquiry EVPD[Serial number] buffer size %d\n", len); | 492 | DPRINTF("Inquiry EVPD[Serial number] buffer size %d\n", len); |
| 492 | l = MIN(len, strlen(s->drive_serial_str)); | 493 | l = MIN(len, strlen(s->drive_serial_str)); |
| 493 | 494 | ||
| 494 | - r->buf_len = 0; | 495 | + r->iov.iov_len = 0; |
| 495 | 496 | ||
| 496 | /* Supported page codes */ | 497 | /* Supported page codes */ |
| 497 | if (bdrv_get_type_hint(s->bdrv) == BDRV_TYPE_CDROM) { | 498 | if (bdrv_get_type_hint(s->bdrv) == BDRV_TYPE_CDROM) { |
| 498 | - outbuf[r->buf_len++] = 5; | 499 | + outbuf[r->iov.iov_len++] = 5; |
| 499 | } else { | 500 | } else { |
| 500 | - outbuf[r->buf_len++] = 0; | 501 | + outbuf[r->iov.iov_len++] = 0; |
| 501 | } | 502 | } |
| 502 | 503 | ||
| 503 | - outbuf[r->buf_len++] = 0x80; // this page | ||
| 504 | - outbuf[r->buf_len++] = 0x00; | ||
| 505 | - outbuf[r->buf_len++] = l; | ||
| 506 | - memcpy(&outbuf[r->buf_len], s->drive_serial_str, l); | ||
| 507 | - r->buf_len += l; | 504 | + outbuf[r->iov.iov_len++] = 0x80; // this page |
| 505 | + outbuf[r->iov.iov_len++] = 0x00; | ||
| 506 | + outbuf[r->iov.iov_len++] = l; | ||
| 507 | + memcpy(&outbuf[r->iov.iov_len], s->drive_serial_str, l); | ||
| 508 | + r->iov.iov_len += l; | ||
| 508 | } | 509 | } |
| 509 | 510 | ||
| 510 | break; | 511 | break; |
| @@ -518,25 +519,25 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, | @@ -518,25 +519,25 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, | ||
| 518 | 519 | ||
| 519 | DPRINTF("Inquiry EVPD[Device identification] " | 520 | DPRINTF("Inquiry EVPD[Device identification] " |
| 520 | "buffer size %d\n", len); | 521 | "buffer size %d\n", len); |
| 521 | - r->buf_len = 0; | 522 | + r->iov.iov_len = 0; |
| 522 | if (bdrv_get_type_hint(s->bdrv) == BDRV_TYPE_CDROM) { | 523 | if (bdrv_get_type_hint(s->bdrv) == BDRV_TYPE_CDROM) { |
| 523 | - outbuf[r->buf_len++] = 5; | 524 | + outbuf[r->iov.iov_len++] = 5; |
| 524 | } else { | 525 | } else { |
| 525 | - outbuf[r->buf_len++] = 0; | 526 | + outbuf[r->iov.iov_len++] = 0; |
| 526 | } | 527 | } |
| 527 | 528 | ||
| 528 | - outbuf[r->buf_len++] = 0x83; // this page | ||
| 529 | - outbuf[r->buf_len++] = 0x00; | ||
| 530 | - outbuf[r->buf_len++] = 3 + id_len; | 529 | + outbuf[r->iov.iov_len++] = 0x83; // this page |
| 530 | + outbuf[r->iov.iov_len++] = 0x00; | ||
| 531 | + outbuf[r->iov.iov_len++] = 3 + id_len; | ||
| 531 | 532 | ||
| 532 | - outbuf[r->buf_len++] = 0x2; // ASCII | ||
| 533 | - outbuf[r->buf_len++] = 0; // not officially assigned | ||
| 534 | - outbuf[r->buf_len++] = 0; // reserved | ||
| 535 | - outbuf[r->buf_len++] = id_len; // length of data following | 533 | + outbuf[r->iov.iov_len++] = 0x2; // ASCII |
| 534 | + outbuf[r->iov.iov_len++] = 0; // not officially assigned | ||
| 535 | + outbuf[r->iov.iov_len++] = 0; // reserved | ||
| 536 | + outbuf[r->iov.iov_len++] = id_len; // length of data following | ||
| 536 | 537 | ||
| 537 | - memcpy(&outbuf[r->buf_len], | 538 | + memcpy(&outbuf[r->iov.iov_len], |
| 538 | bdrv_get_device_name(s->bdrv), id_len); | 539 | bdrv_get_device_name(s->bdrv), id_len); |
| 539 | - r->buf_len += id_len; | 540 | + r->iov.iov_len += id_len; |
| 540 | } | 541 | } |
| 541 | break; | 542 | break; |
| 542 | default: | 543 | default: |
| @@ -592,7 +593,7 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, | @@ -592,7 +593,7 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, | ||
| 592 | outbuf[4] = len - 5; /* Additional Length = (Len - 1) - 4 */ | 593 | outbuf[4] = len - 5; /* Additional Length = (Len - 1) - 4 */ |
| 593 | /* Sync data transfer and TCQ. */ | 594 | /* Sync data transfer and TCQ. */ |
| 594 | outbuf[7] = 0x10 | (s->tcq ? 0x02 : 0); | 595 | outbuf[7] = 0x10 | (s->tcq ? 0x02 : 0); |
| 595 | - r->buf_len = len; | 596 | + r->iov.iov_len = len; |
| 596 | break; | 597 | break; |
| 597 | case 0x16: | 598 | case 0x16: |
| 598 | DPRINTF("Reserve(6)\n"); | 599 | DPRINTF("Reserve(6)\n"); |
| @@ -727,10 +728,10 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, | @@ -727,10 +728,10 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, | ||
| 727 | p[21] = (16 * 176) & 0xff; | 728 | p[21] = (16 * 176) & 0xff; |
| 728 | p += 22; | 729 | p += 22; |
| 729 | } | 730 | } |
| 730 | - r->buf_len = p - outbuf; | ||
| 731 | - outbuf[0] = r->buf_len - 4; | ||
| 732 | - if (r->buf_len > len) | ||
| 733 | - r->buf_len = len; | 731 | + r->iov.iov_len = p - outbuf; |
| 732 | + outbuf[0] = r->iov.iov_len - 4; | ||
| 733 | + if (r->iov.iov_len > len) | ||
| 734 | + r->iov.iov_len = len; | ||
| 734 | } | 735 | } |
| 735 | break; | 736 | break; |
| 736 | case 0x1b: | 737 | case 0x1b: |
| @@ -766,7 +767,7 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, | @@ -766,7 +767,7 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, | ||
| 766 | outbuf[5] = 0; | 767 | outbuf[5] = 0; |
| 767 | outbuf[6] = s->cluster_size * 2; | 768 | outbuf[6] = s->cluster_size * 2; |
| 768 | outbuf[7] = 0; | 769 | outbuf[7] = 0; |
| 769 | - r->buf_len = 8; | 770 | + r->iov.iov_len = 8; |
| 770 | } else { | 771 | } else { |
| 771 | notready: | 772 | notready: |
| 772 | scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_NOT_READY); | 773 | scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_NOT_READY); |
| @@ -827,7 +828,7 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, | @@ -827,7 +828,7 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, | ||
| 827 | if (toclen > 0) { | 828 | if (toclen > 0) { |
| 828 | if (len > toclen) | 829 | if (len > toclen) |
| 829 | len = toclen; | 830 | len = toclen; |
| 830 | - r->buf_len = len; | 831 | + r->iov.iov_len = len; |
| 831 | break; | 832 | break; |
| 832 | } | 833 | } |
| 833 | error_cmd: | 834 | error_cmd: |
| @@ -840,7 +841,7 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, | @@ -840,7 +841,7 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, | ||
| 840 | /* ??? This should probably return much more information. For now | 841 | /* ??? This should probably return much more information. For now |
| 841 | just return the basic header indicating the CD-ROM profile. */ | 842 | just return the basic header indicating the CD-ROM profile. */ |
| 842 | outbuf[7] = 8; // CD-ROM | 843 | outbuf[7] = 8; // CD-ROM |
| 843 | - r->buf_len = 8; | 844 | + r->iov.iov_len = 8; |
| 844 | break; | 845 | break; |
| 845 | case 0x56: | 846 | case 0x56: |
| 846 | DPRINTF("Reserve(10)\n"); | 847 | DPRINTF("Reserve(10)\n"); |
| @@ -877,7 +878,7 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, | @@ -877,7 +878,7 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, | ||
| 877 | outbuf[10] = s->cluster_size * 2; | 878 | outbuf[10] = s->cluster_size * 2; |
| 878 | outbuf[11] = 0; | 879 | outbuf[11] = 0; |
| 879 | /* Protection, exponent and lowest lba field left blank. */ | 880 | /* Protection, exponent and lowest lba field left blank. */ |
| 880 | - r->buf_len = len; | 881 | + r->iov.iov_len = len; |
| 881 | } else { | 882 | } else { |
| 882 | scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_NOT_READY); | 883 | scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_NOT_READY); |
| 883 | return 0; | 884 | return 0; |
| @@ -892,7 +893,7 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, | @@ -892,7 +893,7 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, | ||
| 892 | goto fail; | 893 | goto fail; |
| 893 | memset(outbuf, 0, 16); | 894 | memset(outbuf, 0, 16); |
| 894 | outbuf[3] = 8; | 895 | outbuf[3] = 8; |
| 895 | - r->buf_len = 16; | 896 | + r->iov.iov_len = 16; |
| 896 | break; | 897 | break; |
| 897 | case 0x2f: | 898 | case 0x2f: |
| 898 | DPRINTF("Verify (sector %d, count %d)\n", lba, len); | 899 | DPRINTF("Verify (sector %d, count %d)\n", lba, len); |
| @@ -906,10 +907,10 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, | @@ -906,10 +907,10 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, | ||
| 906 | scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_HARDWARE_ERROR); | 907 | scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_HARDWARE_ERROR); |
| 907 | return 0; | 908 | return 0; |
| 908 | } | 909 | } |
| 909 | - if (r->sector_count == 0 && r->buf_len == 0) { | 910 | + if (r->sector_count == 0 && r->iov.iov_len == 0) { |
| 910 | scsi_command_complete(r, STATUS_GOOD, SENSE_NO_SENSE); | 911 | scsi_command_complete(r, STATUS_GOOD, SENSE_NO_SENSE); |
| 911 | } | 912 | } |
| 912 | - len = r->sector_count * 512 + r->buf_len; | 913 | + len = r->sector_count * 512 + r->iov.iov_len; |
| 913 | if (is_write) { | 914 | if (is_write) { |
| 914 | return -len; | 915 | return -len; |
| 915 | } else { | 916 | } else { |