Commit 8b94ff85 authored by Paolo Bonzini's avatar Paolo Bonzini Committed by Kevin Wolf
Browse files

block: change flush to co_flush



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: default avatarPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
parent e183ef75
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -2892,8 +2892,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
+3 −3
Original line number Diff line number Diff line
@@ -306,9 +306,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[] = {
@@ -334,7 +334,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,
+5 −6
Original line number Diff line number Diff line
@@ -781,10 +781,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)
@@ -826,7 +825,7 @@ static BlockDriver bdrv_qcow = {
    .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_flush      = qcow_co_flush,
    .bdrv_write_compressed = qcow_write_compressed,
    .bdrv_get_info	= qcow_get_info,

+7 −7
Original line number Diff line number Diff line
@@ -1099,24 +1099,24 @@ fail:
    return ret;
}

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)
@@ -1237,7 +1237,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,
+2 −2
Original line number Diff line number Diff line
@@ -281,7 +281,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,
@@ -409,7 +409,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,
Loading