Commit ad53089b0d0b4bc0731d978e5713365e1a91ba74
Committed by
Anthony Liguori
1 parent
4099df58
qcow: add qcow_aio_setup helper
[this one is required for [PATCH] fully split aio_pool from BlockDriver, sorry for not sending it out earlier] Add a qcow_aio_setup helper to qcow to shared common code between the aio_readv and aio_writev methods. Based on the function with the same name in qcow2. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing
1 changed file
with
29 additions
and
23 deletions
block/qcow.c
@@ -503,6 +503,32 @@ typedef struct QCowAIOCB { | @@ -503,6 +503,32 @@ typedef struct QCowAIOCB { | ||
503 | BlockDriverAIOCB *hd_aiocb; | 503 | BlockDriverAIOCB *hd_aiocb; |
504 | } QCowAIOCB; | 504 | } QCowAIOCB; |
505 | 505 | ||
506 | + | ||
507 | +static QCowAIOCB *qcow_aio_setup(BlockDriverState *bs, | ||
508 | + int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, | ||
509 | + BlockDriverCompletionFunc *cb, void *opaque, int is_write) | ||
510 | +{ | ||
511 | + QCowAIOCB *acb; | ||
512 | + | ||
513 | + acb = qemu_aio_get(bs, cb, opaque); | ||
514 | + if (!acb) | ||
515 | + return NULL; | ||
516 | + acb->hd_aiocb = NULL; | ||
517 | + acb->sector_num = sector_num; | ||
518 | + acb->qiov = qiov; | ||
519 | + if (qiov->niov > 1) { | ||
520 | + acb->buf = acb->orig_buf = qemu_blockalign(bs, qiov->size); | ||
521 | + if (is_write) | ||
522 | + qemu_iovec_to_buffer(qiov, acb->buf); | ||
523 | + } else { | ||
524 | + acb->buf = (uint8_t *)qiov->iov->iov_base; | ||
525 | + } | ||
526 | + acb->nb_sectors = nb_sectors; | ||
527 | + acb->n = 0; | ||
528 | + acb->cluster_offset = 0; | ||
529 | + return acb; | ||
530 | +} | ||
531 | + | ||
506 | static void qcow_aio_read_cb(void *opaque, int ret) | 532 | static void qcow_aio_read_cb(void *opaque, int ret) |
507 | { | 533 | { |
508 | QCowAIOCB *acb = opaque; | 534 | QCowAIOCB *acb = opaque; |
@@ -600,19 +626,9 @@ static BlockDriverAIOCB *qcow_aio_readv(BlockDriverState *bs, | @@ -600,19 +626,9 @@ static BlockDriverAIOCB *qcow_aio_readv(BlockDriverState *bs, | ||
600 | { | 626 | { |
601 | QCowAIOCB *acb; | 627 | QCowAIOCB *acb; |
602 | 628 | ||
603 | - acb = qemu_aio_get(bs, cb, opaque); | 629 | + acb = qcow_aio_setup(bs, sector_num, qiov, nb_sectors, cb, opaque, 0); |
604 | if (!acb) | 630 | if (!acb) |
605 | return NULL; | 631 | return NULL; |
606 | - acb->hd_aiocb = NULL; | ||
607 | - acb->sector_num = sector_num; | ||
608 | - acb->qiov = qiov; | ||
609 | - if (qiov->niov > 1) | ||
610 | - acb->buf = acb->orig_buf = qemu_blockalign(bs, qiov->size); | ||
611 | - else | ||
612 | - acb->buf = (uint8_t *)qiov->iov->iov_base; | ||
613 | - acb->nb_sectors = nb_sectors; | ||
614 | - acb->n = 0; | ||
615 | - acb->cluster_offset = 0; | ||
616 | 632 | ||
617 | qcow_aio_read_cb(acb, 0); | 633 | qcow_aio_read_cb(acb, 0); |
618 | return &acb->common; | 634 | return &acb->common; |
@@ -695,20 +711,10 @@ static BlockDriverAIOCB *qcow_aio_writev(BlockDriverState *bs, | @@ -695,20 +711,10 @@ static BlockDriverAIOCB *qcow_aio_writev(BlockDriverState *bs, | ||
695 | 711 | ||
696 | s->cluster_cache_offset = -1; /* disable compressed cache */ | 712 | s->cluster_cache_offset = -1; /* disable compressed cache */ |
697 | 713 | ||
698 | - acb = qemu_aio_get(bs, cb, opaque); | 714 | + acb = qcow_aio_setup(bs, sector_num, qiov, nb_sectors, cb, opaque, 0); |
699 | if (!acb) | 715 | if (!acb) |
700 | return NULL; | 716 | return NULL; |
701 | - acb->hd_aiocb = NULL; | ||
702 | - acb->sector_num = sector_num; | ||
703 | - acb->qiov = qiov; | ||
704 | - if (qiov->niov > 1) { | ||
705 | - acb->buf = acb->orig_buf = qemu_blockalign(bs, qiov->size); | ||
706 | - qemu_iovec_to_buffer(qiov, acb->buf); | ||
707 | - } else { | ||
708 | - acb->buf = (uint8_t *)qiov->iov->iov_base; | ||
709 | - } | ||
710 | - acb->nb_sectors = nb_sectors; | ||
711 | - acb->n = 0; | 717 | + |
712 | 718 | ||
713 | qcow_aio_write_cb(acb, 0); | 719 | qcow_aio_write_cb(acb, 0); |
714 | return &acb->common; | 720 | return &acb->common; |