From 5975d1960d35e1b5c5ae1f39f48bcb8033b99ce3 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Tue, 14 Feb 2012 11:14:59 +0100 Subject: [PATCH 94/99] block: change flush to co_flush RH-Author: Kevin Wolf Message-id: <1329218101-24213-95-git-send-email-kwolf@redhat.com> Patchwork-id: 37279 O-Subject: [RHEL-6.3 qemu-kvm PATCH v2 94/96] block: change flush to co_flush Bugzilla: 783950 RH-Acked-by: Paolo Bonzini RH-Acked-by: Marcelo Tosatti RH-Acked-by: Laszlo Ersek From: Paolo Bonzini Bugzilla: 783950 Since coroutine operation is now mandatory, convert all bdrv_flush implementations to coroutines. For qcow2, this means taking the lock. Other implementations are simpler and just forward bdrv_flush to the underlying protocol, so they can avoid the lock. The bdrv_flush callback is then unused and can be eliminated. Signed-off-by: Paolo Bonzini Signed-off-by: Kevin Wolf (cherry picked from commit 8b94ff85737062876c03e7506abb500521c749b9) Conflicts: block/rbd.c block/vmdk.c Signed-off-by: Kevin Wolf --- block.c | 2 -- block/cow.c | 6 +++--- block/qcow.c | 11 +++++------ block/qcow2.c | 14 +++++++------- block/raw-win32.c | 4 ++-- block/vdi.c | 6 +++--- block/vmdk.c | 6 +++--- block/vpc.c | 6 +++--- block_int.h | 1 - 9 files changed, 26 insertions(+), 30 deletions(-) Signed-off-by: Michal Novotny --- block.c | 2 -- block/cow.c | 6 +++--- block/qcow.c | 11 +++++------ block/qcow2.c | 14 +++++++------- block/raw-win32.c | 4 ++-- block/vdi.c | 6 +++--- block/vmdk.c | 6 +++--- block/vpc.c | 6 +++--- block_int.h | 1 - 9 files changed, 26 insertions(+), 30 deletions(-) diff --git a/block.c b/block.c index e07be6c..220543b 100644 --- a/block.c +++ b/block.c @@ -2746,8 +2746,6 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs) qemu_coroutine_yield(); return co.ret; } - } else if (bs->drv->bdrv_flush) { - return bs->drv->bdrv_flush(bs); } else { /* * Some block drivers always operate in either writethrough or unsafe diff --git a/block/cow.c b/block/cow.c index 70d0eb2..470c93e 100644 --- a/block/cow.c +++ b/block/cow.c @@ -304,9 +304,9 @@ exit: return ret; } -static int cow_flush(BlockDriverState *bs) +static coroutine_fn int cow_co_flush(BlockDriverState *bs) { - return bdrv_flush(bs->file); + return bdrv_co_flush(bs->file); } static QEMUOptionParameter cow_create_options[] = { @@ -332,7 +332,7 @@ static BlockDriver bdrv_cow = { .bdrv_write = cow_co_write, .bdrv_close = cow_close, .bdrv_create = cow_create, - .bdrv_flush = cow_flush, + .bdrv_co_flush = cow_co_flush, .bdrv_is_allocated = cow_is_allocated, .create_options = cow_create_options, diff --git a/block/qcow.c b/block/qcow.c index 06f8a97..938625a 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -895,10 +895,9 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num, return 0; } -static BlockDriverAIOCB *qcow_aio_flush(BlockDriverState *bs, - BlockDriverCompletionFunc *cb, void *opaque) +static coroutine_fn int qcow_co_flush(BlockDriverState *bs) { - return bdrv_aio_flush(bs->file, cb, opaque); + return bdrv_co_flush(bs->file); } static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) @@ -938,9 +937,9 @@ static BlockDriver bdrv_qcow = { .bdrv_is_allocated = qcow_is_allocated, .bdrv_set_key = qcow_set_key, .bdrv_make_empty = qcow_make_empty, - .bdrv_co_readv = qcow_co_readv, - .bdrv_co_writev = qcow_co_writev, - .bdrv_aio_flush = qcow_aio_flush, + .bdrv_co_readv = qcow_co_readv, + .bdrv_co_writev = qcow_co_writev, + .bdrv_co_flush = qcow_co_flush, .bdrv_write_compressed = qcow_write_compressed, .bdrv_get_info = qcow_get_info, diff --git a/block/qcow2.c b/block/qcow2.c index 1aaa2f2..e9af848 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1220,24 +1220,24 @@ static int qcow2_write_compressed(BlockDriverState *bs, int64_t sector_num, return 0; } -static BlockDriverAIOCB *qcow2_aio_flush(BlockDriverState *bs, - BlockDriverCompletionFunc *cb, - void *opaque) +static int qcow2_co_flush(BlockDriverState *bs) { BDRVQcowState *s = bs->opaque; int ret; + qemu_co_mutex_lock(&s->lock); ret = qcow2_cache_flush(bs, s->l2_table_cache); if (ret < 0) { - return NULL; + return ret; } ret = qcow2_cache_flush(bs, s->refcount_block_cache); if (ret < 0) { - return NULL; + return ret; } + qemu_co_mutex_unlock(&s->lock); - return bdrv_aio_flush(bs->file, cb, opaque); + return bdrv_co_flush(bs->file); } static int64_t qcow2_vm_state_offset(BDRVQcowState *s) @@ -1358,7 +1358,7 @@ static BlockDriver bdrv_qcow2 = { .bdrv_co_readv = qcow2_co_readv, .bdrv_co_writev = qcow2_co_writev, - .bdrv_aio_flush = qcow2_aio_flush, + .bdrv_co_flush = qcow2_co_flush, .bdrv_discard = qcow2_discard, .bdrv_truncate = qcow2_truncate, diff --git a/block/raw-win32.c b/block/raw-win32.c index f6252b5..7a671cb 100644 --- a/block/raw-win32.c +++ b/block/raw-win32.c @@ -256,7 +256,7 @@ static BlockDriver bdrv_file = { .bdrv_file_open = raw_open, .bdrv_close = raw_close, .bdrv_create = raw_create, - .bdrv_flush = raw_flush, + .bdrv_co_flush = raw_flush, .bdrv_read = raw_read, .bdrv_write = raw_write, .bdrv_truncate = raw_truncate, @@ -382,7 +382,7 @@ static BlockDriver bdrv_host_device = { .bdrv_probe_device = hdev_probe_device, .bdrv_file_open = hdev_open, .bdrv_close = raw_close, - .bdrv_flush = raw_flush, + .bdrv_co_flush = raw_flush, .bdrv_has_zero_init = hdev_has_zero_init, .bdrv_read = raw_read, diff --git a/block/vdi.c b/block/vdi.c index 31e279e..af227a9 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -883,10 +883,10 @@ static void vdi_close(BlockDriverState *bs) { } -static int vdi_flush(BlockDriverState *bs) +static coroutine_fn int vdi_co_flush(BlockDriverState *bs) { logout("\n"); - return bdrv_flush(bs->file); + return bdrv_co_flush(bs->file); } @@ -922,7 +922,7 @@ static BlockDriver bdrv_vdi = { .bdrv_open = vdi_open, .bdrv_close = vdi_close, .bdrv_create = vdi_create, - .bdrv_flush = vdi_flush, + .bdrv_co_flush = vdi_co_flush, .bdrv_is_allocated = vdi_is_allocated, .bdrv_make_empty = vdi_make_empty, diff --git a/block/vmdk.c b/block/vmdk.c index be6916c..19c4025 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -849,9 +849,9 @@ static void vmdk_close(BlockDriverState *bs) g_free(s->l2_cache); } -static int vmdk_flush(BlockDriverState *bs) +static coroutine_fn int vmdk_co_flush(BlockDriverState *bs) { - return bdrv_flush(bs->file); + return bdrv_co_flush(bs->file); } @@ -883,7 +883,7 @@ static BlockDriver bdrv_vmdk = { .bdrv_write = vmdk_co_write, .bdrv_close = vmdk_close, .bdrv_create = vmdk_create, - .bdrv_flush = vmdk_flush, + .bdrv_co_flush = vmdk_co_flush, .bdrv_is_allocated = vmdk_is_allocated, .create_options = vmdk_create_options, diff --git a/block/vpc.c b/block/vpc.c index 2bb7d6e..d11fe34 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -441,9 +441,9 @@ static coroutine_fn int vpc_co_write(BlockDriverState *bs, int64_t sector_num, return ret; } -static int vpc_flush(BlockDriverState *bs) +static coroutine_fn int vpc_co_flush(BlockDriverState *bs) { - return bdrv_flush(bs->file); + return bdrv_co_flush(bs->file); } /* @@ -627,7 +627,7 @@ static BlockDriver bdrv_vpc = { .bdrv_open = vpc_open, .bdrv_read = vpc_co_read, .bdrv_write = vpc_co_write, - .bdrv_flush = vpc_flush, + .bdrv_co_flush = vpc_co_flush, .bdrv_close = vpc_close, .bdrv_create = vpc_create, diff --git a/block_int.h b/block_int.h index 06c02c3..9c0bff5 100644 --- a/block_int.h +++ b/block_int.h @@ -61,7 +61,6 @@ struct BlockDriver { const uint8_t *buf, int nb_sectors); void (*bdrv_close)(BlockDriverState *bs); int (*bdrv_create)(const char *filename, QEMUOptionParameter *options); - int (*bdrv_flush)(BlockDriverState *bs); int (*bdrv_discard)(BlockDriverState *bs, int64_t sector_num, int nb_sectors); int (*bdrv_is_allocated)(BlockDriverState *bs, int64_t sector_num, -- 1.7.7.5