Revision c87c0672

b/block-qcow.c
530 530
    int n;
531 531
    uint64_t cluster_offset;
532 532
    uint8_t *cluster_data;
533
    struct iovec hd_iov;
534
    QEMUIOVector hd_qiov;
533 535
    BlockDriverAIOCB *hd_aiocb;
534 536
} QCowAIOCB;
535 537

  
......
584 586
    if (!acb->cluster_offset) {
585 587
        if (bs->backing_hd) {
586 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 594
            if (acb->hd_aiocb == NULL)
590 595
                goto fail;
591 596
        } else {
......
605 610
            ret = -EIO;
606 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 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 619
        if (acb->hd_aiocb == NULL)
612 620
            goto fail;
613 621
    }
......
687 695
    } else {
688 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 706
    if (acb->hd_aiocb == NULL)
695 707
        goto fail;
696 708
}
b/block-qcow2.c
1270 1270
    uint64_t cluster_offset;
1271 1271
    uint8_t *cluster_data;
1272 1272
    BlockDriverAIOCB *hd_aiocb;
1273
    struct iovec hd_iov;
1274
    QEMUIOVector hd_qiov;
1273 1275
    QEMUBH *bh;
1274 1276
    QCowL2Meta l2meta;
1275 1277
} QCowAIOCB;
......
1347 1349
            n1 = backing_read1(bs->backing_hd, acb->sector_num,
1348 1350
                               acb->buf, acb->n);
1349 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 1358
                if (acb->hd_aiocb == NULL)
1353 1359
                    goto fail;
1354 1360
            } else {
......
1377 1383
            ret = -EIO;
1378 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 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 1393
        if (acb->hd_aiocb == NULL)
1384 1394
            goto fail;
1385 1395
    }
......
1476 1486
    } else {
1477 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 1496
    if (acb->hd_aiocb == NULL)
1484 1497
        goto fail;
1485 1498
}
b/block.c
55 55
    int ret;
56 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 64
static BlockDriverAIOCB *bdrv_aio_read_em(BlockDriverState *bs,
59 65
        int64_t sector_num, uint8_t *buf, int nb_sectors,
60 66
        BlockDriverCompletionFunc *cb, void *opaque);
......
1370 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 1380
                                uint8_t *buf, int nb_sectors,
1375 1381
                                BlockDriverCompletionFunc *cb, void *opaque)
1376 1382
{
......
1393 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 1403
                                 const uint8_t *buf, int nb_sectors,
1398 1404
                                 BlockDriverCompletionFunc *cb, void *opaque)
1399 1405
{
b/block.h
96 96
BlockDriverAIOCB *bdrv_aio_writev(BlockDriverState *bs, int64_t sector_num,
97 97
                                  QEMUIOVector *iov, int nb_sectors,
98 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 99
void bdrv_aio_cancel(BlockDriverAIOCB *acb);
107 100

  
108 101
/* sg packet commands */
b/hw/ide.c
496 496
    IDEState *ide_if;
497 497
    BlockDriverCompletionFunc *dma_cb;
498 498
    BlockDriverAIOCB *aiocb;
499
    struct iovec iov;
500
    QEMUIOVector qiov;
499 501
    int64_t sector_num;
500 502
    uint32_t nsector;
501 503
} BMDMAState;
......
1467 1469
#ifdef DEBUG_AIO
1468 1470
    printf("aio_read_cd: lba=%u n=%d\n", s->lba, n);
1469 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 1477
    if (!bm->aiocb) {
1474 1478
        /* Note: media not present is the most likely case */
1475 1479
        ide_atapi_cmd_error(s, SENSE_NOT_READY,
b/hw/scsi-disk.c
52 52
    /* Both sector and sector_count are in terms of qemu 512 byte blocks.  */
53 53
    uint64_t sector;
54 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 57
    BlockDriverAIOCB *aiocb;
59 58
    struct SCSIRequest *next;
60 59
    uint32_t status;
......
89 88
        free_requests = r->next;
90 89
    } else {
91 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 93
    r->dev = s;
95 94
    r->tag = tag;
96 95
    r->sector_count = 0;
97
    r->buf_len = 0;
96
    r->iov.iov_len = 0;
98 97
    r->aiocb = NULL;
99 98
    r->status = 0;
100 99

  
......
173 172
        scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_NO_SENSE);
174 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 180
/* Read more data from scsi device into buffer.  */
......
193 192
        return;
194 193
    }
195 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 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 198
        return;
200 199
    }
201 200
    DPRINTF("Read sector_count=%d\n", r->sector_count);
......
208 207
    if (n > SCSI_DMA_BUF_SIZE / 512)
209 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 214
    if (r->aiocb == NULL)
215 215
        scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_HARDWARE_ERROR);
216 216
    r->sector += n;
......
250 250
            return;
251 251
    }
252 252

  
253
    n = r->buf_len / 512;
253
    n = r->iov.iov_len / 512;
254 254
    r->sector += n;
255 255
    r->sector_count -= n;
