diff mbox

[6/6] block: switch bdrv_aio_writev() to coroutines

Message ID 1317831427-477-7-git-send-email-stefanha@linux.vnet.ibm.com
State New
Headers show

Commit Message

Stefan Hajnoczi Oct. 5, 2011, 4:17 p.m. UTC
More sync, aio, and coroutine unification.  Make bdrv_aio_writev() go
through coroutine request processing.

Remove the dirty block callback mechanism which was needed only for aio
processing and can be done more naturally in coroutine context.

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 block.c |   66 +-------------------------------------------------------------
 1 files changed, 2 insertions(+), 64 deletions(-)

Comments

Zhiyong Wu Oct. 11, 2011, 6:46 a.m. UTC | #1
On Thu, Oct 6, 2011 at 12:17 AM, Stefan Hajnoczi
<stefanha@linux.vnet.ibm.com> wrote:
> More sync, aio, and coroutine unification.  Make bdrv_aio_writev() go
> through coroutine request processing.
>
> Remove the dirty block callback mechanism which was needed only for aio
> processing and can be done more naturally in coroutine context.
>
> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
> ---
>  block.c |   66 +-------------------------------------------------------------
>  1 files changed, 2 insertions(+), 64 deletions(-)
>
> diff --git a/block.c b/block.c
> index 5d6e17f..e80121b 100644
> --- a/block.c
> +++ b/block.c
> @@ -2364,76 +2364,14 @@ BlockDriverAIOCB *bdrv_aio_readv(BlockDriverState *bs, int64_t sector_num,
>                                  cb, opaque, false, bdrv_co_do_rw);
>  }
>
> -typedef struct BlockCompleteData {
> -    BlockDriverCompletionFunc *cb;
> -    void *opaque;
> -    BlockDriverState *bs;
> -    int64_t sector_num;
> -    int nb_sectors;
> -} BlockCompleteData;
> -
> -static void block_complete_cb(void *opaque, int ret)
> -{
> -    BlockCompleteData *b = opaque;
> -
> -    if (b->bs->dirty_bitmap) {
> -        set_dirty_bitmap(b->bs, b->sector_num, b->nb_sectors, 1);
> -    }
> -    b->cb(b->opaque, ret);
> -    g_free(b);
> -}
> -
> -static BlockCompleteData *blk_dirty_cb_alloc(BlockDriverState *bs,
> -                                             int64_t sector_num,
> -                                             int nb_sectors,
> -                                             BlockDriverCompletionFunc *cb,
> -                                             void *opaque)
> -{
> -    BlockCompleteData *blkdata = g_malloc0(sizeof(BlockCompleteData));
> -
> -    blkdata->bs = bs;
> -    blkdata->cb = cb;
> -    blkdata->opaque = opaque;
> -    blkdata->sector_num = sector_num;
> -    blkdata->nb_sectors = nb_sectors;
> -
> -    return blkdata;
> -}
> -
>  BlockDriverAIOCB *bdrv_aio_writev(BlockDriverState *bs, int64_t sector_num,
>                                   QEMUIOVector *qiov, int nb_sectors,
>                                   BlockDriverCompletionFunc *cb, void *opaque)
>  {
> -    BlockDriver *drv = bs->drv;
> -    BlockDriverAIOCB *ret;
> -    BlockCompleteData *blk_cb_data;
> -
>     trace_bdrv_aio_writev(bs, sector_num, nb_sectors, opaque);
>
> -    if (!drv)
> -        return NULL;
> -    if (bs->read_only)
> -        return NULL;
> -    if (bdrv_check_request(bs, sector_num, nb_sectors))
> -        return NULL;
> -
> -    if (bs->dirty_bitmap) {
> -        blk_cb_data = blk_dirty_cb_alloc(bs, sector_num, nb_sectors, cb,
> -                                         opaque);
> -        cb = &block_complete_cb;
> -        opaque = blk_cb_data;
> -    }
> -
> -    ret = drv->bdrv_aio_writev(bs, sector_num, qiov, nb_sectors,
> -                               cb, opaque);
> -
> -    if (ret) {
> -        if (bs->wr_highest_sector < sector_num + nb_sectors - 1) {
> -            bs->wr_highest_sector = sector_num + nb_sectors - 1;
> -        }
> -    }
As what is said in patch #3.
> -
> -    return ret;
> +    return bdrv_co_aio_rw_vector(bs, sector_num, qiov, nb_sectors,
> +                                 cb, opaque, true, bdrv_co_do_rw);
>  }
>
>
> --
> 1.7.6.3
>
>
>
diff mbox

Patch

diff --git a/block.c b/block.c
index 5d6e17f..e80121b 100644
--- a/block.c
+++ b/block.c
@@ -2364,76 +2364,14 @@  BlockDriverAIOCB *bdrv_aio_readv(BlockDriverState *bs, int64_t sector_num,
                                  cb, opaque, false, bdrv_co_do_rw);
 }
 
-typedef struct BlockCompleteData {
-    BlockDriverCompletionFunc *cb;
-    void *opaque;
-    BlockDriverState *bs;
-    int64_t sector_num;
-    int nb_sectors;
-} BlockCompleteData;
-
-static void block_complete_cb(void *opaque, int ret)
-{
-    BlockCompleteData *b = opaque;
-
-    if (b->bs->dirty_bitmap) {
-        set_dirty_bitmap(b->bs, b->sector_num, b->nb_sectors, 1);
-    }
-    b->cb(b->opaque, ret);
-    g_free(b);
-}
-
-static BlockCompleteData *blk_dirty_cb_alloc(BlockDriverState *bs,
-                                             int64_t sector_num,
-                                             int nb_sectors,
-                                             BlockDriverCompletionFunc *cb,
-                                             void *opaque)
-{
-    BlockCompleteData *blkdata = g_malloc0(sizeof(BlockCompleteData));
-
-    blkdata->bs = bs;
-    blkdata->cb = cb;
-    blkdata->opaque = opaque;
-    blkdata->sector_num = sector_num;
-    blkdata->nb_sectors = nb_sectors;
-
-    return blkdata;
-}
-
 BlockDriverAIOCB *bdrv_aio_writev(BlockDriverState *bs, int64_t sector_num,
                                   QEMUIOVector *qiov, int nb_sectors,
                                   BlockDriverCompletionFunc *cb, void *opaque)
 {
-    BlockDriver *drv = bs->drv;
-    BlockDriverAIOCB *ret;
-    BlockCompleteData *blk_cb_data;
-
     trace_bdrv_aio_writev(bs, sector_num, nb_sectors, opaque);
 
-    if (!drv)
-        return NULL;
-    if (bs->read_only)
-        return NULL;
-    if (bdrv_check_request(bs, sector_num, nb_sectors))
-        return NULL;
-
-    if (bs->dirty_bitmap) {
-        blk_cb_data = blk_dirty_cb_alloc(bs, sector_num, nb_sectors, cb,
-                                         opaque);
-        cb = &block_complete_cb;
-        opaque = blk_cb_data;
-    }
-
-    ret = drv->bdrv_aio_writev(bs, sector_num, qiov, nb_sectors,
-                               cb, opaque);
-
-    if (ret) {
-        if (bs->wr_highest_sector < sector_num + nb_sectors - 1) {
-            bs->wr_highest_sector = sector_num + nb_sectors - 1;
-        }
-    }
-
-    return ret;
+    return bdrv_co_aio_rw_vector(bs, sector_num, qiov, nb_sectors,
+                                 cb, opaque, true, bdrv_co_do_rw);
 }