256 256
    if (r->sector_count == 0) {
......
260 260
        if (len > SCSI_DMA_BUF_SIZE) {
261 261
            len = SCSI_DMA_BUF_SIZE;
262 262
        }
263
        r->buf_len = len;
263
        r->iov.iov_len = len;
264 264
        DPRINTF("Write complete tag=0x%x more=%d\n", r->tag, len);
265 265
        s->completion(s->opaque, SCSI_REASON_DATA, r->tag, len);
266 266
    }
......
271 271
    SCSIDeviceState *s = r->dev;
272 272
    uint32_t n;
273 273

  
274
    n = r->buf_len / 512;
274
    n = r->iov.iov_len / 512;
275 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 279
        if (r->aiocb == NULL)
279 280
            scsi_command_complete(r, STATUS_CHECK_CONDITION,
280 281
                                  SENSE_HARDWARE_ERROR);
......
334 335
        BADF("Bad buffer tag 0x%x\n", tag);
335 336
        return NULL;
336 337
    }
337
    return r->dma_buf;
338
    return r->iov.iov_base;
338 339
}
339 340

  
340 341
/* Execute a scsi command.  Returns the length of the data expected by the
......
364 365
    /* ??? Tags are not unique for different luns.  We only implement a
365 366
       single lun, so this should not matter.  */
366 367
    r = scsi_new_request(s, tag);
367
    outbuf = r->dma_buf;
368
    outbuf = r->iov.iov_base;
368 369
    is_write = 0;
369 370
    DPRINTF("Command: lun=%d tag=0x%x data=0x%02x", lun, tag, buf[0]);
370 371
    switch (command >> 5) {
......
425 426
        if (len < 4)
426 427
            goto fail;
427 428
        memset(outbuf, 0, 4);
428
        r->buf_len = 4;
429
        r->iov.iov_len = 4;
429 430
        if (s->sense == SENSE_NOT_READY && len >= 18) {
430 431
            memset(outbuf, 0, 18);
431
            r->buf_len = 18;
432
            r->iov.iov_len = 18;
432 433
            outbuf[7] = 10;
433 434
            /* asc 0x3a, ascq 0: Medium not present */
434 435
            outbuf[12] = 0x3a;
......
461 462
                        DPRINTF("Inquiry EVPD[Supported pages] "
462 463
                                "buffer size %d\n", len);
463 464

  
464
                        r->buf_len = 0;
465
                        r->iov.iov_len = 0;
465 466

  
466 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 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 480
                    break;
480 481
                case 0x80:
......
491 492
                        DPRINTF("Inquiry EVPD[Serial number] buffer size %d\n", len);
492 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 497
                        /* Supported page codes */
497 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 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 511
                    break;
......
518 519

  
519 520
                        DPRINTF("Inquiry EVPD[Device identification] "
520 521
                                "buffer size %d\n", len);
521
                        r->buf_len = 0;
522
                        r->iov.iov_len = 0;
522 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 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 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 542
                    break;
542 543
                default:
......
592 593
	outbuf[4] = len - 5; /* Additional Length = (Len - 1) - 4 */
593 594
        /* Sync data transfer and TCQ.  */
594 595
        outbuf[7] = 0x10 | (s->tcq ? 0x02 : 0);
595
	r->buf_len = len;
596
	r->iov.iov_len = len;
596 597
	break;
597 598
    case 0x16:
598 599
        DPRINTF("Reserve(6)\n");
......
727 728
                p[21] = (16 * 176) & 0xff;
728 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 736
        break;
736 737
    case 0x1b:
......
766 767
            outbuf[5] = 0;
767 768
            outbuf[6] = s->cluster_size * 2;
768 769
            outbuf[7] = 0;
769
            r->buf_len = 8;
770
            r->iov.iov_len = 8;
770 771
        } else {
771 772
        notready:
772 773
            scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_NOT_READY);
......
827 828
            if (toclen > 0) {
828 829
                if (len > toclen)
829 830
                  len = toclen;
830
                r->buf_len = len;
831
                r->iov.iov_len = len;
831 832
                break;
832 833
            }
833 834
        error_cmd:
......
840 841
        /* ??? This should probably return much more information.  For now
841 842
           just return the basic header indicating the CD-ROM profile.  */
842 843
        outbuf[7] = 8; // CD-ROM
843
        r->buf_len = 8;
844
        r->iov.iov_len = 8;
844 845
        break;
845 846
    case 0x56:
846 847
        DPRINTF("Reserve(10)\n");
......
877 878
                outbuf[10] = s->cluster_size * 2;
878 879
                outbuf[11] = 0;
879 880
                /* Protection, exponent and lowest lba field left blank. */
880
                r->buf_len = len;
881
                r->iov.iov_len = len;
881 882
            } else {
882 883
                scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_NOT_READY);
883 884
                return 0;
......
892 893
            goto fail;
893 894
        memset(outbuf, 0, 16);
894 895
        outbuf[3] = 8;
895
        r->buf_len = 16;
896
        r->iov.iov_len = 16;
896 897
        break;
897 898
    case 0x2f:
898 899
        DPRINTF("Verify (sector %d, count %d)\n", lba, len);
......
906 907
        scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_HARDWARE_ERROR);
907 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 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 914
    if (is_write) {
914 915
        return -len;
915 916
    } else {

Also available in: Unified diff